Repository navigation
Replace most matchers by obj.should.foo #1350
Description
Activity
Good idea!
Some thoughts:
- Having a small, limited list of matchers would make it possible to just list them all in CONTRIBUTING.md here. Currently it's necessary to look at MSpec's source to learn about rarer matchers.
- Reading your blog post made me appreciate
should.methodsyntax more. I think linking to it in docs would be good. And just generally point out that it's the recommended method to test stuff, instead of looking for specific matchers. - Moving highly specifc matchers into the libraries's specs would be good.
match_yamlis another one that's only used inlibrary/yaml.
be_one_of(true, false)I think there is potential in
be_one_of(*values)matcher. Even if it's rare to need it, it could be used, for example, forIO::Buffer::HOST_ENDIAN.should be_one_of(IO::Buffer::BIG_ENDIAN, IO::Buffer::LITTLE_ENDIAN).
Though this relation this can easily be expressed with[a, b].should.include?(value), so maybe there is no reason to actually have this orbe_true_or_false?Re 1 & 2, yes, we'll need to update CONTRIBUTING.md to reflect this and why not link to the blog post.
match_yaml
good point, updated
Though this relation this can easily be expressed with
[a, b].should.include?(value), so maybe there is no reason to actually have this orbe_true_or_false?Indeed and that's used in some places, but it's not ideal because it reverses the order (the expected value should be on the right and not the left).
So yeah I think we should addbe_one_ofor similar with a better name.
Maybebe_in(a, b)orbe_amongst(a, b)orbe_one_of(a, b).
Python has3 in [1,3] # => Truebut not sure what's a good way to express that in Ruby. I think there was a proposal once to haveObject#in?or so. EDIT: https://bugs.ruby-lang.org/issues/3845Reacted by Alexander BulancovThis is basically all done now, all usages of matchers to be migrated are migrated (though they don't warn for deprecation yet), I added
.should.raiseand updated CONTRIBUTING.md.
What's left is:- Deprecate old matchers: ruby/mspec@82868a2
- Cleanups related to the matchers we keep
- Add
be_inor so
- added a commit that references this issue
on Jun 6, 2026 - added a commit that references this issue
on Jul 27, 2026
Looking at this list we'd remove (or maybe deprecate first? but seems unnecessary) in MSpec and migrate usages in ruby/spec for:
We'd keep (because they cannot be expressed easily as
.should.foo):Others:
The reasoning is those matchers to be removed do nothing more than just
.should.fooand it's far clearer to have the method call literally in the code vs having to "deserialize RSpec notation". See this discussion and this blog post for more thoughts on this.Right now we use a mix of both but it'd be good to be consistent.