OK; I found a bug in my app wherein a link made an incorrect reference. Off I go to write a test but turns out this isn’t so easy. The code is simple:
<%= link_to 'mylist', '/wrong_place' %>
which of course generates:
What I want to do is find the link based on the contained text ‘mylist’ and then test for the href value that I expect to be there.
From what I can tell, there’s no way to do this with CSS selectors: ‘mylist’ is a text element contained in the ‘a’ tag and if I search for that element value, there’s no way to move “up” to its parent, which is where the href attribute lives that I want to test. There was a :contains selector proposed for CSS3 which was removed; various posts claim that it was actually implemented in most browsers, but it doesn’t work in rspec.
Unless I’ve fallen down a rabbit hole and can’t see the obvious solution (entirely possible :=), the only way I figure I can test this is by adding an attribute (class, id, …) to the link which I can then use to select the link and test for the desired href value.
What’s the obvious answer?