Skip to content

Instantly share code, notes, and snippets.

@agenteo
Created May 14, 2010 06:27
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 agenteo/400879 to your computer and use it in GitHub Desktop.
Save agenteo/400879 to your computer and use it in GitHub Desktop.
helpers for capybara
module VerboseExpectationsHelpers
def expect_page_has(path, options={})
@path, @options = path, options
raise Capybara::ElementNotFound, text_found_instead if !page.has_css?(@path, @options)
end
def expect_page_count(path, options={})
@path, @options = path, options
raise Capybara::ElementNotFound, total_found_instead if !page.has_css?(@path, @options)
end
private
def text_found_instead
insted_found = locate(@path)
"Expecting #{@options[:text]} instead I've found #{insted_found.text}"
end
def total_found_instead
r = all(:xpath, Capybara::XPath.from_css(@path), @options)
matches = r.size
%{Expecting #{@options[:count]} matching "#{@path}", found #{matches}.}
end
end
World(VerboseExpectationsHelpers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment