用户索引测试失败Rails教程

时间:2018-05-18 22:37:28

标签: ruby-on-rails ruby ruby-on-rails-5 railstutorial.org

警告:这是一个新手问题,请原谅我。

当我在我正在构建的rails示例应用程序上运行rails测试时,我收到此错误:

Failure:
UsersIndexTest#test_index_as_admin_including_pagination_and_delete_links [/home/ec2-user/environment/sample_app/test/integration/users_index_test.rb:16]:
Expected at least 1 element matching "div.pagination", found 0..
Expected 0 to be >= 1.

和这一个:

Failure:
UsersProfileTest#test_profile_display [/home/ec2-user/environment/sample_app/test/integration/users_profile_test.rb:17]:
Expected at least 1 element matching "div.pagination", found 0..
Expected 0 to be >= 1.

显然,它与我的show.html.erb文件有关,但我无法弄清楚它是什么。以下是文件内容:

<% provide(:title, @user.name) %>
<div class="row">
  <aside class="col-md-4">
    <section class="user_info">
      <h1>
        <%= gravatar_for @user %>
        <%= @user.name %>
      </h1>
      <%= @user.created_at %> <br>
      <%= @user.updated_at %> <br>
      <%= Time.now %>
    </section>
  </aside>
  <div class="col-md-8">
    <% if @user.microposts.any? %>
      <h3>Microposts (<%= @user.microposts.count %>)</h3>
      <ol class="microposts">
        <%= render @microposts %>
      </ol>
      <%= will_paginate @microposts %>
    <% end %>
  </div>
</div>

我不知道问题是什么。

编辑:以下是测试:

  1. user_profile_test.rb
  2. ....测试“个人资料显示”做

        get user_path(@user)
        assert_template 'users/show'
        assert_select 'title', full_title(@user.name)
        assert_select 'h1', text: @user.name
        assert_select 'h1>img.gravatar'
        assert_match @user.microposts.count.to_s, response.body
        assert_select 'div.pagination'
        @user.microposts.paginate(page: 1).each do |micropost|
          assert_match micropost.content, response.body
        end
      end
    

    1. users_index_test.rb
    2. ...测试“索引作为管理员包括分页和删除链接”执行

          log_in_as(@admin)
          get users_path
          assert_template 'users/index'
          assert_select 'div.pagination'
          first_page_of_users = User.paginate(page: 1)
          first_page_of_users.each do |user|
            assert_select 'a[href=?]', user_path(user), text: user.name
            unless user == @admin
              assert_select 'a[href=?]', user_path(user), text: 'delete'
            end
          end
          assert_difference 'User.count', -1 do
            delete user_path(@non_admin)
          end
        end
      

0 个答案:

没有答案