Given a typical Rails 3 environment, why am I unable to execute any tests?

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2011-03-08T00:45:02Z Indexed on 2011/03/12 0:10 UTC
Read the original article Hit count: 220

I'm working on writing simple unit tests for a Rails 3 project, but I'm unable to actually execute any tests.

Case in point, attempting to run the test auto-generated by Rails fails:

require 'test_helper'

class UserTest < ActiveSupport::TestCase
  # Replace this with your real tests.
  test "the truth" do
    assert true
  end
end

Results in the following error:

<internal:lib/rubygems/custom_require>:29:in `require': no such file to load --
test_helper (LoadError)
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from user_test.rb:1:in `<main>'

Commenting out the require 'test_helper' line and attempting to run the test results in this error:

user_test.rb:3:in `<main>': uninitialized constant Object::ActiveSupport (NameError)

The action pack gems appear to be properly installed and up to date:

actionmailer (3.0.3, 2.3.5)
actionpack (3.0.3, 2.3.5)
activemodel (3.0.3)
activerecord (3.0.3, 2.3.5)
activeresource (3.0.3, 2.3.5)
activesupport (3.0.3, 2.3.5)

Ruby is at 1.9.2p0 and Rails is at 3.0.3.

The sample dump of my test directory is as follows:

/fixtures
/functional
/integration
/performance
/unit
-- /helpers
   -- user_helper_test.rb
-- user_test.rb
test_helper.rb

I've never seen this problem before - I've run the typical rake tasks for preparing the test environment. I have nothing out of the ordinary in my application or environment configuration files, nor have I installed any unusual gems that would interfere with the test environment.

Edit

Xavier Holt's suggestion, explicitly specifying the path to the test_helper worked; however, this revealed an issue with ActiveSupport.

Now when I attempt to run the test, I receive the following error message (as also listed above):

user_test.rb:3:in `<main>': uninitialized constant Object::ActiveSupport (NameError)

But as you can see above, Action Pack is all installed and update to date.

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about ruby-on-rails-3