我在找到黄瓜数据表中数字的正确RE时遇到问题。
我的情况是这样的:
local_dhcp.feature
Feature:
Scenario Outline:
Given I have a valid username plus MAC address
When the user <user> with <mac> logs on to Sonar
Then the expected result should be <Expected_Result>
Examples:
| user | mac | Expected_Result|
| mattwwww | 200000000001 | OK |
| matt | 200000000001 | OK |
local_dhcp.rb
Given /^I have a valid username plus MAC address$/ do
@rad = RadiusClient.new
end
When /^the user "(.*?)" with "(\d+)" logs on to Sonar$/ do |username, mac|
puts "user: #{username} mac: #{mac}"
@rad.send(username, mac)
end
Then /^the expected result should be "(.*?)"$/ do |result|
# table is a Cucumber::Ast::Table
pending # express the regexp above with the code you wish you had
end
黄瓜特征\ test.feature
我的问题是:
看截图,它说2过去了,但是,我怎么会在底部看到这个:
您可以使用以下代码段实现未定义步骤的步骤定义:
When /^the user mattwww with (\d+) logs
on to Sonar$/ do |arg1|
对我来说,看起来像mac地址200000000001没有传入。或者,我错了吗?
@rad.send(username,mac)这句话没有运行。我试过这个“用户:#{username} mac:#{mac}”,没有显示值。怎么会?
答案 0 :(得分:0)
如果查看步骤定义中的正则表达式,参数周围会有双引号。这就是他们与功能步骤不匹配的原因。要解决这个问题,您需要做的就是在功能中添加引号:
Feature:
Scenario Outline:
Given I have a valid username plus MAC address
When the user "<user>" with "<mac>" logs on to Sonar
Then the expected result should be "<Expected_Result>"
Examples:
| user | mac | Expected_Result|
| mattwwww | 200000000001 | OK |
| matt | 200000000001 | OK |
或从正则表达式中删除它们:
/^I have a valid username plus MAC address$/
/^the user (.*?) with (\d+) logs on to Sonar$/
/^the expected result should be (.*?)$/