Skip to content

Instantly share code, notes, and snippets.

@zspencer
Created March 28, 2011 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zspencer/891270 to your computer and use it in GitHub Desktop.
Save zspencer/891270 to your computer and use it in GitHub Desktop.
Hacky way to assert against the background color of an element
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