Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

9 participants

@radar

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
@qrush

This patch is not working in the rubygems.org test suite yet.

@dpsk

this issue is really annoy me :(

@mike-burns
Admin

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

@qrush

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

@mike-burns
Admin

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 mike-burns closed this
@ivanoats

@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

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

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

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

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

@asanghi

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

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.

@mattconnolly

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

@vshete vshete referenced this pull request from a commit in webstream-io/jobsworth
@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
Commits on Nov 29, 2011
  1. @radar

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

    radar authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/shoulda/context.rb
View
2  lib/shoulda/context.rb
@@ -1,4 +1,4 @@
-require 'test/unit'
+require 'test/unit/testcase'
require 'shoulda/context/version'
require 'shoulda/context/proc_extensions'
require 'shoulda/context/assertions'
Something went wrong with that request. Please try again.