ruby on rails - Test Error Expected at least 1 element matching "login_path" -


i have integration test isn't working. seems straight forward why won't work tried fix 2 hours , can't.

seems straight forward. can't see whats wrong this. clues?

the error when run rake test

  1) failure: userslogintest#test_login_with_valid_information_followed_by_logout [/users/josephkonop/documents/safsy/website/safsy/safsy/test/integration/users_login_test.rb:32]: expected @ least 1 element matching "a[href="/login"]", found 0.. expected 0 >= 1. 

the test. line 32 assert_select "a[href=?]", login_path

  test "login valid information followed logout"     login_path     post login_path, sessions: { email: @user.email, password: 'password' }     assert is_logged_in?     assert_redirected_to @user     follow_redirect!     assert_template 'users/show'     assert_select "a[href=?]", login_path, count: 0     assert_select "a[href=?]", logout_path     assert_select "a[href=?]", user_path(@user)     delete logout_path     assert_not is_logged_in?     assert_redirected_to root_url     assert_select "a[href=?]", login_path     assert_select "a[href=?]", signup_path     assert_select "a[href=?]", logout_path,      count: 0     assert_select "a[href=?]", user_path(@user), count: 0   end 

my _header login button is

      <ul class="nav navbar-nav navbar-right">            <% if logged_in? %>           <li><%= link_to "users", users_path %></li>           <li><%= link_to "dash", users_path %></li>           </li>           <ul class="nav navbar-nav">             <li class="dropdown">               <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">items<span class="caret"></span></a>               <ul class="dropdown-menu">                 <li><%= link_to "new item", new_item_path %></li>                 <li><%= link_to "edit items", user_items_path %></li>                 <li><a href="#">mass upload items</a></li>                 <li><a href="#">upload item images</a></li>               </ul>             </li>           </ul>           <ul class="nav navbar-nav">             <li class="dropdown">               <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">profile<span class="caret"></span></a>               <ul class="dropdown-menu">                 <li><%= link_to "view profile", user_path(current_user) %></li>                 <li><%= link_to "edit profile", edit_user_path(current_user) %></li>               </ul>             </li>           </ul>           <li><%= link_to "messages", users_path %></li>           <li><%= link_to "log out", logout_path, method: "delete" %></li>         <% else %>           <li><%= link_to "log in", login_path %></li>           <li><a href="#">sign up</a></li>         <% end %>       </ul>     </div><!-- /.navbar-collapse -->   </div><!-- /.container-fluid --> </header> 

you need follow redirect after asserting you've been redirected, before checking login_path url.

from hartl's tutorial:

test "login valid information followed logout"     login_path     post login_path, session: { email: @user.email, password: 'password' }     assert is_logged_in?     assert_redirected_to @user     follow_redirect!     assert_template 'users/show'     assert_select "a[href=?]", login_path, count: 0     assert_select "a[href=?]", logout_path     assert_select "a[href=?]", user_path(@user)     delete logout_path     assert_not is_logged_in?     assert_redirected_to root_url     follow_redirect!  # line need     <---     assert_select "a[href=?]", login_path     assert_select "a[href=?]", logout_path,      count: 0     assert_select "a[href=?]", user_path(@user), count: 0 end 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -