[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

More loosely typed expression

Oliver Saunders

1/8/2008 12:26:00 AM

I'm just trying out RSpec with some really simple code. I have this
line:

@subject.num(0).fizz?.should == false

And I want it to pass if it's false OR nil. I tried using =~ but it made
no difference. Is there no way to do this in Ruby?
--
Posted via http://www.ruby-....

4 Answers

Rick DeNatale

1/8/2008 3:15:00 AM

0

On Jan 7, 2008 7:25 PM, Oliver Saunders <oliver.saunders@gmail.com> wrote:
> I'm just trying out RSpec with some really simple code. I have this
> line:
>
> @subject.num(0).fizz?.should == false
>
> And I want it to pass if it's false OR nil. I tried using =~ but it made
> no difference. Is there no way to do this in Ruby?

@subject.num(0).fizz?.should be

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

jwmerrill@gmail.com

1/8/2008 4:02:00 AM

0

On Jan 7, 7:25 pm, Oliver Saunders <oliver.saund...@gmail.com> wrote:
> I'm just trying out RSpec with some really simple code. I have this
> line:
>
> @subject.num(0).fizz?.should == false
>
> And I want it to pass if it's false OR nil. I tried using =~ but it made
> no difference. Is there no way to do this in Ruby?
> --
> Posted viahttp://www.ruby-....

This doesn't exactly answer your question, but isn't it unusual to
have a method suffixed with a ? that doesn't return a boolean value?
Anyway, here's a solution:

@subject.num(0).fizz?.should_not be

Regards,

Jason

jwmerrill@gmail.com

1/8/2008 4:12:00 AM

0

On Jan 7, 11:01 pm, "jwmerr...@gmail.com" <jwmerr...@gmail.com> wrote:

> This doesn't exactly answer your question, but isn't it unusual to
> have a method suffixed with a ? that doesn't return a boolean value?

Oh yeah, the reason I ask is because, if fizz? acted like other ?
methods, you could do

@subject.num(0).should_not be_fizz

JM

Rick DeNatale

1/8/2008 1:20:00 PM

0

On Jan 7, 2008 11:05 PM, jwmerrill@gmail.com <jwmerrill@gmail.com> wrote:


> Anyway, here's a solution:
>
> @subject.num(0).fizz?.should_not be

Time for me to get new reading glasses, I got the sense of the test reversed.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...