Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

uninitialized constant Test::Unit::TestCase::Assertions (NameError) #482

Closed
Znow opened this issue Oct 20, 2011 · 28 comments
Closed

uninitialized constant Test::Unit::TestCase::Assertions (NameError) #482

Znow opened this issue Oct 20, 2011 · 28 comments

Comments

@Znow
Copy link

Znow commented Oct 20, 2011

Hi there.

I get this error, EVERY time I try run guard or bundle exec rspec or similar..

ive tried googling the error for the past couple of hours and days.

the full error msg:

/home/dg/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/test/unit/testcase.rb:9:in <class:TestCase>': uninitialized constant Test::Unit::TestCase::Assertions (NameError)
from /home/dg/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/test/unit/testcase.rb:8:inmodule:Unit'
from /home/dg/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/test/unit/testcase.rb:4:in <module:Test>'
from /home/dg/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/test/unit/testcase.rb:3:in'
from /home/dg/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/test/unit.rb:5:in <top (required)>'
from /home/dg/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/test/unit/assertions.rb:4:in'
from /home/dg/.rvm/gems/ruby-1.9.2-p290/gems/rspec-rails-2.7.0/lib/rspec/rails/adapters.rb:2:in <top (required)>'
from /home/dg/.rvm/gems/ruby-1.9.2-p290/gems/rspec-rails-2.7.0/lib/rspec/rails.rb:10:in'
from /home/dg/Projects/advicecapital/spec/spec_helper.rb:4:in <top (required)>'
from /home/dg/Projects/advicecapital/spec/models/user_spec.rb:1:inrequire'
from /home/dg/Projects/advicecapital/spec/models/user_spec.rb:1:in <top (required)>'
from /home/dg/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:inload'
from /home/dg/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in block in load_spec_files'
from /home/dg/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:inmap'
from /home/dg/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in load_spec_files'
from /home/dg/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:18:inrun'
from /home/dg/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:80:in run_in_process'
from /home/dg/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:69:inrun'
from /home/dg/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:10:in `block in autorun'

thanks in advance

@justinko
Copy link
Contributor

Are you including the assertions like this?

RSpec.configure do |config|
  config.expect_with :stdlib
  config.include ActiveSupport::Testing::Assertions
end

@Znow
Copy link
Author

Znow commented Oct 21, 2011

I just included that in my spec_helper.rb - but getting the same error

@jonolsson
Copy link

I had the same problem, and got it working by adding
require 'test/unit'
to the top of spec/spec_helper.rb

@Znow
Copy link
Author

Znow commented Oct 21, 2011

yep that sorted the issue, thanks.

but still, it should be fixed from within rspec

@Znow Znow closed this as completed Oct 21, 2011
@kinopyo
Copy link

kinopyo commented Nov 3, 2011

I encountered same issue. @helloworld's solution worked.
But still same option with @Znow, it should be fixed from within rspec.

@justinko
Copy link
Contributor

justinko commented Nov 4, 2011

You should not have to require test/unit. I'd like to see what you've got in your spec_helper.rb

@kinopyo
Copy link

kinopyo commented Nov 4, 2011

@justinko, I think my spec_helper.rb is almost same as default.

Here is the codes without comments.

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  config.mock_with :rspec

  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = true
end

If I don't put require 'test/unit' I would get the error.

@Znow
Copy link
Author

Znow commented Nov 4, 2011

@justinko - The issue is we have to include it? Thats why this issue is here.

my spec_helper.rb is exact as @kinopyo - default spec_helper

@justinko
Copy link
Contributor

justinko commented Nov 7, 2011

@kinopyo - looking at what you pasted, you need to add this line:

config.expect_with :stdlib

That will load in the T/U assertions.

@myronmarston
Copy link
Member

@justinko--for T/U assertion usage with rspec-core, you're right. However, looking at the backtrace from @Znow, it appears to be an rspec-rails issue. The backtrace shows that rspec rails is requiring "test/unit/assertions" (here) and that is generating this error, even though he may not want to specifically use the test unit assertions (and hence, shouldn't have to configure expect_with :stdlib). Maybe we need to add a require 'test/unit' to rspec-rails so it doesn't trigger this error?

@myronmarston
Copy link
Member

@Znow--in the future, please try to report issues involving rspec-rails (especially when rspec-rails is in the backtrace) to the rspec-rails issue tracker. In that would have cut down on the miscommunication on this thread. @justinko assumed you were reporting an rspec-core issue since you reported it to rspec-core.

@justinko
Copy link
Contributor

justinko commented Nov 7, 2011

This issue is really bizarre.

If you look at the stack trace, all of the necessary files are being required. The error is basically saying that a module (Assertions) doesn't exist. The exception occurs in this file, which you can see that the Assertions module is being required.

Obviously, if this was a "user wide" problem, blowing up every Rails app, it'd be fixed by now. I think the issue is specific to their environment.

@Znow - can you paste your Gemfile? I'm stumped, and that's all I can think of.

Hmm, maybe @dchelimsky has an idea.

P.S. @myronmarston - your hyphens are blocking github from "tagging" the username.

@Znow
Copy link
Author

Znow commented Nov 7, 2011

@myronmarston - okay...

@justinko - https://github.com/Znow/advicecapital/blob/master/Gemfile <- this is a Gemfile for a larger project, but still the same issue. I had to manually require 'test/unit' in spec_helper

@justinko
Copy link
Contributor

justinko commented Nov 7, 2011

@Znow - 3 things:

1.) You have minitest included twice in the Gemfile.
2.) You don't need to include minitest. It is part of the Ruby 1.9 standard library.
3.) No need to have :require => 'spec'

I'm confident fixing those 3 things will fix this issue.

@kinopyo
Copy link

kinopyo commented Nov 8, 2011

@Znow, @justinko, I think I found the problem. It's gem 'turn'.

I had 'minitest' in my Gemfile too, after I removed it and ran the rake spec, I got this error. Here is the stack trace.

/Users/aa/.rvm/gems/ruby-1.9.2-p290/gems/turn-0.8.3/lib/turn/autorun/minitest.rb:14:in `<top (required)>'
/Users/aa/.rvm/gems/ruby-1.9.2-p290/gems/turn-0.8.3/lib/turn.rb:13:in `require'
/Users/aa/.rvm/gems/ruby-1.9.2-p290/gems/turn-0.8.3/lib/turn.rb:13:in `<top (required)>'
/Users/aa/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
/Users/aa/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/Users/aa/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
...

