我正在使用rails 3和黄瓜,除了这个小问题外,一切顺利
Given I am on the "edit automobile" page
No route matches {:controller=>"automobiles", :action=>"edit"} (ActionController::RoutingError)
现在路径在paths.rb中设置为edit_automobile_path
在routes.rb我有汽车作为资源,我把它搭建了
所以请告诉我我错过了什么,显然路线是定义和匹配的,因为我跑了rake路线并看到了路线。
请指出我正确的方向
答案 0 :(得分:9)
在您的features/support/paths.rb
文件中,如果这样的路径指定了您需要传递edit_automobile_path
个ID的唯一资源,
automobiles/:id/edit
所以你需要edit_automobile_path(:id
)
为了在黄瓜中这样做,假设你有类似
的东西Given I have an automobile
And I am on the 'edit automobile' page
在您给定的步骤中,def声明变量@automobile = Automobile.create()
然后在你的paths.rb文件中
when /edit automobile page/
edit_automobile_path @automobile
...
答案 1 :(得分:2)
在您的功能文件中,您可以执行以下操作:
Given I have an automobile
Then I want to visit edit automobile page for "automobile1"
然后在您的步骤定义文件中:
Then(/^I want to visit edit automobile page for "(.*?)"$/) do |auto|
automobile = Automobile.find_by_name(auto)
visit edit_automobile_path(automobile.id)
end
答案 2 :(得分:1)
如果你想编辑特定的汽车,我想你可以在paths.rb中使用以下内容:
when /^the edit automobile for "automobile1"$/
edit_automobile_path(Automobile.find_by_name(page_name.scan(/\"([^"]+)/)))
因此它将automobile1
作为参数传递给find_by_name()
。
答案 3 :(得分:1)
您可以按照以下功能文件中的说明进行操作:
Given I have an automobile
Then I want to visit edit automobile page for "automob"
然后在您的步骤定义文件中:
Then(/^I want to visit edit automobile page for "(.*?)"$/) do |auto|
vehicle = Automobile.find_by_name(auto)
visit edit_automobile_path(vehicle.id)
end