How to Stub out Warden/Devise with Rspec in Capybara test

前端 未结 1 1799
天命终不由人
天命终不由人 2021-01-12 03:03

I want to stub out a logged in user (with Devise/Warden) using rspec mocks in a Capybara test suite in my Rails app. This would save a ton of time, and would mean that my te

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 03:31

    Warden comes with built in test helpers. It allows you to login without having to use the UI in your cucumber tests. Just add the files below into your project.

    # features/support/warden.rb

    Warden.test_mode!
    World Warden::Test::Helpers
    After { Warden.test_reset! }
    

    # features/step_definitions/user_steps.rb

    Given /^I am logged in as a user$/ do
      @current_user = User.create!(:username => 'user', :password => 'password')
      login_as(@current_user, :scope => :user)
    end
    

    Use Wardens.test_mode! with Capybara

    0 讨论(0)
提交回复
热议问题