Hartl教程。 9.3.3。分页测试失败

时间:2013-09-27 12:58:14

标签: testing pagination

如果我的测试失败,我将不胜感激。我是基于Michael Hartl教程做的,我几乎尝试了所有内容并阅读了很多关于它的内容,但仍然无能为力。 Tahnks

我的测试:

描述“分页”做

before(:all) do
  sign_in FactoryGirl.create(:user)
  30.times { FactoryGirl.create(:user) }
  visit users_path
end

after(:all)  { User.delete_all }

it 'has the right div' do
  page.should have_selector('div.pagination')
end

it "should list each user" do
  User.paginate(page: 1).each do |user|
    expect{page}.to have_selector('li', text: user.username)
  end
end

我的观点:

<h1>Všichni uživatelé</h1>

<%= will_paginate %>
<ul class="users">
  <% @users.each do |user| %>
    <li>
      <%= gravatar_for user%>
      <%= link_to user.username, user %>
    </li>
  <% end %>
</ul>

<%= will_paginate(:renderer => BootstrapPagination::Rails)%>

我的控制器:

def index
 @users = User.paginate(page: params[:page])
end

我的错误:

 1) User pages index pagination should list each user
 Failure/Error: expect{page}.to have_selector('li', text: user.username)
   expected css "li" with text "Person 44" to return something
 # ./spec/requests/user_pages_spec.rb:122:in `block (5 levels) in <top (required)>'
 # ./spec/requests/user_pages_spec.rb:121:in `block (4 levels) in <top (required)>'

1 个答案:

答案 0 :(得分:0)

我认为这一行:

期待{page} .to have_selector('li',text:user.username)

应该是:

期待{page} .to have_selector('li',text:user.user.name)