Created
August 16, 2013 05:28
-
-
Save Lordnibbler/6247531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec::Matchers.define :have_meta do |name, expected| | |
match do |actual| | |
has_css?("meta[name='#{name}'][content='#{expected}']") | |
end | |
failure_message_for_should do |actual| | |
actual = first("meta[name='#{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 | |
end | |
RSpec::Matchers.define :have_title do |expected| | |
match do |actual| | |
has_css?("title", :text => expected) | |
end | |
failure_message_for_should do |actual| | |
actual = first("title") | |
if actual | |
"expected that title would have been '#{expected}' but was '#{actual.text}'" | |
else | |
"expected that title would exist with '#{expected}'" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding my version derived from above:
This allows me to pass regex as well, eg: