【发布时间】:2015-04-14 13:16:54
【问题描述】:
在我看来,我有:
<%= link_to image_tag("remove.png", title: "remove"), user, method: :delete, data: { confirm: "This will permanently remove the user" } %>
我正在尝试编写一个测试以证明不存在此类链接和图像。我尝试了几个版本,但似乎都没有。我的最佳猜测是:
assert_select 'a[href=?]', user_path(user), method: :delete, count: 0
assert_select 'image_path(remove.png)', count: 0
第一个 assert_select 的测试运行,但计数 1 个这样的链接,而我很确定这样的链接不存在。我认为它正在计算确实存在 user_path(user) 的 show 方法(而不是 delete 方法)。
第二个 assert_select 的测试产生错误:
unexpected '.' after '["remove"]' (called from block (2 levels) in <class:SiteLayoutTest> at /test/integration/site_layout_test.rb:46)
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
【问题讨论】:
-
图片和链接不存在是什么情况?
-
它们只有在管理员登录时才可见(在索引视图中)。否则它们不可见。在服务器上手动测试似乎可以确认代码正常工作。所以似乎是测试写错了,特别是两个 assert_select 行(测试的其余部分工作正常)。
标签: ruby-on-rails ruby ruby-on-rails-4 testing