cor*_*ded 10 ruby ordinals ruby-on-rails cardinality cucumber
我正试图找到一种更好的方式来表达我的黄瓜,所以我正在寻找一个序数到基数函数来转换这个:
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
Run Code Online (Sandbox Code Playgroud)
更动态的东西(而不是为每一行创建单独的步骤)
这是我的网页步骤的示例
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
Run Code Online (Sandbox Code Playgroud)
看到0和1?我希望将"第一"转换为基数,以便我可以替代.你也可以建议一个更好的方式来宣布你的cukes :)
更新的答案 我正处于重构的过程中,但基本上我使用的是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
Run Code Online (Sandbox Code Playgroud)
loo*_*non 19
我真的不完全理解,你究竟想做什么,但你可以通过积极的支持做这样的事情:
1.ordinalize # => "1st"
2.ordinalize # => "2nd"
1002.ordinalize # => "1002nd"
Run Code Online (Sandbox Code Playgroud)
并且有一个动作视图助手number_in_words来获得"第一","第二"等
我不太了解cukes抱歉,
使用简短形式,易于解析的序数:
When /^I fill up the (\d+)(?:st|nd|rd|th) passenger field$/ do |n|
# etc...
end
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4182 次 |
最近记录: |