14

I have an existing rails 3 project that works just fine on ruby 1.9.2-p290. However upgrading to ruby 1.9.3-p0 causes rake test to spit out the following error:

/Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: test/unit/**/*_test.rb (ArgumentError)
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:21:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'
/Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: test/functional/**/*_test.rb (ArgumentError)
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:21:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'

It seems to be a consequence of this rake issue. However when I create a simple rails project on ruby 1.9.3 so such error occurs. What can I do to get my rails project to run on ruby 1.9.3?

Zameer Manji
  • 3,017
  • 5
  • 31
  • 42
  • Which rails version are you using in your Gemfile? I have just tested a new app on rails 3.1.1 and ruby 1.9.3 p0 - the rake test works ok. – Evgenii Nov 01 '11 at 12:06
  • 1
    I have rails 3.1.1 in my Gemfile. It should also be noted that if I change rake to the 0.9.3.beta.1 it works. However it is not desired to use a beta version of rake with the project. – Zameer Manji Nov 01 '11 at 13:47
  • Is it desired to work with Ruby x.x.x-p0 ? It is usually worse than gem beta. – phil pirozhkov Nov 06 '11 at 20:12
  • The speedup from working with ruby 1.9.3 vs 1.9.2 for a rails project is about 33% with my projects. If my tests run 33% faster it is worth it. – Zameer Manji Nov 07 '11 at 01:02
  • If so, consider beta rake also. – phil pirozhkov Nov 07 '11 at 19:44
  • Yeah, if you're willing to use a 0 patch of a language, then a beta release of a stable gem shouldn't be an issue. – WattsInABox Nov 09 '11 at 20:10
  • As I see you are running bundled test/unit. Ruby 1.9.x extracted the test unit to it's own gem. Try to use that, maybe it's already patched for your bug. http://test-unit.rubyforge.org/ – Dalibor Filus Dec 09 '11 at 21:54
  • Are you using bundle exec when calling rake? bundle exec rake test – house9 Dec 18 '11 at 22:55
  • 3
    Strongly disagree with p0/beta gem comparisons. Ruby release cycle is *far* more stringent than most gems. – Xavier Shay Jan 03 '12 at 03:23
  • I agree with @XavierShay here, 1.9.3-p0 is *not* a beta or other pre-release version. It is a full-on officially released version. Patch level is **not** the same as "beta", "RC", or "preview". There was a preview & RC release of 1.9.3, but 1.9.3-p0 is a release version. – Andrew Marshall Mar 02 '12 at 21:50

4 Answers4

9

Adding the test-unit gem worked for me.

davidkovsky
  • 1,147
  • 8
  • 10
  • Hmm. No change for me when I tried it. (Currently attempting to see if using the latest ruby, patchlevel, 1.9.3-p194, makes a difference) – Alan H. Jun 01 '12 at 02:02
6

Try the following (independently):

  1. Use test.test_files = FileList['test/unit/**/test*.rb']
  2. Remove shoulda beta dependency.
  3. Use test/unit gem.
Xavier Shay
  • 4,067
  • 1
  • 30
  • 54
  • 1
    Removing shoulda fixed that for me – Ben Wiseley Mar 21 '12 at 00:29
  • 2
    Removing shoulda worked (as did adding test-unit), but as I was using RSpec and still needed shoulda, I replaced `gem 'shoulda'` with `gem 'shoulda-matchers'` which seems to work just fine. Thoughtbot's documentation does say that only shoulda-matchers are needed for RSpec, and shoulda-context is used "If you're not testing a Rails project or don't want to use the matchers". – Leo Apr 09 '12 at 11:09
4

The shoulda gem is causing a general problem when using rake in test environment on ruby 1.9.3, this is repported in this issue.

Workaround

You can use this line

gem "shoulda", :require => false

in your Gemfile and then somewhere in your test code (e.g. test/test_helper.rb if you are using test-unit) you can put

require 'shoulda'

If you are using rspec you should not use the shoulda gem at all, you should use the shoulda-matchers and this will not cause problems.

Jarl
  • 2,831
  • 4
  • 24
  • 31
0

We changed our rake task (rake file) to look like this

require 'rake/testtask'
  ...
desc "Run all tests in folder tests/test*.rb"
Rake::TestTask.new do |t|
  t.libs << "test"
  t.test_files = FileList['tests/test*.rb']
  t.verbose = true
end

based upon: http://rake.rubyforge.org/classes/Rake/TestTask.html

Tischer
  • 1
  • 1