2013-12-16 89 views
1

我有一個問題,找到黃瓜數據表中的數字正確的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 As we could see on the screenshot, it's catched the user, however, not the mac. I don't know why? As it suggests (\d+) is not working in my case either. Please help.

我的問題是:

  1. 看截圖,上面寫着2過去了,然而,爲什麼我看到這個底部: 您可以實現與這些片段未定義步驟的步驟定義: When /^the user mattwww with (\d+) logs on to Sonar$/ do |arg1| 對我來說,它看起來像mac地址200000000001沒有通過。或者,我錯了嗎?

  2. @ rad.send(username,mac)這句話沒有運行。我試着把這個放在「user:#{username} mac:#{mac}」中,沒有顯示任何值。怎麼來的?

+0

目前還不清楚究竟是你在你的問題問。你可以編輯它,並更具體? – mechanicalfish

+0

嗨,我已經編輯了我的問題,可以請你看一看,看看它是否更有意義?謝謝。 – gugo

+0

它的確如此,謝謝。我寫了一個答案。 – mechanicalfish

回答

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 (.*?)$/ 
+0

嗨Mechaniclfish,我確實意識到這一點,並且我已經嘗試了您所說的刪除或添加雙引號,但是,屏幕截圖的結果仍然相同。它仍然說2未定義---我跳過了預期結果的最後一步。 – gugo

+0

剛剛測試過它,它工作(https://gist.github.com/deCasale/8000774)。比較你的想法和檢查是否有錯別字。 – mechanicalfish

+0

刪除了我的全部。只是複製你的所有,然後跑,---是,成功運行!奇怪的。非常感謝! – gugo