Created
March 28, 2011 20:58
-
-
Save zspencer/891270 to your computer and use it in GitHub Desktop.
Hacky way to assert against the background color of an element
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
class BeStyledWithMatcher | |
def self.match(element, expected_color, browser) | |
element_class = element.instance_variable_get(:@selector)[:class].to_s | |
element_class.chomp!(")") | |
element_class = element_class[7, element_class.length] | |
color=browser.execute_script("return $('.#{element_class}').css('background-color')") | |
puts color | |
expected_color == color | |
end | |
end | |
RSpec::Matchers.define :have_background_color do |expected_color, browser | | |
match do | element | | |
BeStyledWithMatcher.match(element, expected_color, browser) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment