[rspec-users] Testing 'nil.should == something_not_nil' fails

Ivo Wever ivo.wever at gmail.com
Wed Oct 13 11:02:25 EDT 2010


Hello,

After upgrading to rspec 2.0.0.rc, I ran into an issue that I reported
at http://github.com/rspec/rspec-core/issues/issue/183/#issue/183. When
testing something that returned nil, effectively executing 'nil.should
== something_not_nil', rspec would come crashing down. It turned out not
to be a bug in rspec (or, at least, David can't reproduce it).

I initially wrote it off as something strange with my setup and worked
around it for now (specs usually succeed, so nil == nil and everything
works fine), but as 'scrymmyin' reported seeing the same behavior in
issue 183, and as I also see it with rspec 2.0.0, I thought it might be
nice to document it here.

I can reproduce the behavior as follows:

- gem install rspec --version=2.0.0
- mkdir sandbox; cd sandbox
- create Gemfile with contents
  gem 'rspec', '2.0.0'
- run bundle install
- mkdir spec
- create spec/nil_fail.rb with contents
describe 'Sandbox' do
  it 'should show the difference' do
    nil.should == 'foo'
  end
end
- run rspec spec/nil_fail.rb

The result is:

user at machine:~/dev/ruby/sandbox$ rspec spec/nil_fail.rb
F

Failures:
1) 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:in
`detect'
from
$REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:in
`each'
from
$REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:in
`detect'
from
$REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:in
`find_failed_line'
from
$REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:122:in
`read_failed_line'
from
$REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:27:in
`dump_failures'
from
$REE_gems_path/rspec-expectations-2.0.0.rc/lib/rspec/expectations/fail_with.rb:29:in
`each_with_index'
from
$REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:in
`each'
from
$REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:in
`each_with_index'
from
$REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:in
`dump_failures'
from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:74:in
`send'
from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:74:in
`notify'
from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:73:in
`each'
from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:73:in
`notify'
from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:22:in
`conclude'
from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:13:in
`report'
from
$REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/command_line.rb:23:in
`run'
from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:55:in
`run_in_process'
from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:46:in `run'
from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:10:in
`autorun'
from $REE_path/bin/rspec:19

best regards,
-- 
Ivo Wever


More information about the rspec-users mailing list