[Rspec-users] support for arbitrary comparisons

David Chelimsky dchelimsky at gmail.com
Wed Sep 6 10:52:55 EDT 2006


Mike Williams contributed a patch to support arbitrary comparisons.
This is now in the trunk and will be part of the next release. So you
will now be able to do this:

result.should_be < 5
result.should_be >= 7

It also supports alternate syntax for should_be, should_match

result.should == 3
result.should =~ /regex/

Personally, I prefer should_be and should_match in these cases, as I
think they read better. Anyone else have opinions about that?

This patch also supports using methods that are not formatted like
predicates but act like them:

def whatever
  true
end

subject.should_be_whatever

I really object to this on philosophical grounds. Ruby predicates are
a beautiful construct, and I personally feel that if you're writing
methods like that you are violating a ruby aesthetic. If you agree
with that, then you have to agree that supporting them in rspec also
violates the same aesthetic. To that end, even though they work, they
will not be offically supported at this point (i.e. you can use them,
but they may go away some day).

I'm curious to hear thoughts on this as well.

Thanks again to Mike Williams for supporting arbitrary comparisons.
It's really a great addition.

Cheers,
David


More information about the Rspec-users mailing list