Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:28:10+00:00 2026-06-06T18:28:10+00:00

The test I am using is: it { should have_link(‘Logout’, href: logout_url) } I

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:28:11+00:00Added an answer on June 6, 2026 at 6:28 pm

    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:

    it { should have_link('Logout', href: logout_url) }
    

    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_link is what’s called the locator. 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 the logout_url link.

    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_url and not logout_path. By default, rails doesn’t always generate the full url for most links. It just generates paths. Here’s the difference:

    users_url: http://localhost/users
    users_path: /users
    

    Check your page to see which of these types of url’s are being generated by your app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Test::Unit with shoulda to test a controller. Since I'm just testing the
I just started using Cucumber and am not sure how to test a partial
Note: I'm using Google Chrome Currently I have this test page http://www.evecakes.com/doodles/canvas_size_issue.htm It should
I'm trying to test using SFML's full screen mode, however it crashes every time
When running py.test using a plugin that loads xmlrpclib the test run fails with:
I am writing a test using easymock + powermock, the reason I am using
I'm trying to test using QTP a web app that is using ajax4jsf to
When running a test using the Tornado AsyncHTTPTestCase I'm getting a stack trace that
I've written an rspec test using Watir against a web application and it's running
I'm doing a simple test using the wakoopa (software tracking) api . Typing the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.