Test for function_returning_nil.should have(x).items #141

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@docwhat
docwhat commented Apr 20, 2012

nil.should have(8).items returns the expected output:
expected 8, got 0

You should get the same if you call it on a function that
returns nil. However, you get undefined method .items.

@docwhat docwhat Test for function_returning_nil.should have(x).items
`nil.should have(8).items` returns the expected output:
    expected 8, got 0

You should get the same if you call it on a function that
returns `nil`.  However, you get `undefined method .items`.
c620939
@justinko
Contributor
Failures:

  1) have matcher should have(n).items 
     Failure/Error: nil.should have(8).items
     NoMethodError:
       undefined method `items' for nil:NilClass

I cannot reproduce what you're getting. Also "undefined method `items' for nil:NilClass" is the correct error message.

@justinko justinko closed this Apr 20, 2012
@docwhat
docwhat commented Apr 20, 2012

@justinko That is the result I'm getting.

So is it a bug that nil.should have(8).items returns expected 8, got 0?

I find it confusing that it complains about .items -- it just seems to point at the wrong place. If expected 8, got 0 is wrong that maybe expected 8, got nil would be better.

Ciao!

@justinko
Contributor

What version are you using?

Looks like your nil is not behaving correctly.

@docwhat
docwhat commented Apr 22, 2012

My bad, I should have written it down. I tested it with:

  • ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
  • ruby 1.9.2p318 (2012-02-14 revision 34678) [x86_64-darwin11.3.0]
  • ruby 1.8.7 (2012-02-08 patchlevel 358) [i686-darwin11.3.0]

Huh...okay, I cannot create the expected 8, got 0 error again and I don't know why. I tried it the two projects I've been working on the last few days.

I still think it'd be handy to have a better message, maybe Unable to get length of object 'nil' or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment