gpt4 book ai didi

testing - Hartl 教程章节。 9.3.3.分页测试失败

转载 作者:行者123 更新时间:2023-11-28 20:15:37 24 4
gpt4 key购买 nike

对于我的测试失败的任何帮助,我将不胜感激。我是根据 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)%>

我的 Controller :

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

最佳答案

我认为行:

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

应该是:

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

关于testing - Hartl 教程章节。 9.3.3.分页测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19051381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com