黄瓜功能显示错误“无路线匹配”

时间:2012-08-24 10:42:20

标签: ruby-on-rails ruby cucumber

我有一个像这样的功能文件

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"

现在我有一个这样的步骤定义,它传递给定存在以下电影:case。

Given /the following movies exist/ do |movies_table|
  movies_table.hashes.each do |movie|
  Movie.create!(movie)
end

但当黄瓜跑步时当我进入“Alien”的编辑页面时,它会抛出此错误

  

没有路线匹配{:action =>“edit”,:controller =>“movies”}
  (ActionController的:: RoutingError)   ./features/support/paths.rb:20:in`path_to'

我的paths.rb在path_to

中有这个案例
when /^the edit page for (.*)/
  m = Movie.find_by_title($1)
  edit_movie_path(m)

我检查过m是否为零,但在后台我添加了四部电影到数据库。 我还检查了'rake routes',但所有路线都存在。

请帮助我理解,我对铁路和黄瓜很新。感谢

1 个答案:

答案 0 :(得分:0)

(.*)周围缺少双引号

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"')来获取网址。 因此,您递交path_to函数的情况应仅提取名称Alien。由于缺少双引号,$1包含"Alien"而不是Alienfind_by_title实际上正在寻找下面的电影

m = Movie.find_by_title('"Alien"') # Doesn't exist for sure ;)