2

如果我的测试失败,我将不胜感激。我是根据 Michael Hartl 教程做的,我尝试了几乎所有的东西并阅读了很多关于它的内容,但仍然一无所知。坦克斯

我的测试:

描述“分页”做

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)>'
4

1 回答 1

0

我认为这条线:

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

应该:

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

于 2014-02-26T09:57:45.780 回答