Class: Pact::CSV::Differ

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/csv/differ.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected, actual, options = {}) ⇒ Differ

Returns a new instance of Differ.



9
10
11
12
13
14
# File 'lib/pact/csv/differ.rb', line 9

def initialize expected, actual, options = {}
  @expected = expected
  @actual = actual
  @options = options
  puts caller.join("\n")
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



8
9
10
# File 'lib/pact/csv/differ.rb', line 8

def actual
  @actual
end

#expectedObject (readonly)

Returns the value of attribute expected.



8
9
10
# File 'lib/pact/csv/differ.rb', line 8

def expected
  @expected
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/pact/csv/differ.rb', line 8

def options
  @options
end

Class Method Details

.call(expected, actual, options = {}) ⇒ Object



16
17
18
# File 'lib/pact/csv/differ.rb', line 16

def self.call expected, actual, options = {}
  new(expected, actual, options).call
end

Instance Method Details

#callObject



20
21
22
23
24
# File 'lib/pact/csv/differ.rb', line 20

def call
  expected_data = ::CSV.parse(expected, headers: true)
  actual_data = ::CSV.parse(actual, headers: true)
  compare(expected_data, actual_data, options)
end

#compare(expected, actual, options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pact/csv/differ.rb', line 25

def compare(expected, actual, options)
  expected_table = Cucumber::Ast::Table.new(expected.map(&:to_hash))
  actual_table = Cucumber::Ast::Table.new(actual.map(&:to_hash))
  errors = []
  begin
    p options
    expected_table.diff!(actual_table, surplus_col: options["allow_unexpected_keys"])
  rescue => e
    errors = [e.table]
  end
  errors
end