Search code examples
rspecruby-on-rails-3.2sporkrailstutorial.org

Michael Hartl Rails Tutorial (3.2) - Chapter 5 Rspec issue


I've completed Chapter 5 and all the exercises. As part of the final exercise, MH has you write tests for the ApplicationHelper method.

Once that is done, individual tests pass with:

  • shift-command-T in ST2 (using the sublime-text-2-ruby-tests package)
  • rspec spec/requests/user_pages_spec.rb in the terminal
  • rspec spec/requests/static_pages_spec.rb in the terminal

However, if I run all tests with rspec spec/ in the terminal I get this error:

/Users/anonymouscoward/rails/railstut/sample_app/spec/helpers/
application_helper_spec.rb:1:in `<top (required)>': uninitialized
constant ApplicationHelper (NameError)

If I run spork and try rspec spec/ again, all tests pass.

I'm not sure I understand why this works the way it does, or whether I'll always need to have spork running in the future when I want to run all my tests. Thanks.


Solution

  • I'm not sure, but maybe you forgot to require spec_helper. If so, just insert this in the first line of application_helper_spec.rb

    require 'spec_helper'