黄瓜背景和持久场景(或先决条件)

时间:2011-02-09 23:15:46

标签: ruby-on-rails ruby-on-rails-3 cucumber

我遇到了这个问题Cucumber scenarios for extremely long work flow

现在我一直在为一系列多部分表单步骤中的每一步编写孤立的场景。我有一个Background部分,用于设置每个Scenario。但现在当我运行整个功能时,黄瓜想要为每个Background重复Scenario。我想测试一个Scenario,它建立在以前的所有基础之上。

以下是我的功能的简要概述:

Feature: Submit a manuscript
  In order to complete a manuscript submission
  As a corresponding author
  I want to complete the to-do list

  Background:
    Given I am logged in as "Steve"
    And an article_submission "Testing Web Apps" exists
    And "Steve" is a "Corresponding Author" for "Testing Web Apps"
    And I am on the manuscript to-do list page for "Testing Web Apps"

  Scenario: Steve suggests reviewers for his manuscript
    ...
  Scenario: Steve completes the manuscript fees to-do item
    ...
  Scenario: Steve wants to add Barbara as a co-author
    ...
  Scenario: Steve uploads necessary files
    ...
  Scenario: Steve edits the fees page and general information page
    ...
  Scenario: Steve re-uploads the manuscript file
    ...
  Scenario: Steve completes the Copyright Transfer
    ...
  Scenario: Steve completes Author Responsibilities & Agreement
    ...
  # These scenarios depend on all the previous ones having run  
  Scenario: Steve Completes submission
    ...
  Scenario: Steve goes back and make changes
    ...
  Scenario: Steve fills out payment page

是否有办法要求运行以前的方案?有没有办法只运行一次Background

1 个答案:

答案 0 :(得分:2)

我决定在运行功能后立即“冻结”应用程序。我这样做是通过添加转储和加载数据库的钩子来实现的。

features/support/hooks.rb我有:

After('@complete-submission') do
  # Dump the database
  exec "mysqldump -u root --password=### onc_test > #{Rails.root}/support/submission.sql"
end

Before('@load-submission') do
  # Load the database
  exec "mysql -u root --password=### onc_test < #{Rails.root}/support/submission.sql"
end

这基本上是有效的,除了@load-submission神秘地运行Scenario失败,但数据库已加载。所以我必须在没有标签的情况下再次运行它。也许有人可以帮我解决这个问题。