views:

3634

answers:

14

I just updated all my gems and I'm finding that I'm getting errors when trying to run Test::Unit tests. I'm getting the error copied below. That comes from creating new, empty Rails project, scaffolding a simple model, and running rake test.

Tried Googling "uninitialized constant" and TestResultFailureSupport. The only thing I found was this bug report from 2007.

I'm using OS X.

These are the gems that I updated right before the tests stopped working:

$ sudo gem outdated
Password:
RedCloth (4.2.1 < 4.2.2)
RubyInline (3.8.1 < 3.8.2)
ZenTest (4.1.1 < 4.1.3)
bluecloth (2.0.4 < 2.0.5)
capistrano (2.5.5 < 2.5.8)
haml (2.0.9 < 2.2.1)
hoe (2.2.0 < 2.3.2)
json (1.1.6 < 1.1.7)
mocha (0.9.5 < 0.9.7)
rest-client (1.0.2 < 1.0.3)
thoughtbot-factory_girl (1.2.1 < 1.2.2)
thoughtbot-shoulda (2.10.1 < 2.10.2)

Has anyone else seen this issue? Any troubleshooting suggestions?


UPDATE

On a hunch I downgraded ZenTest from 4.1.3 back to 4.1.1 and now everything works again.

Still curious to know if anyone else has seen this or has any interesting comments or insights.


$ rake test
(in /Users/me/foo)
/usr/local/bin/ruby -I"lib:test" "/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/helpers/users_helper_test.rb" "test/unit/user_test.rb" 
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:105:in `const_missing': uninitialized constant Test::Unit::TestResult::TestResultFailureSupport (NameError)
    from /usr/local/lib/ruby/gems/1.8/gems/test-unit-2.0.2/lib/test/unit/testresult.rb:28
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:158:in `require'
    from /usr/local/lib/ruby/gems/1.8/gems/test-unit-2.0.2/lib/test/unit/ui/testrunnermediator.rb:9
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:158:in `require'
     ... 6 levels...
    from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:214:in `run'
    from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
    from /usr/local/lib/ruby/1.8/test/unit.rb:278
    from /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
/usr/local/bin/ruby -I"lib:test" "/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/functional/users_controller_test.rb"
+4  A: 

This apparently comes from using Test::Unit 2.0 with the old Test::Unit. According to Kouhei Sutou on RubyForge, it can be fixed by calling gem 'test-unit' before you require 'test/unit'.

Chuck
or uninstall the test-unit gem (if that's an available option).
rogerdpack
+5  A: 

This can happen if modules are declared in a single statement when the parent module they are nested inside has not yet been loaded. I haven't looked at the code in those gems, but my hunch is that's what is happening. Chuck's solution would suggest that. calling gem 'test-unit' first will load the parent module, so the setup of zen test ends up working ok.

e.g.

module Foo::Bar
  def do_stuff
    # insert awesomeness here...
  end
end

Will result in an error if the parent Foo module hasn't already been defined (e.g. by another gem)

A safer way to declare this is

module Foo
  module Bar
    def do_stuff
      # insert awesomeness here...
    end
  end
end

May be a bug in Zentest that needs patching.

madlep
+3  A: 

As this link suggests http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/50 it may happen due to preliminary initialization of mocha lib. To prevent it from happeing it is advisable to add line

config.gem 'test-unit', :lib => 'test/unit'

to config/environment.rb

Anaderi
in cases where this works, note you can also just put in config/environments/test.rb
tardate
+1  A: 

I have this problem on OS X 10.6 and I don't seem to be able to solve it without uninstalling either test-unit (2.0.5) or mocha (0.9.8). Unfortunately, I have dependencies on both of these.

I can distill the problem right down to:

rails blah; cd blah # rails 2.3.4 ruby -I. -e 'require "test/unit"' # as done by autotest

At this point, I get the exception:

/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:105:in const_missing': uninitialized constant Test::Unit::TestResult::TestResultFailureSupport (NameError) from /Library/Ruby/Gems/1.8/gems/test-unit-2.0.5/lib/test/unit/testresult.rb:28 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require' ...

Tried the config.gem cure suggested above. It doesn't seem to work for me.

Ritchie
I have the same problem. I put the `mocha` gem declaration above the `shoulda` one, which worked for `rake test`, but not for `autotest`.
James A. Rosen
+1  A: 

I was getting this without mocha or shoulda installed.

This post suggests it's due to an incompatibility in test-unit >= 2.0, which I installed as a dependency for the systools gems. Downgrading to 1.2.3 worked for me, a simple require might also.

scottburton11
+1  A: 

Same issue with me too. Nothing above mentioned worked for me except downgrading test-unit back to 1.2.3 I'm missing the coloring of the test-unit 2.x

Millisami
You can add the `redgreen` gem to get your coloring back.
James A. Rosen
A: 

Found the (ugly) solution:

gem 'unit/test' must be called inside the tests too, not only in the Rakefile.

Elia Schito
+3  A: 

Here is the recipe for test_unit 2.0.7 on Rails 2.3.5:

In config/environments/test.rb:

config.gem 'test-unit', :version => '2.0.7', :lib => false

In test_helper.rb, add require 'test/unit', immediately after require 'test_help'

So it looks like this:

require 'test_help'
require 'test/unit'

If you receive this error: %': one hash required (ArgumentError), upgrade gem i18n to v0.3.6.

Matt Scilipoti
A: 

I ran into this today on Mac OS X 10.6. My solution is as follows:

config.gem 'test-unit', :lib => 'test/unit', :version => '1.2.3'
config.gem 'autotest'
config.gem 'cucumber'
config.gem 'cucumber-rails', :lib => false
config.gem 'ffaker', :lib => 'faker'
config.gem 'rspec', :lib => false, :version => '>= 1.2.0'
config.gem 'rspec-rails', :lib => false, :version => '>= 1.2.0'
config.gem 'selenium-client', :lib => 'selenium'
config.gem "thoughtbot-factory_girl", :lib => 'factory_girl', :source => "http://gems.github.com"
config.gem 'thoughtbot-shoulda', :lib => 'shoulda'
config.gem 'webrat'
config.gem 'ZenTest', :lib => 'zentest'
Martin Streicher
+1  A: 

As with aronchick's comment, for me (OS X 10.6) solution was

sudo gem uninstall test-unit

all versions.

sbwoodside
A: 

If you add the following line to your environment.rb, or your config/environments/test.rb this should fix the issue

config.gem "test-unit", :lib => "test/unit", :version => ">=2.0.9", :env => "test"

I Believe you will need to add it before the mocha line if you use mocha

Mike Simkins
A: 

Following sbwoodside's solution worked for me on OS X 10.5.8.

Chip Castle
A: 

You get auto_test to work again with something like

RUBY="ruby -I.:lib:test -rubygems -e 'gem \"test-unit\"'" autotest

radiospiel
A: 

Same here with OSX 10.6, uninstalling test-unit as suggested sbwoodside worked fine

Dida