Afficher un message
Vieux 12/06/2008, 00h31   #4
Rick DeNatale
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rspec and inequalities?

[Note: parts of this message were removed to make it a legal post.]

On Mon, Jun 9, 2008 at 11:54 AM, Mark Thomas <ruby@thomaszone.com> wrote:

>
> > It's basically the same:
> >
> > x.should be < y
> >
> > James

>
> Thanks! Is this syntactic sugar for all be_xxx methods?



No.

1.should be > 0
will work, but say:

1.should be_false > 0

will fail when RSpec tries to send #:0? to 1. One might say that this is an
rspec bug, but I'd say that 1.should be_false > 0 is nonsensical, so who
cares.


> I just noticed
> that I can omit the underscore in be_true also. I'm surprised I
> haven't noticed that in examples.



This is because

x.should be y

is interpreted as

x.should eql y

so it will succeed if x.eql?(y) returns a truthy value.

Also note that there's a difference between

x.should be_true
or
x.should be true
or
x.should eql true

and

x.should be

The first three will succeed only iff x == true whereas the latter will
succeed iff x is any truthy value (i.e. anything except nil and false),
likewise

x.should_not be

will succeed iff x is a falsy value (i.e. nil or false)

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

  Réponse avec citation
 
Page generated in 0,06198 seconds with 9 queries