Routing problem with cucumber

喜欢而已 提交于 2019-12-04 07:40:25

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
Ahmad Z. Tibi

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!