值未编辑。黄瓜+水豚

时间:2014-12-07 11:34:43

标签: ruby-on-rails cucumber capybara bdd

我有一个简单的BDD测试。

我有这样的场景:

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

我有这样的步骤:

When /^(?:|I )go to (.+)$/ do |page_name|
  visit path_to(page_name)
end

When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
  fill_in(field, :with => value)
end

When /^(?:|I )press "([^"]*)"$/ do |button|
  click_button(button)
end

Then /^the director of "([^"]*)" should be "([^"]*)"$/ do |movie, director|
    film = Movie.find_by_title(movie)
    puts page.body
    assert film.director.should == director
end

我的问题是导演价值不是编辑。我无法将它与导演进行比较。

其他值正确分配,我可以断言" film.rating.should == director"得到那个预期的" Ridley Scott"得到了" R"。但对于导演我没有。

对于我已创建用于编辑导演或数据库的字段的视图不是问题,其中我有一个dirctor列。

我的直觉是db没有重新加载但是我找不到这个命令。

我会很高兴得到任何帮助:)

答案:

我忘了在我的模型中包括:导演,而且它无法回顾这个论点。 Thnx,因为我从中学到了任何帮助。

1 个答案:

答案 0 :(得分:1)

你的直觉是正确的,我不知道如何重新加载数据库,不过我要说的是因为你写的集成测试只关注用户如何看待网站。< / p>

如果你给了你的测试更多的步骤,比如导航到&#34; Alien&#34;电影页面并检查页面上显示的导演是否是&#34; Ridley Scott&#34;你会知道导演已经在你的数据库中被更改了,但它也被显示在你的视图中(没有通过直接检查数据库来检查)。

Rspec expectations非常适合检查网页内容。

例如

expect(page).to have_text("Director: #{director})