The test I am using is:
it { should have_link('Logout', href: logout_url) }
I am just testing for the existence of a <a> tag with Logout as the text, and the href to be logout_url path. Should I be using another syntax for this?
Gems:
rails 3.2.6
rspec-rails 2.10.1
capybara 1.1.2
There are a number of ways you can do this. I’d recommend (if you haven’t already) familiarizing yourself with the overall capybara dsl as well as some of the specific sections such as the capybara matchers.
I believe your test is fine written as:
as long as the link text really is ‘Logout’ and the href is specified correctly (see below).
According to the capybara docs, the first parameter to
have_linkis what’s called thelocator. In your case it’s ‘Logout’. This can be either the text in the link itself, or it can be the #id of the dom element. So in your case you need to have the text ‘Logout’ in the link that has thelogout_urllink.Note that locaters in capybara are case sensitive, so make sure you match on case.
You might also want to consider whether you should be using
logout_urland notlogout_path. By default, rails doesn’t always generate the full url for most links. It just generates paths. Here’s the difference:Check your page to see which of these types of url’s are being generated by your app.