Created
October 9, 2012 21:33
-
-
Save otaviocardoso/3861599 to your computer and use it in GitHub Desktop.
Workaround para adicionar 'has_{no_}text?' em projeto com capybara 1.1
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
# all code from capybara master | |
module MatchersHelper | |
# Capybara::Helpers | |
def normalize_whitespace(text) | |
text.to_s.gsub(/[\s\u0085\u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]+/, ' ').strip | |
end | |
def to_regexp(text) | |
text.is_a?(Regexp) ? text : Regexp.escape(normalize_whitespace(text)) | |
end | |
# Capybara::Node::Matchers | |
def has_text?(content) | |
unless normalize_whitespace(text).match(to_regexp(content)) | |
raise ExpectationNotMet | |
end | |
return true | |
rescue Capybara::ExpectationNotMet | |
return false | |
end | |
def has_no_text?(content) | |
synchronize do | |
if normalize_whitespace(text).match(to_regexp(content)) | |
raise ExpectationNotMet | |
end | |
end | |
return true | |
rescue Capybara::ExpectationNotMet | |
return false | |
end | |
end |
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
#... | |
RSpec.configure do |config| | |
config.before(:suite) do | |
class Capybara::Session | |
include MatchersHelper | |
end | |
end | |
end | |
#... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment