HTTP basic auth for Capybara

后端 未结 6 987
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 00:06

I\'m writing some RSpec tests for my Rails 3 application and trying to switch from Webrat to Capybara. So far so good but the application uses HTTP basic auth to authorize m

6条回答
  •  时光取名叫无心
    2020-12-05 00:48

    This has changed in recent versions of cucumber-rails (I am using 1.0.2).

    cucumber-rails uses the Rack/Test driver by default, so if you have not changed that, the following instructions will work.

    Create features/step_definitions/authorize.rb:

    Given /^I am logged in as "([^\"]*)" with "([^\"]*)"$/ do |username, password|
      authorize username, password
    end
    

    Now you can use this in your features:

    Given I am logged in as "admin" with "password"
    

提交回复
热议问题