0

我是 Rails 新手,正在关注 Michael Hartl 的 Rails 教程。我在第 5 章中无法通过 rspec。这是麻烦的spec/helpers/application_helper_spec.rb:

require 'spec_helper'
describe ApplicationHelper do
  describe "full_title" do
    it "should include the page title" do
      full_title("foo").should =~ /foo/
    end
  end
end

和 bin/rspec spec/helpers/application_helper_spec.rb 给出:

Failure/Error: Unable to find matching line from backtrace
     NoMethodError:
       undefined method `load_session' for nil:NilClass

我在 app/helper/application_helper.rb 中定义了 ApplicationHelper,并且在 spec/requests 中的测试过去没有问题。知道发生了什么吗?提前致谢!

这里是 app/helper/application_helper.rb

module ApplicationHelper
  # Returns the full title on a 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

如果有人想要,这里是 spec/spec_helper.rb: http ://dpaste.com/1309484/

和宝石的版本:http: //dpaste.com/hold/1309485/

已编辑

好吧,我认为这是一个 spork 问题,但我不确定,因为如果我用这个替换 require "spec_helper" 行:

require "/home/charlie/rails_projects/sample_app/app/helpers/application_helper.rb"
RSpec.configure do |c|
   c.include ApplicationHelper
end

考试过去了。而我的 spec_helper 所做的就是设置 spork。那么我的 spec_helper.rb 有问题吗?

4

1 回答 1

0

似乎可以通过将guard-spork更新到1.4.2来解决,并且做

bundle install
于 2013-07-19T02:10:28.260 回答