0

我正在关注 Michael Hartl 教程的第 5 章。当我从根目录运行以下命令时,

$ bundle exec rspec spec/

我收到以下错误:

No DRb server is running. running in local process instead ...
c:/sites/sample_app/spec/helpers/applcation_helper_spec.rb:1:in '<top required>>': uninitialized constant ApplicationHelper (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:746:in 'loud'
.
.

我想我应该尝试找出哪些文件失败了,我发现 2 个文件出现了上述错误(其余的文件运行了测试并通过了 0 个失败)。失败的有:

1) 规范/帮助者/application_helper_spec.rb

describe ApplicationHelper do

  describe "full_title" do
    it "should include the page name" do
      full_title("foo").should =~ /foo/
    end

    it "should include the base name" do
      full_title("foo").should =~ /^Ruby on Rails Tutorial Sample App/
    end

    it "should not include a bar for the home page" do
      full_title("").should_not =~ /\|/
    end
  end
end

2) 规范/支持/实用程序.rb

include ApplicationHelper
4

1 回答 1

1

阅读后,我发现 rspec 需要 spork 运行(不知道为什么它适用于某些测试而不适用于其他测试?)。我忘了要求 spec_helper,所以我将它插入到 application_helper_spec.rb 的第一行并且它起作用了。

require 'spec_helper'  

这是引导我找到答案的帖子。

于 2012-04-12T15:54:57.963 回答