My page should contain a link that looks like <a href="/desired_path/1">Click to go</a>
.
How would you test for that using assert_select? I want to check for the presence of an a
tag with href="/desired_path/1"
. How do you test the attributes of a tag?
Are there any resources to explain how to use assert_select? I read the Guides and API documentation, but didn't figure it out. Are there any recommended better ways of doing this?
I am working in Rails 3 and using the built-in test framework.
Thanks.
In assert_select, you can also use a question mark for the attribute value, and then follow with a string to match.
assert_select "a[href=?]", "/desired_path/1"
There's another way to use assert_select that is more friendly, especially if you want to match a partial string or regexp pattern:
assert_select "a", :href => /acebook\.com\/share/