Forked from yosemsweet/rspec_custom_matcher_capybara.rb
Created
November 28, 2011 08:12
-
-
Save tyok/1399571 to your computer and use it in GitHub Desktop.
Capybara matchers in RSpec custom matcher
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_widget_elements_for do |widget| | |
match do |actual| | |
puts actual.to_yaml | |
@errors = {} | |
expected_elements = { | |
:widget => ".widget", | |
:content_type => ".#{widget.content_type}", | |
:body => ".body", | |
:title => ".title", | |
:comment_count => ".comment_count", | |
:toggle_facebook_comments => "a.toggle_facebook_comments[href='#']", | |
:toolbox => ".toolbox", | |
:content => ".content", | |
:tags => ".tags" | |
} | |
error_prefix = "Can't find selector " | |
expected_elements.each do |key, selector| | |
puts have_selector(selector).inspect | |
@errors[key] = error_prefix + selector unless have_selector(selector).matches?(actual) | |
end | |
@errors.empty? | |
end | |
failure_message_for_should do |actual| | |
message = "expected #{actual} to have widget elements" | |
message += "\n#{@errors.to_yaml}" unless @errors.empty? | |
message | |
end | |
failure_message_for_should_not do |actual| | |
message = "expected #{actual} to not have widget elements" | |
message += "\n#{@errors.to_yaml}" unless @errors.empty? | |
message | |
end | |
description do | |
message = "has widget elements for #{widget}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment