我有一个类似的功能文件
Feature: search for movies by director
As a movie buff
So that I can find movies with my favorite director
I want to include and serach on director information in movies I enter
Background: movies in database
Given the following movies exist:
| title | rating | director | release_date |
| Star Wars | PG | George Lucas | 1977-05-25 |
| Blade Runner | PG | Ridley Scott | 1982-06-25 |
| Alien | R | | 1979-05-25 |
| THX-1138 | R | George Lucas | 1971-03-11 |
Scenario: add director to existing movie
When I go to the edit page for "Alien"
And I fill in "Director" with "Ridley Scott"
And I press "Update Movie Info"
Then the director of "Alien" should be "Ridley Scott"
现在我有一个这样的步骤定义,它通过了给定以下电影的存在:案例。
Given /the following movies exist/ do |movies_table|
movies_table.hashes.each do |movie|
Movie.create!(movie)
end
结束
但当黄瓜运行步骤时,当我转到"外星人"的编辑页面时,它会抛出这个错误
没有路由匹配{:action=>"编辑",:controller=>"电影"}
(ActionController::RoutingError)./features/support/paths.rb:20:在"path_to"中
我的paths.rb在path_to 中有这个案例
when /^the edit page for (.*)/
m = Movie.find_by_title($1)
edit_movie_path(m)
我检查过m是零,但在后台我把其中四部电影添加到了数据库中。我还检查了"确定路线",但所有路线都存在。
请帮我理解,我对铁轨和黄瓜很陌生。感谢
(.*)
周围缺少双引号
when /^the edit page for (.*)/
应该是
when /^the edit page for "(.*)"/
解释:假设您的websteps.rb包含
When /^(?:|I )go to (.+)$/ do |page_name|
visit path_to(page_name)
end
这意味着它将首先通过调用path_to('the edit page for "Alien"')
来获取url。因此,您提交path_to
函数的情况应该只提取名称Alien
。由于缺少双引号,$1
包含"Alien"
,而不是仅包含Alien
。find_by_title
实际上正在寻找一部低于的电影
m = Movie.find_by_title('"Alien"') # Doesn't exist for sure ;)