私はキュウリを表現するより良い方法を見つけようとしているので、これを変換する序数から基数関数を探しています:
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
より動的なものに (行ごとに個別のステップを作成する代わりに)
ここに私のWebステップのサンプルがあります
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を使用し、その上で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