我正在关注rails 教程,已完成第 5 章,并决定从 Rails 4 beta1 升级到新发布的rc2。现在规格失败了。
... application_helper_spec.rb:3:in `<top (required)>':
uninitialized constant ApplicationHelper (NameError)
我已经擦除并重新创建了该spec_helper.rb
文件,rm
并bundle exec rspec --init
解决了我的第一个问题。我对第二个问题感到困惑,即规范没有找到我定义的应用程序助手。
完整的错误输出:
tim@atom:~/repo/rails_tutorial_sample_app$ bundle exec rspec
No DRb server is running. Running in local process instead ...
/home/tim/repo/rails_tutorial_sample_app/spec/helpers/application_helper_spec.rb:3:in `<top (required)>': uninitialized constant ApplicationHelper (NameError)
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:77:in `rescue in run'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:73:in `run'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
我不明白它如何加载足够好的东西来解决它。我通读了Rails/RSpec - 为原始辅助方法编写测试,这所指的一切似乎都是有序的。
以下是两个明显相关的文件:
规范/助手/application_helper_spec.rb
require 'spec_helper'
describe ApplicationHelper do
describe "full_title" do
it "should include the page title" do
expect(full_title("foo")).to match(/foo/)
end
it "should include the base title" do
expect(full_title("foo")).to match(/^Ruby on Rails Tutorial Sample App/)
end
it "should not include a bar for the home page" do
expect(full_title("")).not_to match(/\|/)
end
end
end
app/helpers/application_helper.rb
module ApplicationHelper
# full title on per page basis
def full_title(page_title)
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
end
我的完整资源位于https://github.com/timabell/rails_tutorial_sample_app/tree/4b3d93bbfdb0adb36b87b760c90c3bdda87def16
哈!我喜欢在最深处,但我想我只是淹死了......