给予/何时/然后在黄瓜中弃用

时间:2012-03-15 22:08:53

标签: ruby-on-rails-3 cucumber

我收到以下代码警告:

WARNING: Using 'Given/When/Then' in step definitions is deprecated, use 'step' to call other steps instead

我该如何纠正?

代码:

Feature: Viewing tickets
 In order to view the tickets for a project
 As a user
 I want to see them on that project's page

Background:
 Given there is a project called "TextMate 2"
 And that project has a ticket:
 | title           | description                   |
 |  Make it shiny! | Gradients! Starbursts! Oh my! |
 And there is a project called "Internet Explorer"
 And that project has a ticket:
 | title                | description   |
 | Standards compliance | Isn't a joke. |
 And I am on the homepage

Scenario: Viewing tickets for a given project
  When I follow "TextMate 2"
  Then I should see "Make it shiny!"
  And I should not see "Standards compliance"
  When I follow "Make it shiny!"
  Then I should see "Make it shiny" within "#ticket h2"
  And I should see "Gradients! Starbursts! Oh my!"

  When I am on the homepage
  And I follow "Internet Explorer"
  Then I should see "Standards compliance"
  And I should not see "Make it shiny!"
  When I follow "Standards compliance"
  Then I should see "Standards compliance" within "#ticket h2"
  And I should see "Isn't a joke.

非常感谢!

2 个答案:

答案 0 :(得分:7)

在步骤定义中的某处,您使用以下结构:

Then "a file named '#{want_file}' should exist"

相反,你应该使用

step("a file named '#{want_file}' should exist")

或(我认为首选) - 避免从另一个步骤中调出一步。最好重构定义并将共同部分提取到单独的类或方法中。

答案 1 :(得分:1)

替换它(features / step_definitions / web_steps.rb,第35-37行):

When /^(.*) within (.*[^:])$/ do |step, parent|
  with_scope(parent) { When step }
end

有这样的事情:

When /^(.*) within (.*[^:])$/ do |the_step, parent|
  with_scope(parent) { step the_step }
end

为我工作!