Created
December 1, 2012 09:20
-
-
Save certainty/4181253 to your computer and use it in GitHub Desktop.
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
require "spec_helper" | |
module Capybara | |
module Node | |
module Matchers | |
def has_text?(content) | |
normalized_content = normalize_whitespace(content) | |
wait_until do | |
normalize_whitespace(text).include?(normalized_content) or | |
raise ExpectationNotMet | |
end | |
rescue Capybara::ExpectationNotMet | |
return false | |
end | |
def has_no_text?(content) | |
normalized_content = normalize_whitespace(content) | |
wait_until do | |
!normalize_whitespace(text).include?(normalized_content) or | |
raise ExpectationNotMet | |
end | |
rescue Capybara::ExpectationNotMet | |
return false | |
end | |
def normalize_whitespace(text) | |
text.gsub(/\s+/, ' ').strip | |
end | |
alias_method :has_content?, :has_text? | |
alias_method :has_no_content?, :has_no_text? | |
end | |
end | |
end | |
feature 'capybara' do | |
scenario "ignores hidden elements", js: true do | |
visit root_path | |
save_and_open_page | |
expect(page).to_not have_content("i'm hidden") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment