Hi I wanna match meta og tags. So I modify a bit the matcher from spree/spree's capybara_ext.rb.
RSpec::Matchers.define :have_meta do |name, expected|
match do |actual|
has_css?("meta[property='#{name}'][content='#{expected}']", visible: false)
end
failure_message_for_should do |actual|
actual = first("meta[property='#{name}']")
if actual
"expected that meta #{name} would have content='#{expected}' but was '#{actual[:content]}'"
else
"expected that meta #{name} would exist with content='#{expected}'"
end
end
endI use it like this (visit the root_path using capybara):
describe "should have meta tags" do
include ApplicationHelper
it "checks for home page's meta og:title" do
expect(page).to have_meta('og:title', page_title)
end
it "checks for home page's meta og:description" do
page.should have_meta('og:description', description)
end
endpage_title and description are from ApplicationHelper.
However, by running spec I found first("meta[property='#{name}']") is always nil.
Is it good to put this kind of spec in spec/features? or spec/requests?
If this is bad, what do you do if you want to match meta og tags?