Forum: RSpec [rspec] be_something accepts nils

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2009-03-13 13:46
(Received via mailing list)
Hi

Just noticed that the behaviour of

   @cow.should_not be_hungry

is not the same as

   @cow.hungry?.should == false # nil also passes

Don't know how this has escaped me for so long =)

What's the thinking behind this?  You can already do

   @cow.hungry?.should(_not) be_nil

so surely it makes more sense for be_true and be_false to check for
booleans?

Ashley


--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
http://aviewfromafar.net/
http://twitter.com/ashleymoran
48641c4be1fbe167929fb16c9fd94990?d=identicon&s=25 Mark Wilden (Guest)
on 2009-03-13 15:48
(Received via mailing list)
On Fri, Mar 13, 2009 at 5:17 AM, Ashley Moran >
> What's the thinking behind this?  You can already do
>
>  @cow.hungry?.should(_not) be_nil
>
> so surely it makes more sense for be_true and be_false to check for
> booleans?

In common Ruby use, nil is usually treated the same as false, so
that's the way the dynamic matcher works - it's the most convenent.

You see explicit comparisons against true or false pretty rarely (in
my experience). Unless you have a specific need for a three-valued
truth system (e.g., true, false, and unknown), I think it's best
practice not to assume that if !x == true, then x must == false, and
vice versa.

///ark
39100495c9937c39b2e0c704444e1b4a?d=identicon&s=25 Pat Maddox (Guest)
on 2009-03-13 16:44
(Received via mailing list)
On Mar 13, 2009, at 5:17 AM, Ashley Moran wrote:

> Don't know how this has escaped me for so long =)
>
> What's the thinking behind this?  You can already do
>
>  @cow.hungry?.should(_not) be_nil
>
> so surely it makes more sense for be_true and be_false to check for
> booleans?

be_true and be_false do check for booleans :)  but you didn't use
either of them.

The expanded form of
@cow.should_not be_hungry
is
@cow.hungry?.should_not be

Pat
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2009-03-13 17:51
(Received via mailing list)
On 13 Mar 2009, at 15:42, Pat Maddox wrote:

>> @cow.hungry?.should == false # nil also passes
> be_true and be_false do check for booleans :)  but you didn't use
> either of them.
>
> The expanded form of
> @cow.should_not be_hungry
> is
> @cow.hungry?.should_not be
>
> Pat

Like yoda sounds, that does


Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2009-03-13 21:46
(Received via mailing list)
On 13 Mar 2009, at 16:34, Matt Wynne wrote:

>> The expanded form of
>> @cow.should_not be_hungry
>> is
>> @cow.hungry?.should_not be
>>
>> Pat
>
> Like yoda sounds, that does

And enlightened, I am =)

Thanks Pat

--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
http://aviewfromafar.net/
http://twitter.com/ashleymoran
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2009-04-28 15:34
(Received via mailing list)
On 13 Mar 2009, at 16:34, Matt Wynne wrote:
> Like yoda sounds, that does


Been implemented properly, it has :)

http://blog.zenspider.com/2009/04/spec-yoda-will.html

--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
http://aviewfromafar.net/
http://twitter.com/ashleymoran
This topic is locked and can not be replied to.