views:

792

answers:

2

I get the error in subj when I'm trying to run specs or generators in a fresh rails project.

This happens when I add shoulda to the mix.

I added the following in the config/environment.rb:

config.gem 'rspec', :version => '1.2.6', :lib => false
config.gem 'rspec-rails', :version => '1.2.6', :lib => false
config.gem "thoughtbot-shoulda", :version => "2.10.2", :lib => 'shoulda', :source => "http://gems.github.com"

I'm on OSX.

  • ruby 1.8.6 (2008-08-11 patchlevel 287)
  • gems 1.3.5
  • rails 2.3.4
  • rspec - 1.2.6
  • shoulda - 2.10.2
  • test-unit - 2.0.3

I'm aware of this and adding config.gem 'test-unit', :lib => 'test/unit' indeed solves the genrator problem as it doesn't throw an exception, but it prints 0 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications at the end of the run so I suppose it tries to run tests which is unexpected and undesired, also the specs stop to run at all, seems like rspec is not running at all, when running rake spec I get the test-unit output again (with 0 tests as there are only specs, no tests defined)

A: 

test-unit is actually built into Ruby so removing the gem falls back on Ruby's built-in version. Unless there's something special that you need that's not included in the default test-unit then I wouldn't worry about this too much.

Peter Wagenet
yes, but if merely having test-unit installed (it was dependency for something) screws things up then there is a problem somewhere. for now I just removed the test-unit gem, but I might have to bring it back again.
Vitaly Kushner
True enough. I've seen the same problem before so hopefully someone else can shed some light on it.
Peter Wagenet
+1  A: 

I ran into a similar problem recently and traced it to this commit in rubygems:

http://github.com/vvs/rubygems/commit/cbb4b07d491dd49b8dff8ab7af706dde31307c7d

Which loads the 'test-unit' gem if it is there, or silently moves on if it's not. The author of this change perhaps is not aware of a fundamental truth - that activating a gem can often change the behavior of other gems loaded into the system. Application developers should be in charge of defining the set of gems they want activated; that the rubygems system itself decides to optionally load a gem is a head-scratcher.

The other half of this problem is the question of why the test-unit gem interferes with rspec. This I can't answer, but I did trace it to the fact that no ExampleGroups get registered, which in turn is due the fact that the "inherited" callback in ExampleGroupMethods does not get called when Rspec dynamically creates a new subclass of ActiveSupport::TestCase (this happens in ExampleGroupMethods#subclass)

So on thinking about it, is not clear if I'm talking about the same problem or a different one. The problem I'm talking about only happens when I use geminstaller, which requires a part of rubygems ('rubygems/validator') that then tries to require test-unit, but silently moves on if the gem is not available.It doesn't sound like you're using geminstaller, so it's not clear to me that it's rubygems that is pulling in test-unit.
not sure either and I don't hit that problem anymore, but going to award you points for the effort anyway :)I didn't have the patience to trace it all.
Vitaly Kushner