I have the following:
test "should update deal" do
patch user_deal_url(@user, @deal), params: { deal: { name: @deal.name+'xxx' } }
# p @response.body
# p @deal.errors.full_messages
assert_select ".alert", false # should not have alert
assert_redirected_to dashboard_url
follow_redirect!
assert_select ".alert", "Deal was successfully updated."
end
It only says:
Failure:
DealsControllerTest#test_should_update_deal [C:/Users/Chloe/workspace/test/controllers/deals_controller_test.rb:73]:
Expected response to be a <3XX: redirect>, but was a <200: OK>
I thought I could print @deal.errors.full_messages
but it's not the same @deal
in the controller. I'm able to print the entire response body and copy it into Notepad++ and search for the error messages, but it's so tedious. I thought I can assert that .alert
doesn't exist and it would tell me what it actually was. I added
assert_select "#error_explanation", false # should not have error
But that only told me that it exists, not why it failed.
Expected exactly 0 elements matching "#error_explanation", found 1..
Expected: 0
Actual: 1
So how do you quickly determine why a model is failing to save or update in a controller during testing?
Rails 5.0.2
Reference: http://ift.tt/MUotxZ
Aucun commentaire:
Enregistrer un commentaire