黄瓜似乎跳过了给定的步骤

发布于 2024-11-28 22:30:10 字数 2766 浏览 1 评论 0原文

据我所知,黄瓜在这两个场景之间只访问数据库一次,但它会在场景之间清除数据库。

功能:

Feature: a new user vists the site and signs up
    in order to get new users
    when an unlogged in users comes to the website
    then they should see the sign-up dialog
    and be able to signup for the website 

    Background:
        Given I have at least one deal

    Scenario: a new user is asked to signup
        Given I am on show deal
        Then I should see "New Here?"

    @javascript
    Scenario: new user signup failure
        Given I am on show deal
        When I fill in "consumer[user_attributes][email]" with "[email protected]"
        And I press "consumer_submit"
        Then I should see "1 error prohibited"

步骤定义:

Given /^I have at least one deal$/ do
  Deal.create copy:'Example Deal Copy', copy_header:'Example Deal Header', copy_subheader:'Example Deal Subheader' if Deal.all.size == 0
end

结果:

Background:                      # features/new_user_signup.feature:7
    Given I have at least one deal # features/step_definitions/new_user_signup_steps.rb:1

  Scenario: a new user is asked to signup # features/new_user_signup.feature:10
    Given I am on show deal               # features/step_definitions/web_steps.rb:44
    Then I should see "New Here?"         # features/step_definitions/web_steps.rb:105

  @javascript
  Scenario: new user signup failure                                        # features/new_user_signup.feature:15
    Given I am on show deal                                                # features/step_definitions/web_steps.rb:44
      Couldn't find Deal with ID=1 (ActiveRecord::RecordNotFound)
      ./app/controllers/deals_controller.rb:17:in `show'
      <internal:prelude>:10:in `synchronize'
      ./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'
      features/new_user_signup.feature:16:in `Given I am on show deal'
    When I fill in "consumer[user_attributes][email]" with "[email protected]" # features/step_definitions/web_steps.rb:60
    And I press "consumer_submit"                                          # features/step_definitions/web_steps.rb:52
    Then I should see "1 error prohibited"                                 # features/step_definitions/web_steps.rb:105

Failing Scenarios:
cucumber features/new_user_signup.feature:15 # Scenario: new user signup failure

无论我放在第二个位置,都会出现 ActiveRecord 错误。为什么我的第二种情况数据库中没有记录?

As best I can tell cucumber is only hitting the database once between these two scenarios, but it's clearing out the database between scenarios.

The Features:

Feature: a new user vists the site and signs up
    in order to get new users
    when an unlogged in users comes to the website
    then they should see the sign-up dialog
    and be able to signup for the website 

    Background:
        Given I have at least one deal

    Scenario: a new user is asked to signup
        Given I am on show deal
        Then I should see "New Here?"

    @javascript
    Scenario: new user signup failure
        Given I am on show deal
        When I fill in "consumer[user_attributes][email]" with "[email protected]"
        And I press "consumer_submit"
        Then I should see "1 error prohibited"

The Step Definition:

Given /^I have at least one deal$/ do
  Deal.create copy:'Example Deal Copy', copy_header:'Example Deal Header', copy_subheader:'Example Deal Subheader' if Deal.all.size == 0
end

The Result:

Background:                      # features/new_user_signup.feature:7
    Given I have at least one deal # features/step_definitions/new_user_signup_steps.rb:1

  Scenario: a new user is asked to signup # features/new_user_signup.feature:10
    Given I am on show deal               # features/step_definitions/web_steps.rb:44
    Then I should see "New Here?"         # features/step_definitions/web_steps.rb:105

  @javascript
  Scenario: new user signup failure                                        # features/new_user_signup.feature:15
    Given I am on show deal                                                # features/step_definitions/web_steps.rb:44
      Couldn't find Deal with ID=1 (ActiveRecord::RecordNotFound)
      ./app/controllers/deals_controller.rb:17:in `show'
      <internal:prelude>:10:in `synchronize'
      ./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'
      features/new_user_signup.feature:16:in `Given I am on show deal'
    When I fill in "consumer[user_attributes][email]" with "[email protected]" # features/step_definitions/web_steps.rb:60
    And I press "consumer_submit"                                          # features/step_definitions/web_steps.rb:52
    Then I should see "1 error prohibited"                                 # features/step_definitions/web_steps.rb:105

Failing Scenarios:
cucumber features/new_user_signup.feature:15 # Scenario: new user signup failure

Whichever scenario I put second will give the ActiveRecord error. Why are there no records in the database for my second scenario?

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

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

发布评论

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

评论(1

凯凯我们等你回来 2024-12-05 22:30:10

现在我知道你是如何映射“show deal”的了,我想说问题是 Deal 实例可能存在,但它的 id 不等于 1。你能检查一下吗?

这里有一个提示:当您在 path.rb 中定义路径时,您可以执行以下操作:

when /the edit deal page/
edit_deal_path(Deal.first)

甚至可以这样:

when /the deal page for deal named ".*"/
        deal_name = page_name.scan(/".*"/).first.gsub("\"", '') 
        deal = Deal.find_by_name(deal_name)
        deal_path(deal)

只要您像这样定义了“我在”网页步骤:

Given /^(?:|I )am on (.+)$/ do |page_name|
  visit path_to(page_name)
end

这比“交易/1”:)

Now I know how you've mapped "show deal" I am tempted to say that the problem is that the Deal instance possibly exists but it's id is not equal 1. Can you check please?

And here is a tip: while you're defining paths in your path.rb, you may do something like this:

when /the edit deal page/
edit_deal_path(Deal.first)

or even this:

when /the deal page for deal named ".*"/
        deal_name = page_name.scan(/".*"/).first.gsub("\"", '') 
        deal = Deal.find_by_name(deal_name)
        deal_path(deal)

As long as you've defined your "I am on" webstep like this:

Given /^(?:|I )am on (.+)$/ do |page_name|
  visit path_to(page_name)
end

It's far better than "deals/1" :)

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