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
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
...
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
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()
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With