You can see that error comes from turn. Seems like turn was requiring minitest.

# under /Users/aa/.rvm/gems/ruby-1.9.2-p290/gems/turn-0.8.3/lib/turn/autorun/minitest.rb 
require 'turn/autoload'

require 'minitest/unit'
require 'minitest/spec'

require 'turn/colorize'
require 'turn/controller'
require 'turn/runners/minirunner'

if MiniTest::Unit.respond_to?(:runner=)
  MiniTest::Unit.runner = Turn::MiniRunner.new
else
  raise "MiniTest v#{MiniTest::Unit::VERSION} is out of date.\n" \
        "`gem install minitest` and add `gem 'minitest' to you test helper."
  #MiniTest::Unit = Turn::MiniRunner
end

So to sum up:
1.) Remove 'turn' and 'minitest' from Gemfile.
2.) No need to require 'test/unit' in spec_helper.rb
3.) Also don't need this one: config.expect_with :stdlib, default just works fine.

@Znow
Copy link
Author

Znow commented Nov 8, 2011

@justinko - Yes, my :require => 'rspec' was necessary, or else it wouldnt recognize a certain command.

and no, those 3 issues wont fix the issue, because I have already tried that, without any luck.

@justinko
Copy link
Contributor

justinko commented Nov 8, 2011

@Znow - did you do what @kinopyo did? Remove the 'turn' gem.

@pheen
Copy link

pheen commented Nov 12, 2011

Hi @justinko, I was having the same issue:

