Skip to content

Instantly share code, notes, and snippets.

@gma
Created November 10, 2012 17:00
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 gma/4051712 to your computer and use it in GitHub Desktop.
Save gma/4051712 to your computer and use it in GitHub Desktop.
module CapybaraAssertions
def css_assertion_builder(outcome, selector, text, message)
if text
options = { :text => text }
message ||= "#{outcome} have found '#{selector}' containing '#{text}'"
else
options = {}
message ||= "#{outcome} have found '#{selector}'"
end
is_present = page.has_css?(selector, options)
case outcome
when 'should'
assert is_present, message
when 'should not'
fail message if is_present
end
end
def assert_has_css(selector, text = nil, message = nil)
css_assertion_builder('should', selector, text, message)
end
def fail_if_has_css(selector, text = nil, message = nil)
css_assertion_builder('should not', selector, text, message)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment