should require 'test/unit/testcase' and not 'test/unit' #4

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
9 participants

radar commented Nov 29, 2011

This is because requiring 'test/unit' triggers Test::Unit's autorun functionality, which can lead to errors, as shown in this Gist: https://gist.github.com/1402816.

The problem surfaced in Spree 0.70.0's test suite as well as in Rubygems.org test suite.

By requiring test/unit/testcase instead, it will not trigger this autorun event.

@radar radar should require 'test/unit/testcase' and not 'test/unit'
This is because requiring 'test/unit' triggers Test::Unit's autorun functionality, which can lead to errors, as shown in this Gist: https://gist.github.com/1402816.

The problem surfaced in Spree 0.70.0's test suite as well as in Rubygems.org test suite.
ee902d4

dpsk commented Dec 8, 2011

this issue is really annoy me :(

Owner

mike-burns commented Dec 9, 2011

@qrush, you say this does not work in the wild?

Contributor

qrush commented Dec 9, 2011

Try it out with gemcutter, it wasn't working for me.

Owner

mike-burns commented Jan 13, 2012

We no longer use shoulda-context, and as such we are looking for a new maintainer.

@radar, if you wish to take over please let us know. Same to you @dpsk and @qrush .

Thank you,
-Mike

mike-burns closed this Jan 13, 2012

ivanoats commented Mar 5, 2012

@mike-burns @radar I'm confused, the current gem spec for should requires shoulda-context . What's the best way to resolve this issue so that it does not happen for other people, and so that everyone does not require their own fork of shoulda-context ?

asanghi commented Mar 31, 2012

Just create a fresh new rails app with shoulda gem added using ruby-1.9.3-p125.

rails -v => 3.2.3
gem -v => 1.8.21
bundle -v => 1.1.3
ruby -v => ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.2.0]
rvm -v => 1.11.3
rails new shouldatest
cd shouldatest
echo "gem 'shoulda'" >> Gemfile
bundle
bundle exec rake db:migrate
$ bundle exec rake db:migrate
/Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: db:migrate (ArgumentError)
    from /Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
    from /Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
    from /Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
    from /Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
    from /Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
    from /Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
    from /Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:21:in `run'
    from /Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
    from /Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
    from /Users/adityasanghi/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'

I'll test if @radar's patch works again but just reporting that this is still a problem. If i'm missed something, kindly correct me.

Just to clarify, the rake task actually executes fine but it just ends with the ugly error above.

asanghi commented Mar 31, 2012

To add to this further -

I tested a brand new rails app with shoulda in ruby-1.9.2-p290

rails new shouldatest
cd shouldatest
echo "gem 'shoulda'" >> Gemfile
bundle
bundle exec rake db:migrate

The result was

[ 01:01:39 ] > bundle exec rake db:migrate
Loaded suite /Users/adityasanghi/.rvm/gems/ruby-1.9.2-p290/bin/rake
Started

Finished in 0.001001 seconds.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

Test run options: --seed 3958

Applying @radar's patch makes it work and no extraneous Start/Finish stuff is printed on ruby1.9.2

I'm cloning @rubygems.org repository and trying out the patch there again.

asanghi commented Mar 31, 2012

So somehow I was not able to reproduce the problem with rubygems.org Rails app even though bundler uses the unpatched shoulda-context gem. Perhaps some other gem silences or fixes this bug (I will look deeper).

However, I learnt that adding gem 'test-unit', :require => "test/unit" in my app's Gemfile fixes the error seen above.

It seems from my finding that on ruby1.9.x we have to add test-unit gem if we're using shoulda. The finding seems unscientific to me but it seems like test-unit does handle at_exit hook a bit better than the core ruby lib.

bonyiii commented Mar 31, 2012

Assanghi is right if i add gem 'test-unit', :require => "test/unit" to Gemfile it works.

asanghi commented Mar 31, 2012

I realized I had shoulda gem in the :development group of my Gemfile. It really doesnt need to be. Moving it into the :test group reduces the problem considerably. But you can consistently reproduce the problem when RAILS_ENV=test

levity commented Jun 6, 2012

test-unit does not have all of the same assertions as minitest, so Asanghi's solution was not suitable for me. However, this worked:

# Gemfile
gem 'shoulda', :require => false

# test/test_helper.rb
require 'shoulda'

If you have other gems that require minitest, you will have to do the same thing for them.

I was getting this too, gem 'shoulda', :require => false solved it for me. Thanks.

@vshete vshete pushed a commit to webstream-io/jobsworth that referenced this pull request Dec 23, 2013

@liufengyun liufengyun fix an error when running migrations 93a3ec0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment