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 8666401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:43:20+00:00 2026-06-12T17:43:20+00:00

I am trying to write a unit test to assert few meta tag values

  • 0

I am trying to write a unit test to assert few meta tag values (under section of the response). How can I use the attribute tag to check individual value?
Ex:

<meta property="keyword" content="site keywords" />
<meta property="description" content="site description" />

So far this is all I got. But it comes back as failed.

it "should check meta fields" do
  get :show, {:format => 'html' }
  r = response.body
  r.should have_selector('meta', :content => @site.title)
end
  • 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-12T17:43:21+00:00Added an answer on June 12, 2026 at 5:43 pm

    Capybara’s have_selector matcher takes an option :text, not :content:

    r.should have_selector('meta', :text => @site.title)
    

    See this discussion and this discussion on github.

    However, that doesn’t explain why your spec fails, since the :content option is ignored and should make your test if anything more permissive.

    The most likely reason this test is failing is that it is being called from a controller spec, in which case the response will be blank because rspec-rails prevents rails from actually rendering views. If this is the case, you will need to either move the spec to a file under spec/requests/, or add the directive render_views just inside the describe block.

    If that doesn’t work then you’ll have to provide more information on the context for the spec, otherwise it’s hard to figure out what’s going wrong.

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

Sidebar

Related Questions

I'm trying to write a unit test for a controller that's nested, but can't
I'm trying to write a unit test that will loop through all action methods
i'm trying to write an unit test for my Android's RelativeLayout. Currently, my testcode
I am trying to write a unit test for my one controller to verify
I'm trying to write a unit test that will raise an event on a
I'm trying to write a unit test for a piece of code that generates
I am trying to write a unit test for a client server application. To
I am trying to write a Unit test for a class that has several
I'm trying to write a C# unit test with VS 2008's built-in unit testing
I am new to spock. I am trying to write a spock unit test

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.