assert_tag for a hyperlink in a functional test’s response

I spent some time yesterday trying this out.
I am writing it here to save your time.

Here is the functional test’s code to check for a hyperlink with text “Back to Index” which links to the index action of the controller being tested.

link = find_tag :tag => "a", :content =>"Back to Inbox"
assert_equal @controller.url_for(:action => 'index', :only_path => true), link.attributes["href"]

It could have been done in a single assert_tag … but the statement becomes too long.


  1. Hi

    I found this link on google while searching for a solution of similar issue and YES your code worked for me, I am new ruby learner so wanted extend my thanks for the time you spent to save our time

    Thanks again


Leave a Reply

Your email address will not be published. Required fields are marked *

thirteen − = 8