Rails: How to use Capybara to test a link's href-value without caring about the text? -


capybara provides useful method check link:

have_link 

which far can tell can used like:

have_link("link_text", :href => "actual link") 

however, don't care link_text, rather want check href (as linking test text more brittle). if want check href view test.

how use capybara check href without needing check text? maybe can use regex?

[edit] changed wording based on answer below

capybara doesn't provide link_to method i'm not sure you're getting (rails provides link_to generating links in view). find link based on href using capybara do

link = page.find(:css, 'a[href="actual link"]') 

or if you're looking assert element exists

page.assert_selector(:css, 'a[href="actual link"]') 

or - if using rspec

expect(page).to have_selector(:css, 'a[href="actual link"]') 

since have link default searches substrings in link text can

expect(page).to have_link(nil, href: 'actual link') 

or

page.assert_selector(:link, nil, href: 'actual link') 

Comments