Hi I wanna match meta og tags. So I modify a bit the matcher from 
spree/spree <https://github.com/spree/spree>'s 
capybara_ext.rb<https://github.com/spree/spree/blob/master/core/lib/spree/testing_support/capybara_ext.rb#L110>
.

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
  endend

I 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)
  endend

page_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?

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/818fb75c-f2c8-49f9-99fc-5f6142df2663%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to