Sha256: 6ddf737a2ae0cb7348630587a0fe876ad4b984bf12a3be483a4c0d32de3f16f7
Contents?: true
Size: 1.51 KB
Versions: 1
Compression:
Stored size: 1.51 KB
Contents
module Richard class CurlReply attr_reader :missing, :surplus def initialize(text) @text = text @missing = @surplus = [] @pretty = false end def use_pretty_xml @pretty = true; end def matches?(expected) actual_lines = strip(@text) expected_lines = parse(expected) matches = actual_lines.select do |line| expected_lines.any?{|it| it.matches?(line)} end expectations_that_did_not_match_anything = expected_lines.select do |expected| actual_lines.none?{|line| expected.matches?(line)} end @missing = expectations_that_did_not_match_anything.map(&:text) @surplus = actual_lines - matches return matches.size.eql? expected_lines.size end def eql?(text) strip(@text).eql? strip(text) end def equals?(text); self.eql? text; end def ==(text); self.eql? text; end def to_s; @text; end def inspect; to_s; end private def parse(text) convert_all strip(text) end def strip(text) format(text).map(&:chomp).map(&:strip) end def format(text) return text.lines unless @pretty lines = text.lines body = lines.delete_at(lines.size-1) lines += Richard::Internal::XmlFormat.pretty(body) lines end def convert_all(lines=[]) lines.map do |text| text.start_with?("/") ? Richard::Internal::PatternLine.new(text) : Richard::Internal::TextLine.new(text) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
richard_iii-0.1.0 | lib/richard_iii/curl_reply.rb |