【发布时间】: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