More loosely typed expression

  • Thread starter Oliver Saunders
  • Start date
O

Oliver Saunders

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?
 
R

Rick DeNatale

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
 
J

jwmerrill

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?

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
 
J

jwmerrill

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top