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

爱⌒轻易说出口 提交于 2019-12-24 11:32:53

问题


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.


回答1:


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'



回答2:


I ran into the same issue. Thanks for the fix!

I found this response on another forum, which seems helpful in thinking about how Spork relates to Rspec.

RSpec does not "run" spec_helper. By default, rspec loads files that end with "_spec.rb" and it is up to those files to require spec_helper.rb. http://www.ruby-forum.com/topic/167768




回答3:


describe "ApplicationHelper" do

ApplicationHelper should be a string, not constant



来源:https://stackoverflow.com/questions/10036996/michael-hartl-rails-tutorial-3-2-chapter-5-rspec-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!