module Jquery::Rails::SelectorAssertions
def assert_select_jquery(*args, &block)
def assert_select_jquery(*args, &block) jquery_method = args.first.is_a?(Symbol) ? args.shift : nil jquery_opt = args.first.is_a?(Symbol) ? args.shift : nil id = args.first.is_a?(String) ? args.shift : nil pattern = "\\s*\\.#{jquery_method || '\\w+'}\\(" pattern = "#{pattern}['\"]#{jquery_opt}['\"],?\\s*" if jquery_opt pattern = "#{pattern}#{PATTERN_HTML}" pattern = "(?:jQuery|\\$)\\(['\"]#{id}['\"]\\)#{pattern}" if id fragments = Nokogiri::HTML::Document.new response.body.scan(Regexp.new(pattern)).each do |match| doc = Nokogiri::HTML::Document.parse(unescape_js(match.first)) doc.root.children.each do |child| fragments << child if child.element? end end unless fragments.children.any? { |child| child.element? } opts = [jquery_method, jquery_opt, id].compact flunk "No JQuery call matches #{opts.inspect}" end if block begin in_scope, @selected = @selected, fragments yield ensure @selected = in_scope end end end
def unescape_js(js_string)
def unescape_js(js_string) # js encodes double quotes and line breaks. unescaped= js_string.gsub('\"', '"') unescaped.gsub!('\\\'', "'") unescaped.gsub!(/\\\//, '/') unescaped.gsub!('\n', "\n") unescaped.gsub!('\076', '>') unescaped.gsub!('\074', '<') # js encodes non-ascii characters. unescaped.gsub!(PATTERN_UNICODE_ESCAPED_CHAR) {|u| [$1.hex].pack('U*')} unescaped end