我試圖找到我的表達黃瓜更好的辦法,所以我想找一個序號,以基數函數轉換這樣的:有沒有在紅寶石或鐵軌的基本功能的序數?
When I fill up the first passenger field
Then I should see the passenger list update with the first passenger details
When I follow "Add Another Passenger"
Then I should see a second passenger field
When I fill up the second passenger field
Then I should see the passenger list update with the second passenger details
到的東西更多動態(而不是創建每行單獨的步驟)
,這裏是我的網絡的樣本步驟
When /^I fill up the first passenger field$/ do
fill_in("booking_passengers_attributes_0_first_name", :with => "Blah")
fill_in("booking_passengers_attributes_0_last_name", :with => "blah")
select("5' to 6'", :from => "booking_passengers_attributes_0_height")
select("100 to 150lbs", :from => "booking_passengers_attributes_0_weight")
end
When /^I fill up the second passenger field$/ do
fill_in("booking_passengers_attributes_1_first_name", :with => "Wee")
fill_in("booking_passengers_attributes_1_last_name", :with => "Sir")
select("5' to 6'", :from => "booking_passengers_attributes_1_height")
select("150 to 200lbs", :from => "booking_passengers_attributes_1_weight")
end
看到0和1?我希望將「第一」轉換爲基數,以便我可以替換。你也可以提出一個更好的方式來聲明
修訂ANSWER 我在重構的中間:)但基本上我用1號,而不是第一和使用to_i上的cukes。
When /^I fill up the "([^"]*)" passenger field$/ do |id|
input_id = id.to_i - 1
fill_in("booking_passengers_attributes_#{input_id}_first_name", :with => id)
fill_in("booking_passengers_attributes_#{input_id}_last_name", :with => "Passenger")
select("5' to 6'", :from => "booking_passengers_attributes_#{input_id}_height")
select("100 to 150lbs", :from => "booking_passengers_attributes_#{input_id}_weight")
end
是的我想我可以使用它。如果沒有stdnd | rd | th,我可以使用n.to_i並立即將其轉換爲數字。感謝您的支持! – corroded 2011-05-06 05:42:37
如果有其他人遇到這個問題,你應該使用(?:st | nd | rd | th),以便它不是「| th passenger field」(錯誤地匹配「我填滿第一個」) – 2011-12-02 23:21:28