我正在关注rails tutorial,已完成第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 - writing tests for original helper methods,其中所指的一切似乎都是有序的。
以下是两个明显相关的文件:
规格/助手/ 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
应用/助手/ 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
HALP!我喜欢陷入困境,但我想我只是淹死了......
答案 0 :(得分:1)
Rails核心团队为RC打破了beta1测试的一些变化,所以你必须改变它们。本教程已更新,但如果您遵循旧版本,则应删除当前代码库中的一些过时测试。除了在书中稍微回溯之外,我建议看一下latest version of the sample app code(我刚刚更新为使用Rails 4.0 RC2)。这应该可以帮助您找到破损测试的正确替代品。