Skip to content

Instantly share code, notes, and snippets.

@certainty
Created December 1, 2012 09:20
Show Gist options
  • Save certainty/4181253 to your computer and use it in GitHub Desktop.
Save certainty/4181253 to your computer and use it in GitHub Desktop.
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