Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

after mocha update from 0.9.5 to 0.9.6 unit tests fails to execute

#50

Unit tests fails


/usr/local/bin/ruby18 -I"lib:test" "/home/taro/gems/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/helpers/items_helper_test.rb" "test/unit/helpers/users_helper_test.rb" "t
est/unit/helpers/user_sessions_helper_test.rb" "test/unit/helpers/comments_helper_test.rb" "test/unit/helpers/checklist_templates_helper_test.rb" "test/unit/helpers/checklists_helper
_test.rb" "test/unit/helpers/companies_helper_test.rb" "test/unit/item_test.rb" "test/unit/user_test.rb" "test/unit/asset_test.rb" "test/unit/comment_test.rb" "test/unit/checklist_te
mplate_test.rb" "test/unit/company_test.rb" "test/unit/checklist_test.rb"
/home/taro/gems/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:105:in `const_missing': uninitialized constant Test::Unit::TestResult::TestResultFailureSupport (NameError
)
        from /home/taro/gems/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 /home/taro/gems/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:158:in `require'
        from /home/taro/gems/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 /home/taro/gems/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:158:in `require'
        from /home/taro/gems/gems/test-unit-2.0.2/lib/test/unit/ui/console/testrunner.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 /home/taro/gems/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:158:in `require'
        from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:25
        from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:214:in `[]'
        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 /home/taro/gems/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5

Reported by iwakura-taro · June 30th, 2009 @ 05:36 PM

State: open
Milestone: none
Assigned to: James Mead James Mead

Activity

  1. James Mead
    James Mead
    • Tag set to bug-report

    Thanks for reporting the problem. I'd be really grateful if you could supply us with a bit more information :-

    What version of Ruby are you using?

    What version of the test-unit gem are you using?

    Are you running this in a Rails project using "rake test:units"? If yes, what version of Rails?

    Does it work if you uninstall the test-unit gem? Or are you relying on functionality provided in the test-unit gem?

    Also does it fail if you run a single unit test using Ruby not Rake? e.g. "ruby test/unit/user_test.rb"? Do all unit tests fail the same way?

    Thanks, James.

    June 30th, 2009 @ 05:46 PM

  2. James Mead
    James Mead

    I have reproduced the problem with Ruby 1.8.6, Rails 2.3.2 and test-unit gem 2.0.2.

    The main problem seems to be that the test-unit gem is not being loaded before Mocha.

    A simple fix seems to be to add a line to test/test_helper.rb as follows :-

    ENV["RAILS_ENV"] = "test"
    require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
    gem 'test-unit' # <= add this line
    require 'test_help'
    

    Please let me know if this fixes your problem.

    Cheers, James.

    June 30th, 2009 @ 06:03 PM

  3. James Mead
    James Mead

    Hmm. That's strange. I wonder if there is a difference between versions of RubyGems. What version do you have? I have 1.3.1.

    You could try :-

    require 'test/unit'
    

    instead of my previous suggestion of :-

    gem 'test-unit'
    

    In test/test_helper.rb.

    Please let me know if this helps.

    Cheers, James.

    June 30th, 2009 @ 10:15 PM

  4. James Mead
    James Mead
    • State changed from new to open

    Thanks for the extra information.

    I think the important thing is for me to understand exactly how and when Mocha is being loaded.

    I'm attaching a patched version of the 0.9.6 mocha gem which prints out some diagnostic data.

    I'd really appreciate it if you could download the mocha-debug-0.9.6.gem file and install it :-

    sudo gem install $DOWNLOAD_PATH/mocha-debug-0.9.6.gem
    

    Note that you will need to replace $DOWNLOAD_PATH with the path to the downloaded file.

    Then if you run your tests and send me the output - that would be great.

    I'd expect to see a "stack trace" which will tell me what is requiring Mocha. I would also expect to see a message explaining what Mocha modules are being included into Test::Unit::TestCase.

    Thanks.

    July 1st, 2009 @ 09:21 AM

  5. James Mead
    James Mead

    It looks like Mocha is being loaded when the thoughtbot-shoulda gem is loaded. This is in turn loading activesupport/testcase.rb which is loading the mocha gem.

    I have reproduced the error [Note 1] in your latest trace by putting creating an empty Rails project and adding the following to config/environment.rb :-

      config.gem 'thoughtbot-shoulda', :version => '2.10.1', :lib => 'shoulda'
    

    And installing the test-unit gem version 2.0.2.

    Then running rake test:functionals gives me the error.

    However, note that this is a different error than the one you originally reported [Note 2].

    If you don't need Mocha for your own tests, can you try uninstalling the Mocha gem. This works for me.

    If you do need Mocha for your own tests, but you don't need the test-unit gem, can you try uninstalling the test-unit gem. This works for me.

    If you do need Mocha and you do need the test-unit gem, can you try adding a line in config/environment.rb just before the shoulda gem is required :-

      gem 'test-unit'
      config.gem 'thoughtbot-shoulda', :version => '2.10.1', :lib => 'shoulda'
    

    This fixes the problem for me.

    Let me know if any of these solutions work for you.

    BTW - it might be more sensible to require the shoulda in config/environments/test.rb, because I you probably only want it loaded in the test environment.

    Cheers, James.

    [Note 1] uninitialized constant Test::Unit::TestCase::DESCENDANTS (NameError) in gems/test-unit-2.0.2/lib/test/unit/collector/descendant.rb:14

    [Note 2] uninitialized constant Test::Unit::TestResult::TestResultFailureSupport (NameError) in gems/test-unit-2.0.2/lib/test/unit/testresult.rb:28

    July 1st, 2009 @ 12:17 PM

  6. James Mead
    James Mead
    • State changed from open to resolved

    July 1st, 2009 @ 04:56 PM

  7. James Adam
    James Adam

    I have hit this issue outwith any Rails context. With both Ruby 1.8.7 and 1.9.1, if you install the test-unit gem (2.0.7) and mocha (0.9.8), and then run the following script, the exception will be raised:

    require 'rubygems'
    require 'test/unit'
    require 'mocha'
    

    I believe this is happening because test/unit is being loaded from the ruby standard library. Then, when mocha loads, it detects that test/unit is present (via Mocha::Integration.test_unit_testcase_defined?), but then tries to detect the version (see mocha/integration/test_unit.rb) by calling require "test/unit/version".

    Because this file doesn't exist in the standard library, I believe Rubygems is then allowing require to start searching within gems, finally finding the file in the test-unit gem. This then causes some of the gem to load, despite other parts of Test::Unit already being loaded from the standard library.

    In my particular case, I have the gem present for another project, but don't want to make it a requirement of my current project, so we're a bit stuck.

    I can't think of a good solution for this. Some ideas:

    • trying to detect which version of test/unit is loaded in some way other than requiring any files (and thus triggering Rubygems' overly-helpful behaviour)
    • side-stepping the issue by using Bundler to 'isolate' the available gems in my project

    Anyway, I thought it might be useful to write this out, if only for further thought.

    May 31st, 2010 @ 10:26 PM

  8. James Mead
    James Mead

    Hi James,

    That's really helpful - thanks.

    It might be worth trying the same experiment with Mocha built from HEAD. I suspect it won't actually fix the problem, but I've added more debug information and I've provides integration monkey-patches for more recent versions of e.g. test-unit.

    It sounds like it might be worth trying your first suggested solution i.e. detecting test-unit version without requiring files.

    Cheers, James.

    June 1st, 2010 @ 08:12 AM

  9. James Mead
    James Mead
    • State changed from resolved to open

    June 1st, 2010 @ 08:13 AM

  10. James Mead
    James Mead

    I've pushed up an attempted fix for this [1]. Is there any chance you could try it out?

    I'm not 100% convinced it's a sensible solution, but it seems to do the job. I have a slight concern it may have undesirable side effects.

    [1] http://github.com/floehopper/mocha/commit/22599b8bbc99f72b8c33f76df...

    June 5th, 2010 @ 05:46 PM

  11. James Mead
    James Mead
    • State changed from open to resolved
    • Milestone order changed from 0 to 0

    This was fixed in Mocha 0.9.9 :-

    $ ruby -v
    ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.4.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02
    $ rvm gemset use mochabug
    Now using gemset 'mochabug'
    $ gem install test-unit -v2.0.7
    Successfully installed test-unit-2.0.7
    1 gem installed
    $ gem install mocha -v0.9.8
    Successfully installed mocha-0.9.8
    1 gem installed
    $ cat bug.rb
    require 'rubygems'
    require 'test/unit'
    require 'mocha'
    $ ruby bug.rb
    /Users/jamesmead/.rvm/gems/ree-1.8.7-2010.02@mochabug/gems/test-unit-2.0.7/lib/test/unit/testresult.rb:28: uninitialized constant Test::Unit::TestResult::TestResultFailureSupport (NameError)
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /Users/jamesmead/.rvm/gems/ree-1.8.7-2010.02@mochabug/gems/test-unit-2.0.7/lib/test/unit/ui/testrunnermediator.rb:9
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /Users/jamesmead/.rvm/gems/ree-1.8.7-2010.02@mochabug/gems/test-unit-2.0.7/lib/test/unit/ui/console/testrunner.rb:11
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/test/unit/autorunner.rb:25
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/test/unit/autorunner.rb:214:in `[]'
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/test/unit/autorunner.rb:214:in `run'
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
        from /Users/jamesmead/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/test/unit.rb:279
    $ gem uninstall mocha -v0.9.8
    Successfully uninstalled mocha-0.9.8
    $ gem install mocha -v0.9.9 
    Successfully installed mocha-0.9.9
    1 gem installed
    $ ruby bug.rb
    Loaded suite bug
    Started
    
    Finished in 0.000143 seconds.
    
    0 tests, 0 assertions, 0 failures, 0 errors
    

    I've also tried the same test in Ruby 1.9.2.

    I'm closing this ticket. Thanks.

    November 26th, 2010 @ 11:12 AM

  12. James Mead
    James Mead

    Note that the fix mentioned above has been reverted [1] in the latest Mocha.

    We believe the problem can be averted by adding a gem "test-unit" statement before require "test/unit".

    [1] https://github.com/freerange/mocha/pull/140

    March 4th, 2013 @ 12:56 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.