#503 new
eventualbuddha

RSpec fails to finish running properly depending on load order

Reported by eventualbuddha | August 22nd, 2008 @ 07:03 PM | in No-Milestone-Assigned

This is the error that occurs:

/var/lib/gems/1.8/gems/rspec-1.1.4/lib/spec.rb:27:in `exit?': undefined method `run?' for Test::Unit:Module (NoMethodError)
    from /var/lib/gems/1.8/gems/rspec-1.1.4/lib/spec/runner.rb:193:in `register_at_exit_hook'
    from spec/dsl_spec.rb:3

This doesn't happen on every machine, but it happens every time on my Ubuntu Linux 64-bit continuous integration machine when the following are true:

  1. RSpec is loaded while Object.const_defined?(:Test) is false
  2. Spec.exit? is called while Object.const_defined?(:Test) is true
  3. test/unit has not been loaded

My particular way to cause this was to have a spec_helper.rb file that looked like this:

require 'rubygems'
require 'spec'

require File.dirname(__FILE__) + '/../lib/myproject'

Where the project in question loaded ActiveRecord and, by implication, ActiveSupport, which doesn't actually load test/unit but defines the Test::Unit module. Therefore when Spec.exit? is called, it assumes test/unit has been loaded and calls Test::Unit.run?, resulting in the above error.

Someone else had the same problem: https://www.ruby-forum.com/topic...

A workaround is to require 'spec' only after your app code has been initialized, so either Test will be there or it won't.

My commit on github: http://github.com/eventualbuddha...

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Behaviour Driven Development for Ruby.

Shared Ticket Bins

People watching this ticket

Tags