C:\Sites\tasks>guard
[0mUsing polling (Please help us to support your system better than that).[0m
[0mGuard is now watching at 'C:/Sites/tasks'[0m
[0mGuard::RSpec is running, with RSpec 2![0m
[0m←[0mRunning all specs←[0m
You must use ANSICON 1.31 or later (http://adoxa.110mb.com/ansicon/) to use colo
ur on Windows
C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/test/unit/testcase.rb:9:in `<class:Te
stCase>': uninitialized constant Test::Unit::TestCase::Assertions (NameError)
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/test/unit/testcase.rb:8:
in `<module:Unit>'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/test/unit/testcase.rb:4:
in `<module:Test>'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/test/unit/testcase.rb:3:
in `<top (required)>'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/test/unit.rb:5:in `<top
(required)>'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/test/unit/assertions.rb:
4:in `<top (required)>'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-rails-2.
7.0/lib/rspec/rails/adapters.rb:2:in `<top (required)>'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-rails-2.
7.0/lib/rspec/rails.rb:10:in `<top (required)>'
        from C:/Sites/tasks/spec/spec_helper.rb:4:in `<top (required)>'
        from C:/Sites/tasks/spec/requests/tasks_spec.rb:1:in `require'
        from C:/Sites/tasks/spec/requests/tasks_spec.rb:1:in `<top (required)>'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/configuration.rb:459:in `load'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/configuration.rb:459:in `block in load_spec_files'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/configuration.rb:459:in `map'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/configuration.rb:459:in `load_spec_files'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/command_line.rb:18:in `run'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/runner.rb:80:in `run_in_process'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/runner.rb:69:in `run'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/runner.rb:10:in `block in autorun'

and my Gemfile looked like:

source 'http://rubygems.org'

gem 'rails', '3.1.1'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :test, :development do
    gem 'turn'
    gem 'minitest', '~> 2.6.1'
    gem 'rspec-rails'
    gem 'capybara'
    gem 'guard-rspec'
    gem 'rb-notifu'
end

I removed gem 'turn' from my Gemfile and it solved the issue.

C:\Sites\tasks>guard
[0mUsing polling (Please help us to support your system better than that).[0m
[0mGuard is now watching at 'C:/Sites/tasks'[0m
[0mGuard::RSpec is running, with RSpec 2![0m
[0m←[0mRunning all specs←[0m
You must use ANSICON 1.31 or later (http://adoxa.110mb.com/ansicon/) to use colo
ur on Windows
F

Failures:

  1) Tasks GET /tasks works! (now write some real specs)
     Failure/Error: get tasks_index_path
     NameError:
       undefined local variable or method `tasks_index_path' for #<RSpec::Core::
ExampleGroup::Nested_1::Nested_1:0x28c6260>
     # ./spec/requests/tasks_spec.rb:7:in `block (3 levels) in <top (required)>'


Finished in 26.64 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/tasks_spec.rb:5 # Tasks GET /tasks works! (now write some
real specs)

Awesome, thanks! I just installed ruby so I pretty much have a default installation. I had thought getting an error like this was a bit odd.

Btw, quick question if you don't mind. Where it says "←[0mUsing polling (Please help us to support your system better than that).←[0m", what does that actually mean? I assumed it was because I was using cmd instead of another tool, but I've tried google-ing it and I'm wasn't really able to find anything helpful.

@myronmarston
Copy link
Member

Btw, quick question if you don't mind. Where it says "←[0mUsing polling (Please help us to support your system better than that).←[0m", what does that actually mean? I assumed it was because I was using cmd instead of another tool, but I've tried google-ing it and I'm wasn't really able to find anything helpful.

It's a message from guard. It means it has to use polling to detect file changes, as opposed to an event-based system. See the guard readme for more info.

@nogeek
Copy link

nogeek commented Jul 4, 2012

+1 to removing gem "turn" to solve this issue

@aspiers
Copy link

aspiers commented Mar 16, 2013

-1 to removing turn being considered as a general solution, since it is a valid use case to have both Test::Unit and RSpec tests in the same code tree, and turn is a nice way to get decent output from Test::Unit. If turn is the culprit, then an issue should be submitted to the turn issue tracker. Otherwise RSpec should be fixed to tolerate the presence of turn.

@myronmarston
Copy link
Member

-1 to removing turn being considered as a general solution, since it is a valid use case to have both Test::Unit and RSpec tests in the same code tree, and turn is a nice way to get decent output from Test::Unit.

I would agree that it should be fine to have both T::U tests and rspec specs in the same project, and to use turn with the T::U tests. As far as I know, having this setup doesn't cause problems....it's once you load turn in the RSpec environment that it causes problems. Can't you simply load turn only in your T::U tests?

If turn is the culprit, then an issue should be submitted to the turn issue tracker.

I agree. I've never used turn and don't have the time to play with it, but if anyone can determine if turn is at fault in any way, I would encourage you to submit an issue to the turn tracker.

Otherwise RSpec should be fixed to tolerate the presence of turn.

I'm not convinced RSpec should work around a gem that's only designed to work with an entirely different test framework when the simple solution is to simply not load it in your rspec environment.

@aspiers
Copy link

aspiers commented Mar 17, 2013

Submitted as turn-project/turn#117.

@trans
Copy link

trans commented Mar 17, 2013

Has anyone tried putting gem 'turn' below gem 'rspec-rails', also below gem 'minitest'?

@myronmarston
Copy link
Member

It's still unclear to me why anyone is loading turn in your rspec environment. As I asked above, why can't you just only load it in your Test::Unit environment?

@aspiers
Copy link

aspiers commented Mar 17, 2013

Presumably you mean gem 'turn', require: false in Gemfile, and then only require 'turn' in test/test_helper.rb? I'm pretty sure I tried that, but ICBW ... I think the issue might be that turn in Gemfile pulls in minitest.

@myronmarston
Copy link
Member

That, or not using Bundler.require at all. I think it should be avoided and bundler's maintainer expressed agreement with this.

@aspiers
Copy link

aspiers commented Mar 17, 2013

Ah, so maybe the problem is that minitest is automatically being required even though auto-require of turn is disabled? Thanks for the link, I didn't know about that! I was wondering why rake was so damn slow ;-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants