Ruby 黄瓜路由问题
我正在使用rails 3和cucumber,除了这个小问题,一切都进展顺利Ruby 黄瓜路由问题,ruby,ruby-on-rails-3,cucumber,bdd,Ruby,Ruby On Rails 3,Cucumber,Bdd,我正在使用rails 3和cucumber,除了这个小问题,一切都进展顺利 Given I am on the "edit automobile" page No route matches {:controller=>"automobiles", :action=>"edit"} (ActionController::RoutingError) 现在,路径在paths.rb中设置为edit_automobile_path 在routes.rb中,我有汽车作为一种资源,我搭建了
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路径并看到了路径
请在您的
功能/support/path.rb文件中为我指出正确的方向,这样的路径指定了一个唯一的资源,您需要通过编辑路径
一个id
在您的rake路线中,它看起来像汽车/:id/edit
所以你需要有编辑路径(: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
...
如果您想编辑特定的汽车,我想您可以在path.rb中使用以下内容:
when /^the edit automobile for "automobile1"$/
edit_automobile_path(Automobile.find_by_name(page_name.scan(/\"([^"]+)/)))
因此它将automobile1
作为参数传递给find_by_name()
在功能文件中,您可以执行以下操作:
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
Then(/^I want to visit edit automobile page for "(.*?)"$/) do |auto|
vehicle = Automobile.find_by_name(auto)
visit edit_automobile_path(vehicle.id)
end
您可以按照功能文件中的以下说明进行操作:
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|
automobile = Automobile.find_by_name(auto)
visit edit_automobile_path(automobile.id)
end
Then(/^I want to visit edit automobile page for "(.*?)"$/) do |auto|
vehicle = Automobile.find_by_name(auto)
visit edit_automobile_path(vehicle.id)
end
非常感谢,我还在学习,谢谢,谢谢,谢谢,好的,回去工作吧,没问题。别忘了,如果这个模型成为一个嵌套资源,你必须指定:automobile\u id或其他什么,因为它不知道要查找哪个id,所以你必须更改path.rb中的调用来处理这个问题。