0
我正在添加一些控制器测试以确保我的分页工作正常。我使用gemfile“Will-paginate”,它会自动为30位用户添加分页。在这个测试中,我添加31个用户并查找选择器,但是我收到的错误告诉我,分页从不出现。我究竟做错了什么?RSpec控制器测试分页
谢谢你们!
HAML:
= will_paginate @users, :class => 'pagination'
user_controller_spec.rb
let(:user) { FactoryGirl.create(:user) }
describe 'GET #index' do
before { get :index }
it { should respond_with(200) }
it { should render_template('index') }
it { should render_with_layout('application') }
it { should use_before_action(:authorize_user!) }
it 'shows pagination' do
users = FactoryGirl.create_list(:user, 31)
expect(:index).to have_css('div.pagination')
end
end
错误:
1) Admin::UsersController GET #index shows pagination
Failure/Error: expect(:index).to have_css('div.pagination')
expected to find css "div.pagination" but there were no matches
验证,如果你有实际31个用户'希望(User.count)。为了EQ 31',如果你这样做是正确的链接将显示 ' – DevMarwen
嗨Marwen, 有用的评论。谢谢!它证实有35个用户(我以前也创造了几个) 故障/错误:期待(User.count)。为了EQ 31 预期:31 了:35 所以有35个用户,并应显示分页? – Andy
问题是测试仍然失败 – Andy