Testing views with will_paginate Gem using Capybara/Rspec

无人久伴 提交于 2019-12-06 06:17:16

When you use:

before(:all)  { 30.times { FactoryGirl.create(:user) } }

You already have an user created so the total count goes up to 31 and so it paginates (pagination with will_paginate shows 30 records per page by default).

Try creating 31 microposts instead of 30, it should pass.

before(:each) { 31.times { FactoryGirl.create(:micropost, user: user) } }

Edit: I forgot to pass the :user to the micropost Factory, it should work now (is the code I have on my tests and it passes)

Austin B

According to http://thewebfellas.com/blog/2008/8/3/roll-your-own-pagination-links-with-will_paginate

"<%= will_paginate %>" produces a div tag with class = pagination, but I didn't see anything that would imply making testing for 'div.pagination' pass.

I changed the test to

it { should have_selector('div', class: 'pagination') }

and that should basically test the same thing, and this passes for me. Hope this helps!

jsonmanz
<%= provide (:title, 'All users') %>
<h1>All users</h1>

<div class="pagination">
<%=will_paginate%>
</div>

<ul class="users">
<%=render @users%>
</ul> 

<div class="pagination">
<%= will_paginate %>
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!