規格/功能/ album_spec.rb:Rspec的功能測試問題
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上的某處,我可以查看。 – drKreso
確實如此:[here](https://github.com/pawel7318/footoo)。 – pawel7318