【问题标题】:Value is not edited. Cucumber + Capybara值未编辑。黄瓜+水豚
【发布时间】:2014-12-09 03:01:02
【问题描述】:

我有一个任务要做简单的 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 列的 director 或 db 的视图的问题。

我的直觉是 db 没有重新加载,但我找不到用于此的命令。

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

答案:

我忘记在我的模型中包含 :director,它无法检索参数。感谢您的帮助,因为我从中学到了任何东西。

【问题讨论】:

  • 您是否为test 环境迁移了数据库,为cucumber 环境迁移了数据库?
  • 我使用了 rake db:test:prepared 但它仍然没有通过编辑的值
  • RAILS_ENV=test rake db:migrate 你正在使用名为test的测试数据库

标签: ruby-on-rails cucumber capybara bdd


【解决方案1】:

您的直觉是正确的,我也不知道如何准确地重新加载数据库,但我想说的是,因为您编写集成测试只关注用户如何看待网站。

如果您再进行一些测试,例如导航到“外星人”电影页面并检查页面上显示的导演是否是“雷德利·斯科特”,您就会知道导演在您的数据库中已更改,但并且它正在您的视图中显示(通过直接检查数据库未检查的内容)。

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

例如

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

【讨论】:

  • 责任在我这一边,顺便说一句,当我将主管参数推送到 attr_accessor 时,您的回答也是正确的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-06
  • 2012-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多