Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用Desive和cucumber测试登录_Ruby On Rails_Devise_Cucumber - Fatal编程技术网

Ruby on rails 使用Desive和cucumber测试登录

Ruby on rails 使用Desive和cucumber测试登录,ruby-on-rails,devise,cucumber,Ruby On Rails,Devise,Cucumber,我正在尝试用Cucumber测试登录功能。 My file users_steps.rb包含 Given /^I am a user named "([^"]*)" with an email "([^"]*)" and password "([^"]*)"$/ do |name, email, password| u = User.new(:name => name, :email => email, :passwor

我正在尝试用Cucumber测试登录功能。 My file users_steps.rb包含

Given /^I am a user named "([^"]*)" with an email "([^"]*)" and password "([^"]*)"$/ do |name, email, password|
  u = User.new(:name => name,
               :email => email,
               :password => password,
               :password_confirmation => password)
  u.skip_confirmation!
  u.save!
end


When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
  #Given %{I am not logged in}
  When %{I go to the sign in page}
  And %{I fill in "user_email" with "#{email}"}
  And %{I fill in "user_password" with "#{password}"}
  And %{I press "Log Me In"}
end

Then /^I should be signed in$/ do
  Then %{I should see "Sign out"}
end

Then /^I should be signed in$/ do
  Then %{I should see "Sign out"}
end

Then /^I sign out$/ do
  visit('/account/logout')
end
我的设想是:

  Scenario: User signs in successfully with email
    Given I am not logged in
    And I am a user named "foo" with an email "user@test.com" and password "please"
    When I go to the sign in page
    And I sign in as "user@test.com/please"
    Then I should be signed in
    When I return next time
    Then I should be already signed in
但是,此测试无法让用户登录。我已检查用户是否正确创建,但在填写表单后,我被重定向到登录页面


我在用水豚。我缺少什么?

您可能想使用:

一,。在位于步骤定义中的user_steps.rb文件中:

Given /^a valid user$/ do
  @user = User.create!({
             :email => "minikermit@hotmail.com",
             :password => "12345678",
             :password_confirmation => "12345678"
           })
end

Given /^a logged in user$/ do
  Given "a valid user"
  visit signin_url
  fill_in "Email", :with => "minikermit@hotmail.com"
  fill_in "Password", :with => "12345678"
  click_button "Sign in"
end
在要测试身份验证的功能中:

Scenario: Login
  Given a valid user
  When I go to the login page
  And I fill in the following:
    |Email|minikermit@hotmail.com|
    |Password|12345678|
  And I press "Sign in"
  Then I should see "Signed in successfully."
不要忘记在support/path.rb中更改登录页面的路径

when /the login page/
  user_session_path
在这里,我的路径是使用designe默认设置。您可以使用
rake routes
来发现您的登录路径


您可能需要更改“登录”、“成功登录”中的文本以匹配您的页面。我的假设是,您正在使用cucumber+capybara+Desive的默认配置。

谢谢您的回复。遗憾的是,我无法修复,所以我重构了代码并发布了从用户实例变量中填写登录信息不是很简单吗?例如,在“Email”中填写:with=>@user.Email我不能用自己的用户登录吗?