Search code examples
ruby-on-railsrspec2rspec-rails

spec/helpers/application_helper_spec.rb cannot pass: undefined method `load_session' for nil:NilClass


I'm a Rails newbie, and am following Michael Hartl's Rails Tutorial. I'm having trouble getting the rspec past in the 5th chapter. Here is the troublesome 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

and bin/rspec spec/helpers/application_helper_spec.rb gives:

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

I have the ApplicationHelper defined in app/helper/application_helper.rb, and the test in spec/requests past without problems. Any idea about what's going on? Thanks in advance!

And here is 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

In case anyone would want it, here's spec/spec_helper.rb: http://dpaste.com/1309484/

And the version of gems: http://dpaste.com/hold/1309485/

Edited

Well, I figured it is a spork problem, but I'm not sure, cause if I replace the require "spec_helper" line with this:

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

The test pasts. And all my spec_helper do is to set up spork. So is there something wrong with my spec_helper.rb?


Solution

  • It seems that it can be solved by updating guard-spork to 1.4.2, and do

    bundle install