More loosely typed expression

Discussion in 'Ruby' started by Oliver Saunders, Jan 8, 2008.

  1. 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-forum.com/.
     
    Oliver Saunders, Jan 8, 2008
    #1
    1. Advertising

  2. On Jan 7, 2008 7:25 PM, Oliver Saunders <> 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.denhaven2.com/
     
    Rick DeNatale, Jan 8, 2008
    #2
    1. Advertising

  3. Oliver Saunders

    Guest

    On Jan 7, 7:25 pm, Oliver Saunders <> 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-forum.com/.


    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
     
    , Jan 8, 2008
    #3
  4. Oliver Saunders

    Guest

    On Jan 7, 11:01 pm, "" <> 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
     
    , Jan 8, 2008
    #4
  5. On Jan 7, 2008 11:05 PM, <> 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.denhaven2.com/
     
    Rick DeNatale, Jan 8, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ersin Gençtürk
    Replies:
    1
    Views:
    3,501
    Ersin Gençtürk
    Oct 6, 2004
  2. Michael
    Replies:
    4
    Views:
    427
    Matt Hammond
    Jun 26, 2006
  3. Richard Maher
    Replies:
    4
    Views:
    796
    Thomas 'PointedEars' Lahn
    Jan 10, 2010
  4. Yingjie Lan
    Replies:
    4
    Views:
    309
    John Nagle
    Jan 29, 2010
  5. Richard Maher
    Replies:
    4
    Views:
    141
    Thomas 'PointedEars' Lahn
    Jan 10, 2010
Loading...

Share This Page