【发布时间】:2014-04-11 00:17:51
【问题描述】:
spec/features/album_spec.rb:
feature "Album Pages" do
given(:album) { create(:album) } # by Factory_Girl
scenario "Edit album" do
visit edit_album_path album
fill_in "Name", with: "bar"
expect {click_button "Update Album"}.to change(Album.last, :name).to("bar")
end
end
错误:
1) Album Pages Edit album
Failure/Error: expect {click_button "Update Album"}.to change(Album.last, :name).to("bar")
name should have been changed to "bar", but is now "Gorgeous Granite Table"
# ./spec/features/albums_spec.rb:27:in `block (2 levels) in <top (required)>'
应用程序运行良好,如果我单击按钮,它会重定向到专辑的网站,其名称显示为<h1>。我试过这个:
scenario "Edit album" do
visit edit_album_path album
fill_in "Name", with: "bar"
click_button "Update Album"
save_and_open_page
#expect {click_button "Update Album"}.to change(Album.last, :name).to("bar")
end
我得到了一个页面,其中bar 为<h1>,所以我不知道我的测试出了什么问题,我可以在 test.log 中看到:
SQL (0.7ms) UPDATE "albums" SET "name" = ?, "updated_at" = ? WHERE "albums"."id" = 1 [["name", "bar"], ["updated_at", Fri, 11 Apr 2014 11:30:00 UTC +00:00]]
有什么想法吗?
【问题讨论】:
-
我假设你在 github 上的某个地方有我可以查看的代码。
-
对,对:here.
标签: ruby-on-rails rspec