问题
I have a controller spec that needs a super admin to be logged in to work
I followed this guide to and wrote the (paraphrased) following in my tests
before(:each) do
super_admin = FactoryGirl.create(:super_admin)
login_as super_admin, scope: :super_admin
end
it "does whatever" do
get :whatever
expect(whatever).to eq(whatever)
end
it "does something else" do
get :something_else
expect(something_else).to (something_else)
end
My problem is that the login is only working for tests past the first, debugging revealed that it was failing authentication, if I use before(:each) to login, and is failing every test except the first when i use before(:all)
I found login_as with rspec fails first test where the asker appears to be having a similar problem, but the only answer doesn't help me
回答1:
So, it looks like login_as
doesn't play well with controller specs (I'm assuming), when I switched login_as super_admin, scope: :super_admin
with sign_in super_admin
everything started working
来源:https://stackoverflow.com/questions/39877687/rspec-devise-login-as-does-not-work-on-the-first-test