cucumber / cucumber-rails

Rails Generators for Cucumber with special support for Capybara and DatabaseCleaner
https://github.com/cucumber/cucumber-rails
MIT License
1.02k stars 327 forks source link

Assert not working? Results in "undefined method `add_assertion' for nil:NilClass" #97

Closed contentfree closed 13 years ago

contentfree commented 13 years ago

I upgraded from the gem version of cucumber-rails to HEAD on the git repo, updated my support files (env.rb et al) and now I'm bombing tests on ol' assert.

My test is a typical assert page.has_css? ... and the resulting error is undefined method 'add_assertion' for nil:NilClass. Stacktrace:

undefined method `add_assertion' for nil:NilClass
/Users/dave/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48 :in `method_missing'
/Users/dave/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/test/unit/testcase.rb:127 :in `add_assertion'
/Users/dave/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/test/unit/assertions.rb:494 :in `_wrap_assertion'
/Users/dave/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/test/unit/assertions.rb:61 :in `assert'
/Users/dave/Sites/mysite.com/features/step_definitions/my_steps.rb:122 

Seems very strange... The problem, apparently, is that TestCase#run is never run, so when assert is called, the @_result variable isn't set and add_assertion barfs.

(Sorry about the double post -- I don't know why #96 got closed.)

contentfree commented 13 years ago

Also, it doesn't happen with my Ruby 1.9.2 install, just 1.8.7. (It was working fine in 1.8.7 until I switched to HEAD on master at the git repo)

contentfree commented 13 years ago

Adding the following to env.rb right after require 'cucumber/rails fixed Ruby 1.8.x for me:

if RUBY_VERSION =~ /1.8/
  require 'test/unit/testresult'
  Test::Unit.run = true
end
atexit commented 13 years ago

I had exactly the same problem, but for 1.9.2. Using contentfree's env.rb workaround made my asserts no longer explode.

pvdb commented 13 years ago

Great fix/workaround by contentfree... thanks!

byrnejb commented 13 years ago

Have this issue as well. Thanks for the work-around.

caseydreier commented 13 years ago

I just had this same issue for Ruby 1.8.7 EE, Rails 3.0.7, and Cucumber 0.10.2 and Cucumber Rails 0.4.1. The fix above worked.

aslakhellesoy commented 13 years ago

Fixed by c032b0cef534d360fe69098ae8e4eb2d6937b2e8