【发布时间】:2013-06-09 07:49:57
【问题描述】:
我正在关注rails tutorial,已完成第 5 章,并决定从 Rails 4 beta1 升级到新发布的 rc2。 现在规范失败了。
... application_helper_spec.rb:3:in `<top (required)>':
uninitialized constant ApplicationHelper (NameError)
我已经用rm 和bundle exec rspec --init 擦除并重新创建了spec_helper.rb 文件,这解决了我的第一个问题。我对第二个问题感到困惑,即规范没有找到我定义的应用程序助手。
完整的错误输出:
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,这里提到的一切似乎都井井有条。
这是两个明显相关的文件:
spec/helpers/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
停下!我喜欢在最深处,但我想我只是淹死了......
【问题讨论】:
-
试试
rails g rspec:install- 你当前的 spec_helper 看起来不对。 -
hrmm,该命令抛出了我之前遇到的错误。
bundle exec rails g rspec:install /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc2/lib/rails/application/configuration.rb:144:in `const_get': uninitialized constant ActionDispatch::Session::EncryptedCookieStore (NameError)... -
我看看stackoverflow.com/a/15849479/10245然后回来,看起来和我一样。
标签: ruby-on-rails rspec railstutorial.org ruby-on-rails-4