[rspec-users] Expecting nil or false

Scott Taylor scott at railsnewbie.com
Tue Mar 31 12:35:04 EDT 2009

On Mar 31, 2009, at 12:08 PM, Fernando Perez wrote:

> Hi,
> I just ran into this issue. I have a method that returns: false, true,
> nil or an object.
> This method is used by another method to test for true/false. In Ruby
> that's easy to handle as nil and false evaluate to false, and  
> everything
> else evaluates to true, but RSpec seems to expect an exact value  
> such as
> nil, true, false, not_nil, etc.

Use the boolean matchers:

def foo?

obj.should be_foo #=> fails
obj.should_not be_foo  #=> passes


> Do I have to rewrite my return values to always return true or false?
> -- 
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list