Created
May 14, 2010 06:27
-
-
Save agenteo/400879 to your computer and use it in GitHub Desktop.
helpers for capybara
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
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