RSpec 2.3 + Development 1.0.11

I have a really old Rails 2.3.18, ruby ​​1.9.3, an rspec 1.x application that we are updating, and it had a quiet authentication. So I replaced it with Devise 1.0.11.

I can enter the application, but my tests will not run;

Here is the example in question

require 'spec_helper'

describe CategoriesController do
  context "As a logged in user" do
    before do
      login_user
      current_firm = mock_model(Firm, :id => 1)
      controller.stub!(:current_firm).and_return(current_firm)
    end

    describe "#index" do
      it "should render index" do
        get :index
        response.should render_template('index')
      end
    end

  end
end

Here is the error I get:

NoMethodError in 'CategoriesController As a logged in user#index should render index'
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]=
/home/map7/code/pdfcat/spec/spec_helper.rb:18:in `login_user'
spec/controllers/categories_controller_spec.rb:6:in `block (3 levels) in <top (required)>'

Error in this line;

[20, 29] in /usr/local/rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/warden-0.10.7/lib/warden/session_serializer.rb
   20        key
   21      end
   22  
   23      def store(user, scope)
   24        return unless user
=> 25        session[key_for(scope)] = serialize(user)
   26      end

The problem is that "session" is zero when I am at this point.

I clicked the full code here: https://github.com/map7/pdfcat/tree/devise

My plan was to get devise to work in tests, then I could go to Rails 3.0 and continue with the upgrade.

+6
source share
1 answer

google , , , : https://groups.google.com/forum/#!topic/rspec/4AHuPtHFD34

:

before do
  request.env['warden'].stub(:authenticate!) { double(User) }
end

, , rails_helper.rb,

+1

All Articles