如何在黄瓜ruby中实现数据表,我需要一个例子来从一个功能文件中同时使用数据表和示例

时间:2016-02-29 11:44:06

标签: ruby cucumber gherkin

我想知道如何在黄瓜红宝石中实现数据表? 需要一个示例来从特征文件中同时使用数据表和示例。

请提供这些及其实施文件的示例功能。

1 个答案:

答案 0 :(得分:3)

使用这样的场景

Scenario Outline:
  Given I have a username and password and a boolean
    |username | password | boolean    |
    | myname  | mysecret | <boolean>  |
  Then I print them out

  Examples:
    | boolean |
    | true    |
    | false   |

你会像这样使用步骤defs:

Given(/^I have a username and password and a boolean$/) do | table |
  @data = table.hashes
end

Then(/^I print them out$/) do
  @data.each { |_k, v| puts v }
  # or
  data_for_row_one_of_table = @data[0]
  username = data_for_row_one_of_table['username']
  # Do something with username here
  ...
end

这会回答你的问题吗?

相关问题