Failure to render diff for 'nil.should == something_not_nil'
When the thing you are writing a spec for yields nil, and the expected value is different, the error is not what you would hope for:
describe 'Sandbox' do
it 'should show the difference' do
nil.should == 'foo'
end
end
user@machine:~/dev/ruby/sandbox$ rspec spec/nil_fail.rb F
Failures:
- Sandbox should show the difference
$REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:138:in
find_failed_line': undefined methoddowncase' for nil:NilClass (NoMethodError) from $REE_gems_path/rspec-expectations-2.0.0.rc/lib/rspec/expectations/fail_with.rb:29:indetect' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:ineach' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:indetect' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:infind_failed_line' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:122:inread_failed_line' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:27:indump_failures' from $REE_gems_path/rspec-expectations-2.0.0.rc/lib/rspec/expectations/fail_with.rb:29:ineach_with_index' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:ineach' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:ineach_with_index' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:indump_failures' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:74:insend' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:74:innotify' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:73:ineach' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:73:innotify' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:22:inconclude' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:13:inreport' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/command_line.rb:23:inrun' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:55:inrun_in_process' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:46:inrun' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:10:inautorun' from rspec:19
I just pasted your example into a file and ran it against rspec-2.0.0.rc and the current master using ruby 1.8.6, 1.8.7, 1.9.2, ree-1.8.7, and jruby, and got this in every case:
Failures:
1) Sandbox should show the difference
Failure/Error: nil.should == 'foo'
expected: "foo",
got: nil (using ==)
I'm closing this as I can not reproduce it, but if you are able to provide information I can use to reproduce it I'll be glad to reopen it.
Strange, I'm not sure what the difference between your setup and mine might be. This one is Ubuntu Lucid, REE 2010.02
I can reproduce it in a clean environment:
-
gem uninstall rspec rspec-core rspec-expectations rspec-mocks
-
gem install rspec rspec-core rspec-expectations rspec-mocks --pre ('gem install rspec --pre' doesn't pull the other the others along; should that be the case?)
-
Create a new empty directory.
-
Create a Gemfile with one line:
gem 'rspec', '2.0.0.rc',
-
Run 'bundle install'
-
Create a directory 'spec' with one file, 'nil_fail.rb', with the content from my original post.
-
Run 'rspec spec/nil_fail.rb' or 'bundle exec rspec spec/nil_fail.rb' and it fails.
Do you have any suggestions on what might be wrong over here?
re: the dependent gems not being installed, I'm guessing you have an older version of rubygems, in which case you should definitely upgrade to 1.3.7.
re: why you're seeing different behaviour from me, I'm stumped. Why don't you post this to the rspec-user's list and we'll see if anyone with the same setup as you can be of any help.
Concerning the dependent gems: REE 2010.02 comes with rubygems 1.3.7, so that shouldn't be the problem. I removed all installed gems and after that rspec once again pulls the others along. It seems another gem can get in the way, though I don't know which one it was.
I also have this issue on Ubuntu maybe it has to do with the gems system on Ubuntu. Confusion please let me know if you find anything out. I will do the same if I find anything.
A little more information is that it is the path argument that is nil.
The fact that the expectation is set on nil is a red herring. The problem is actually the same one that is reported in #190, which is that if the file name doesn't end in _spec.rb, the file location is not stored correctly by rspec, and the error is generated when trying to report the failure.
Verified: renaming the file to end in _spec.rb solves the issue and results in the expected diff.