0
改變了我有這樣的特徵:Rspec的 - 預計#COUNT由1變了,但被0
feature "Blog features -", type: :feature, js: true do
let!(:admin) { FactoryGirl.create(:admin) }
scenario "Create new Blog" do
expect do
sign_in_as_admin(admin)
visit "/admin/blogs/new"
fill_in "blog_title", with: "title"
fill_in "blog_content", with: "lorem ipsum dolor"
click_button "Save"
end.to change(Blog, :count).by(1)
end
end
博客是正確保存在數據庫中,但測試沒有通過,我得到這個錯誤:expected #count to have changed by 1, but was changed by 0
嘗試更改(Blog.count)。從(0)。到(1) – forthowin
然後我得到:預期#count已從0更改爲1 - 但沒有更改,但博客正在正確保存在db :/ – darkcode
你爲什麼要把這段代碼放在期望的任何原因?你可以移動它,並在click_button「保存」後,預計(Blog.count).to eq(1) – forthowin