【问题标题】:Hartl tutorial chap. 9.3.3. pagination test failHartl 教程章节。 9.3.3.分页测试失败
【发布时间】:2014-11-25 06:42:25
【问题描述】:

如果我的测试失败,我将不胜感激。我是根据 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)>'

【问题讨论】:

    标签: testing pagination


    【解决方案1】:

    我认为行:

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

    应该是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多