Michael Hartl Rails教程(3.2)-第5章Rspec问题 [英] Michael Hartl Rails Tutorial (3.2) - Chapter 5 Rspec issue
问题描述
我已经完成了第5章和所有练习.作为最后练习的一部分,MH让您为ApplicationHelper方法编写测试.
I've completed Chapter 5 and all the exercises. As part of the final exercise, MH has you write tests for the ApplicationHelper method.
完成后,个人测试将通过:
-
ST2中的
-
shift-command-T
(使用sublime-text-2-ruby-tests包)
终端中的 -
rspec spec/requests/user_pages_spec.rb
终端中的 -
rspec spec/requests/static_pages_spec.rb
shift-command-T
in ST2 (using the sublime-text-2-ruby-tests package)rspec spec/requests/user_pages_spec.rb
in the terminalrspec spec/requests/static_pages_spec.rb
in the terminal
但是,如果我在终端中使用rspec spec/
运行 all 测试,则会出现此错误:
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)
如果我运行spork并再次尝试
If I run spork and try rspec spec/
again, all tests pass.
我不确定我为什么会这样工作,或者将来要运行所有测试时是否总是需要运行spork.谢谢.
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.
推荐答案
我不确定,但是也许您忘记了需要spec_helper. 如果是这样,只需将其插入application_helper_spec.rb
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'
这篇关于Michael Hartl Rails教程(3.2)-第5章Rspec问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!