class RSpecHtmlMatchers::HaveTag

def matches? src, &block

def matches? src, &block
  @block = block if block
  src = src.html if defined?(Capybara::Session) && src.is_a?(Capybara::Session)
  case src
  when String
    parent_scope = Nokogiri::HTML(src)
    @document    = src
  else
    parent_scope  = src.current_scope
    @document     = parent_scope.to_html
  end
  @current_scope = begin
                     parent_scope.css(tag)
                     # on jruby this produce exception if css was not found:
                     # undefined method `decorate' for nil:NilClass
                   rescue NoMethodError
                     Nokogiri::XML::NodeSet.new(Nokogiri::XML::Document.new)
                   end
  if tag_presents? && proper_content? && count_right?
    @block.call(self) if @block
    true
  else
    false
  end
end