在文件
中_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>
为什么我需要&#39; |&#39; 5号线的管道?没有管道,它会通过期待&#34;删除&#34;而使user_index_test.rb失败。但只能找到&#34; Profile&#34;。当我放入管道时,所有测试都通过了。我不明白为什么需要管道。
编辑:
感谢那些指出它在&lt;%标签之外的人,这意味着它只是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&#39; a [href =?]&#39;,user_path(用户),text:&#39; delete&#39;,第16行是哪里循环开始。
编辑2:UUUUGHGHH。此测试有时仅失败。很困惑。现在它已经过去了,我没有对相关文件进行编辑。