module ActionDispatch::Assertions::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 = "\\.#{jquery_method || '\\w+'}\\("
  pattern = "#{pattern}['\"]#{jquery_opt}['\"],?\\s*" if jquery_opt
  pattern = "#{pattern}#{RJS_PATTERN_HTML}" if block
  pattern = "(?:jQuery|\\$)\\(['\"]#{id}['\"]\\)#{pattern}" if id
  fragments = []
  response.body.scan(Regexp.new(pattern)).each do |match|
    doc = HTML::Document.new(unescape_rjs(match.first))
    doc.root.children.each do |child|
      fragments.push child if child.tag?
    end
  end
  if fragments.empty?
    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