【发布时间】:2016-06-06 19:58:52
【问题描述】:
在文件中
_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号线的管道?如果没有管道,它会通过期望“删除”但只找到“配置文件”而使 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 'a[href=?]', user_path(user), text: 'delete',第 16 行是循环开始的地方。
编辑 2:UUUUGHGHH。这个测试有时会失败。好迷茫。现在它通过了,我没有对相关文件进行任何编辑。
【问题讨论】:
-
你能粘贴测试吗?
-
管道只是 UI 上两个链接之间的符号。
-
我记得他测试响应中是否存在管道(管道刚刚显示,文本检查它是否存在。
标签: ruby-on-rails