在文件中
_user.html.erb
<li>
<%= gravatar_for user, size: 52 %>
<%= link_to user.name, user %>
<% if current_user.admin? && !current_user?(user) %>
| <%= link_to "delete", user, method: :delete,data: { confirm: "You sure?" } %>
<% end %>
</li>为什么我需要5号线上的管道?如果没有管道,它就会失败,因为它期望“删除”,但只查找“配置文件”。当我把管子放进去时,所有的测试都通过了。我不明白为什么我需要烟斗。
编辑:
感谢那些指出它在<%标记之外的人,这意味着它只是HTML中的文本。所以这是测试,在文件users_index_test.rb ..。
test "index as admin including pagination and delete links" do
log_in_as(@user)
get users_path
assert_template 'users/index'
assert_select 'div.pagination'
first_page_of_users = User.paginate(page: 1)
first_page_of_users.each do |user|
assert_select 'a[href=?]', user_path(user), text: user.name
unless user == @admin
assert_select 'a[href=?]', user_path(user), text: 'delete'
end
end
assert_difference 'User.count', -1 do
delete user_path(@non_admin)
end
end所以我想问题不再是关于管道的了。这是为什么我的测试套件失败的消息:
test_index_as_admin_including_pagination_and_delete_links#UsersIndexTest (1460776244.08s)
<delete> expected but was
<Profile>..
Expected 0 to be >= 1.
test/integration/users_index_test.rb:19:in `block (2 levels) in <class:UsersIndexTest>'
test/integration/users_index_test.rb:16:in `block in <class:UsersIndexTest>'顺便说一下,第19行写着`assert_select 'ahref=?',user_path(用户),文本:‘删除’,第16行是循环开始的地方。
编辑2: UUUUGHGHH这个测试有时会失败。太困惑了。现在它已经过去了,我没有对相关文件进行编辑。
https://stackoverflow.com/questions/37665867
复制相似问题