vendredi 9 octobre 2015

Expected at least 1 element matching "div#error_explanation", found 0.. Expected 0 to be >= 1

I'm a rails noob & can't make the connection of this error and the code while following Hartl's Rails tutorial.

Similar questions here @ stackoverflow don't solve the problem of my particular test failure error message as my partial code is same as Hartl's code on github and all other aspects of my integration testing pass green.

sample_app_3rd_edition/app/views/shared/_error_messages.html.erb

Here is my code from the integration test

/test/integration/password_resets_test.rb

       #Invalid password & confirmation
       patch password_reset_path(user.reset_token),
         email: user.email,
         user: { password:               "foobazz",
                 password_confirmation:  "barquux" }
       assert_select 'div#error_explanation'

which generates an error message referring to line 6:

test_password_resets#PasswordResetsTest (1442030711.19s)
    Expected at least 1 element matching "div#error_explanation", found 0..
    Expected 0 to be >= 1.

Next is the partial

/app/views/shared/_error_messages.html.erb

from which assert_select 'div#error_explanation' is supposed to render the error message needed for the invalid password and confirmation.

/app/views/shared/_error_messages.html.erb

<% if @user.errors.any? %>
     <div id="error_explanation">
       <div class="alert alert-danger">
      The form contains <%= pluralize(@user.errors.count,"error") %>
       </div>
       <ul>
         <% @user.errors.full_messages.each do |msg| %>
           <li><%= msg %></li>
         <% end %>
       </ul>
    </div>
 <% end %>

I simply don't understand why assert_select is not working here since the _error_message partial works for all other tests referencing the same partial. I think I understand that the integration test failure is telling me that "there is no message (element) where there should be one."

Help clearing up my confusion is greatly appreciated! I'll be happy to post UserController/ PasswordController or whatever @user variable code is needed.

Aucun commentaire:

Enregistrer un commentaire