0

我有一个这样的功能文件

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

结尾

但是当黄瓜运行步骤时,当我进入“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 是否为零,但在后台我将四部电影添加到数据库中。我还检查了“耙路线”,但所有路线都存在。

请帮助我理解,我对铁轨和黄瓜很陌生。谢谢

4

1 回答 1

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。由于缺少双引号,因此$1is contains"Alien"而不是 only Alien。实际上是在find_by_title寻找像下面这样的电影

m = Movie.find_by_title('"Alien"') # Doesn't exist for sure ;)
于 2012-08-24T10:50:52.433 回答