简体   繁体   中英

How can I test integration with RSpec and Devise

I have quite some issues with testing the features of my rails application using RSpec. I have a company controller, and are using devise to make sure that you need to be logged in to access the controller.

I then have integration tests like the following:

describe "with valid information" do
            before do
                fill_in "company_address", with: "My special address"
                fill_in "company_name", with: "My User"
                fill_in "company_contact_email", with: "test@test.com"
                fill_in "company_contact_name", with: "Someone Hello"
            end

            it "should create a company" do
                expect { click_button submit }.to change(Company, :count).by(1)
            end     
        end

It, of course, fails because I don't have a user who is logged in. I have tried creating a test helper like described here, and it works well for controllers, but not for integration tests.

What is the best way to log a user in with Devise, prior to these tests?

add file devise.rb to rspec/support And here is content

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end

Another way to solve your problem: Rails integration test with the devise gem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM