0

我正在关注rails 教程,已完成第 5 章,并决定从 Rails 4 beta1 升级到新发布的rc2现在规格失败了

... application_helper_spec.rb:3:in `<top (required)>':
      uninitialized constant ApplicationHelper (NameError)

我已经擦除并重新创建了该spec_helper.rb文件,rmbundle 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

哈!我喜欢在最深处,但我想我只是淹死了......

4

1 回答 1

1

Rails Core 团队对破坏 beta1 测试的 RC 进行了一些更改,因此您必须更改它们。本教程已更新,但如果您遵循旧版本,则应删除当前代码库中的一些过时测试。除了在书中稍微回溯一下,我建议看一下示例应用程序代码的最新版本(我刚刚更新为使用 Rails 4.0 RC2)。这应该可以帮助您找到损坏测试的正确替代品。

于 2013-06-13T18:43:42.300 回答