Class: Pact::Matchers::UnixDiffFormatter
- Inherits:
-
Object
- Object
- Pact::Matchers::UnixDiffFormatter
- Includes:
- JRubySupport
- Defined in:
- lib/pact/matchers/unix_diff_formatter.rb
Defined Under Namespace
Classes: NoDifferenceDecorator, RegexpDecorator
Constant Summary collapse
- MESSAGES_TITLE =
"\n\nDescription of differences\n--------------------------------------"
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(diff, options = {}) ⇒ UnixDiffFormatter
constructor
A new instance of UnixDiffFormatter.
- #to_s ⇒ Object
Methods included from JRubySupport
#add_blank_lines_in_empty_arrays, #add_blank_lines_in_empty_hashes, #fix_blank_lines_in_empty_hashes
Constructor Details
#initialize(diff, options = {}) ⇒ UnixDiffFormatter
Returns a new instance of UnixDiffFormatter.
14 15 16 17 18 19 20 21 |
# File 'lib/pact/matchers/unix_diff_formatter.rb', line 14 def initialize diff, = {} @diff = diff @colour = .fetch(:colour, false) @actual = .fetch(:actual, {}) @include_explanation = .fetch(:include_explanation, true) @differ = Pact::Matchers::Differ.new(@colour) @messages = Pact::Matchers::ExtractDiffMessages.call(diff).collect{ | | "* #{}" }.join("\n") end |
Class Method Details
.call(diff, options = {}) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/pact/matchers/unix_diff_formatter.rb', line 23 def self.call diff, = {} # require stops circular dependency from pact/configuration <-> pact/matchers/unix_diff_formatter require 'pact/configuration' = {colour: Pact.configuration.color_enabled} new(diff, .merge()).call end |
Instance Method Details
#call ⇒ Object
30 31 32 |
# File 'lib/pact/matchers/unix_diff_formatter.rb', line 30 def call to_s end |
#to_s ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pact/matchers/unix_diff_formatter.rb', line 34 def to_s expected = generate_string(diff, :expected) actual = generate_string(diff, :actual) suffix = @include_explanation ? key + "\n" : '' = @include_explanation ? "#{MESSAGES_TITLE}\n#{@messages}\n" : '' string_diff = @differ.diff_as_string(actual, expected).lstrip string_diff = remove_first_line(string_diff) string_diff = remove_comma_from_end_of_arrays(string_diff) suffix + string_diff + end |