Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing problem with cucumber

I am working with rails 3 and cucumber, all is going well except for this little problem

Given I am on the "edit automobile" page
  No route matches {:controller=>"automobiles", :action=>"edit"} (ActionController::RoutingError)

Now the path is set in paths.rb as edit_automobile_path

and in the routes.rb I have automobiles as a resource, I scaffolded it

so please tell me what I am missing, clearly the route is defined and matches, because I ran rake routes and saw the route.

please point me in the right direction

like image 699
creativeKoder Avatar asked Aug 26 '10 14:08

creativeKoder


4 Answers

In your features/support/paths.rb file for a path like this that specifies a unique resource you need to pass your edit_automobile_path an id,

in your rake routes it will look like automobiles/:id/edit

so you need to have edit_automobile_path(:id)

In order to do this in cucumber assume you have something like

Given I have an automobile
And I am on the 'edit automobile' page

In your given step def declare a variable @automobile = Automobile.create()

And then in your paths.rb file

when /edit automobile page/
  edit_automobile_path @automobile
...
like image 107
Jed Schneider Avatar answered Oct 03 '22 17:10

Jed Schneider


In your feature file you can do something like this :

Given I have an automobile
Then I want to visit edit automobile page for "automobile1"

Then in your step definition file:

Then(/^I want to visit edit automobile page for "(.*?)"$/) do |auto|
 automobile = Automobile.find_by_name(auto)
 visit edit_automobile_path(automobile.id)
end
like image 38
Rupali Avatar answered Oct 03 '22 17:10

Rupali


In case you want to edit a particular automobile, I guess you can use the following within paths.rb:

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

so it passes the automobile1 as a parameter to find_by_name().

like image 29
Ahmad Z. Tibi Avatar answered Oct 03 '22 18:10

Ahmad Z. Tibi


You can do it as mentioned below in your feature file :

Given I have an automobile
Then I want to visit edit automobile page for "automob"

Then in your step definition file:

Then(/^I want to visit edit automobile page for "(.*?)"$/) do |auto|
 vehicle = Automobile.find_by_name(auto)
 visit edit_automobile_path(vehicle.id)
end
like image 32
Anuradha Avatar answered Oct 03 '22 17:10

Anuradha