我正在尝试找到一种更好的方法来表达我的黄瓜,所以我正在寻找一个将其转换为基数的序数函数:
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 了吗?我希望将“第一”转换为基数,这样我就可以替换了。您也可以建议一种更好的方式来声明杯子:)
更新的答案 我正在重构,但基本上我使用 1st 而不是 first 并使用 to_i 。
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