Cucumber 和 Devise,重定向太多?

发布于 2024-10-27 10:36:43 字数 1982 浏览 1 评论 0原文

我正在尝试用黄瓜为 Devise 创建一个测试。这是我的功能

Feature: Login to locomotive
  In order to login to locomotive
  As a user 
  I want to be able to use Locomotive

Scenario: Login to locomotive
    Given I am a authenticated user
    Then I should see "logged in as <email>"
    Then show me the page

,这是我的用户步骤

Given /^I am not authenticated$/ do
  visit('/users/sign_out') # ensure that at least
end

Given /^I have one\s+user "([^\"]*)" with password "([^\"]*)" and username "([^\"]*)"$/ do |email, password, username|
  @user = User.new(:email => email,
           :username => username,
           :first_name => 'Josh',
           :last_name => 'Crowder',
           :password => password,
           :password_confirmation => password).save!
end

Given /^I am a authenticated user$/ do
  email = '[email protected]'
  username = 'josh'
  password = 'secretpass'

  Given %{I have one user "#{email}" with password "#{password}" and username "#{username}"}
  And %{I go to login}
  And %{I fill in "user_login" with "#{email}"}
  And %{I fill in "user_password" with "#{password}"}
  And %{I press "Sign in"}
end

我收到此错误消息

F--

(::) failed steps (::)

redirected more than 5 times, check for infinite redirects. (Capybara::InfiniteRedirectError)
./features/step_definitions/web_steps.rb:29:in `block (2 levels) in <top (required)>'
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:28:in `/^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/'
features/user_authentication.feature:7:in `Given I am a authenticated user'

Failing Scenarios:
cucumber features/user_authentication.feature:6 # Scenario: Login to locomotive

1 scenario (1 failed)
3 steps (1 failed, 2 skipped)

我不知道为什么会发生这种情况,有什么想法吗?

I am trying to create a test with cucumber for Devise. This is my feature

Feature: Login to locomotive
  In order to login to locomotive
  As a user 
  I want to be able to use Locomotive

Scenario: Login to locomotive
    Given I am a authenticated user
    Then I should see "logged in as <email>"
    Then show me the page

and this is my user steps

Given /^I am not authenticated$/ do
  visit('/users/sign_out') # ensure that at least
end

Given /^I have one\s+user "([^\"]*)" with password "([^\"]*)" and username "([^\"]*)"$/ do |email, password, username|
  @user = User.new(:email => email,
           :username => username,
           :first_name => 'Josh',
           :last_name => 'Crowder',
           :password => password,
           :password_confirmation => password).save!
end

Given /^I am a authenticated user$/ do
  email = '[email protected]'
  username = 'josh'
  password = 'secretpass'

  Given %{I have one user "#{email}" with password "#{password}" and username "#{username}"}
  And %{I go to login}
  And %{I fill in "user_login" with "#{email}"}
  And %{I fill in "user_password" with "#{password}"}
  And %{I press "Sign in"}
end

Im getting this error message

F--

(::) failed steps (::)

redirected more than 5 times, check for infinite redirects. (Capybara::InfiniteRedirectError)
./features/step_definitions/web_steps.rb:29:in `block (2 levels) in <top (required)>'
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:28:in `/^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/'
features/user_authentication.feature:7:in `Given I am a authenticated user'

Failing Scenarios:
cucumber features/user_authentication.feature:6 # Scenario: Login to locomotive

1 scenario (1 failed)
3 steps (1 failed, 2 skipped)

I have no clue why this is happening, any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只涨不跌 2024-11-03 10:36:43

可能有很多事情——如果没有更多代码就无法判断。一些可能性:

  • 您是否需要对登录页面进行身份验证?这会让你陷入循环。您想要从身份验证解决方案中排除“打开”页面(例如登录),
  • 您可以将“然后向我显示”页面放在更高的位置,这样您就可以准确看到发生了什么,
  • 您可以将其重置回默认值通过注释掉其他路由来验证解决方案(例如设计)只是为了看看发生了什么

当您通过浏览器尝试时会发生什么?

Could be tons of things -- no way to tell without more code. Some possibilities:

  • are you requiring authentication for the login page? That can get you in a loop. You want to exclude the "open" pages (like sign_in) from your authentication solution
  • you could put the Then Show Me The page higher so you can see exactly what's happening
  • you could reset back to the defaults of your authentication solution (eg devise) by commenting out other routes just to see what's going on

What happens when you try it through the browser?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文