2016-08-19 102 views
0

这一步在我的Ruby功能的文件查找和访问客户记录:黄瓜元数不匹配错误

When I search with the following details: "<recordReference>", "<secondIdentifier>", "<postcode>": 
    | recordReference | secondIdentifier| postcode | 
    | REFABCDE12345678| IDcode1234  | PC11 1PC | 

它具有这样的步骤定义:

When(/^I search with the following details: "(.*?)", "(.*?)", "(.*?)":$/) do |recordReference, secondIdentifier, postcode| 
    find(:css, "#dln").native.send_keys recordReference 
    find(:css, "#nino").native.send_keys secondIdentifier 
    find(:css, "#postcode").native.send_keys postcode 
    check 'confirmation' 
    click_button 'submit' 
end 

当它运行时,我得到以下错误:

Cucumber::ArityMismatchError: Your block takes 3 arguments, but the Regexp matched 4 arguments. 
features/step_definitions/refactored_commands.rb:207:in `/^I search with the following details: "(.*?)", "(.*?)", "(.*?)":$/' 

我做了什么错,怎么解决?

对于信息 - 我得到同样的错误消息,如果parenthases被取出步骤定义的:

When /^I search with the following details: "(.*?)", "(.*?)", "(.*?)":$/ do |recordReference, secondIdentifier, postcode| 

回答

1

第四个参数是数据表。删除前三个参数并放入DataTable选项,您将从DataTable中获取所有数据。建议您使用dryRun = true选项让Cucumber创建适当的步骤定义匹配器,这是从我的Java知识中不知道这个dryRun选项是如何在ruby中。 另外,你将不得不改变你的步伐在特征文件与传递数据表的步骤

从你的表的格式删除提到的3个参数

0

它看起来像你混淆了一个方案概述了它看起来你要什么,实际上应该是

Scenario Outline: xxx 
    ... 
    When I search with the following details: "<recordReference>", "<secondIdentifier>", "<postcode>" 
    ... 

    Examples: 
    | recordReference | secondIdentifier| postcode | 
    | REFABCDE12345678| IDcode1234  | PC11 1PC | 

,然后将每个大纲将一次已填充值的示例中的每一行被称为 - 所以你的步骤将是

When(/^I search with the following details: "(.*?)", "(.*?)", "(.*?)"$/) do |recordReference, secondIdentifier, postcode| 
    ... 
end 

在一个侧面说明 - 有你打电话.native.send_keys任何理由 - 我相信每一个驱动程序支持正常的水豚send_keys API,因此这纯粹是find(:css, '#dln').send_keys recordReference(或当然只是fill_in('dln', with: recordReference)