ruby或rails中是否有序数到基数函数?
我正在尝试找到一种更好的方式来表达我的黄瓜,所以我正在寻找一个序数到基数函数,将其转换
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?我希望将“第一个”转换为基数,这样我就可以替换。您也可以建议一种更好的方式来声明 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
I'm trying to find a better way in expressing my cucumbers so I am looking for an ordinal to cardinal function that converts this:
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
into something more dynamic(instead of creating separate steps for each line)
here's a sample of my web steps
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
See that 0 and 1? I wish to convert "first" to a cardinal number so i can just substitute. You can also just suggest a better way to declare the cukes :)
UPDATED ANSWER
I am in the middle of refactoring but basically I used 1st instead of first and used to_i on that.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我并不完全理解,确切地说你想要做什么,但是你可以在积极支持的情况下做这样的事情:
并且有一个动作视图助手 number_in_words 来获取“第一”,“第二”等
我对 cukes 不太了解对不起,
i dont really completely understand,exactly what you want to do, but you can do something like this with active support:
and there is a action view helper number_in_words to get "first" , "second" etc
i don't know much about cukes sorry,
使用简短、易于解析的序数词:
Use the short-form, easily-parsable ordinal:
此函数内置于 Chronic 中:
This function is built into Chronic: