我需要在外部电子邮件中找到天气无跟踪链接,它不应该在任何内部电子邮件中。
test "should have nofollow in external links and not in internal links in comment" do
visit @game_path
fill_in('comment_comment', :with => 'Please click link <a href='http://www.internallink.com/soccer'> internal link <a/> and click external link <a href='http://www.google.com'> external link <a/>
click_button('submit_comment')
assert page.has_no_css?('div.error'), "Error div found on page after posting comment"
assert page.has_content?('Please click link '), "Comment not found on page after posting"
ext = find(:xpath, "//a[@href='http://www.google.com']")
assert_equal(ext['rel'], "nofollow")
internal = find(:xpath, "//a[@href='http://www.internallink.com/soccer']")
assert_equal(internal.try(:rel), nil)
end
在assert_equal(int.try(:rel), nil)
中出错。 anybuddy可以指导我寻求解决方案吗?
我的最终目标是在用户评论中测试,外部链接是否应该包含rel ='nofollow'属性?
答案 0 :(得分:1)
为什么不检查是否存在没有rel ='nofollow'的链接?
find(:xpath, "//a[@href='http://www.internallink.com/soccer' and @rel != 'nofollow']")