开发者

Cucumber Seems to Skip Given Step

开发者 https://www.devze.com 2023-03-27 02:44 出处:网络
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.

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 "test@test.com"
        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'
      ./开发者_如何学Pythonfeatures/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 "test@test.com" # 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?


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" :)

0

精彩评论

暂无评论...
验证码 换一张
取 消