0

I need to find weather no-follow link exists in external email and it should not be in any internal email.

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

It is giving error in assert_equal(int.try(:rel), nil). Can anybuddy guide me for solution?

My final goal is to test in User comment, External link should have rel='nofollow' attribute present or not?

4
  • what is the error it's giving?
    – dax
    Commented Aug 20, 2013 at 7:05
  • @dax error is NoMethodError: undefined method `rel' for #<Capybara::Element tag="a"> Commented Aug 20, 2013 at 7:07
  • this might help make things easier? samuelmullen.com/2011/12/…
    – dax
    Commented Aug 20, 2013 at 7:23
  • Sorry dax, I didn't find solution there. Commented Aug 20, 2013 at 8:07

1 Answer 1

1

Why not check for the presence of the link without the rel='nofollow'?

find(:xpath, "//a[@href='http://www.internallink.com/soccer' and @rel != 'nofollow']")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.