Я новичок в огурце, и я нашел следующие фрагменты, чтобы проверить функцию входа в Devise.Однако кажется, что пропущен еще один шаг, и я не нашел никакого решения:
Given /^that a confirmed user exists$/ do
pending # express the regexp above with the code you wish you had
end
Вот следующий код:
features / authentication / session.feature
Feature: Session handling
In order to use the site
As a registered user
I need to be able to login and logout
Background:
Given that a confirmed user exists
Scenario Outline: Logging in
Given I am on the login page
When I fill in "user_email" with "<email>"
And I fill in "user_password" with "<password>"
And I press "Sign in"
Then I should <action>
Examples:
| email | password | action |
| minimal@example.com | test1234 | see "Signed in successfully" |
| bad@example.com | password | see "Invalid email or password" |
Scenario: Logging out
Given I am logged in
When I go to the sign out link
Then I should see "Signed out successfully"
features / step_definitions / authentication_steps.rb
# Session
Given /^I am logged in$/ do
visit path_to('the login page')
fill_in('user_email', :with => @user.email)
fill_in('user_password', :with => @user.password)
click_button('Sign in')
if defined?(Spec::Rails::Matchers)
page.should have_content('Signed in successfully')
else
assert page.has_content?('Signed in successfully')
end
end
spec / factories / user.rb
Factory.define :minimal_user, :class => User do |u|
u.username 'minimal'
u.email 'minimal@example.com'
u.password 'test1234'
u.password_confirmation 'test1234'
end
Здесь ссылка на оригинальный код
Большое спасибо за вашу помощь !!