lundi 24 septembre 2018

Rspec test with devise login just work one time

I'm trying to test some views with devise and rspec. In this test, the first one passes. The second is redirect to sign_in page.

If I substitute :all to :each the first one fails and the second passes

The login_as just working in the first test. Why?

require 'rails_helper'

RSpec.describe StoresController, type: :controller do
    context "with valid params" do
        user = FactoryBot.build(:user)
        before(:all) do
            login_as(user, :scope => :user)
        end

        it "renders the index template" do
            get :index
            expect(response).to render_template("index")
        end

        it "creates a new store" do
            get :new
            expect(response).to render_template("new")
        end

    end
end

Aucun commentaire:

Enregistrer un commentaire