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
Capybara’s
have_selectormatcher takes an option:text, not:content:See this discussion and this discussion on github.
However, that doesn’t explain why your spec fails, since the
:contentoption 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_viewsjust inside thedescribeblock.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.