黄瓜的路由问题

我正在使用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我有汽车作为资源,我搭建了它

所以请告诉我我错过了什么,显然路线是定义和匹配的,因为我跑了耙路线并看到了路线。

请指出我正确的方向

在您的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 ... 

在您的function文件中,您可以执行以下操作:

 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 

如果你想编辑特定的汽车,我想你可以在paths.rb中使用以下内容:

 when /^the edit automobile for "automobile1"$/ edit_automobile_path(Automobile.find_by_name(page_name.scan(/\"([^"]+)/))) 

所以它将find_by_name()作为参数传递给find_by_name()

您可以按照以下function文件中的说明执行此操作:

 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