Class: Pact::CSV::Differ
- Inherits:
-
Object
- Object
- Pact::CSV::Differ
- Defined in:
- lib/pact/csv/differ.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #compare(expected, actual, options) ⇒ Object
-
#initialize(expected, actual, options = {}) ⇒ Differ
constructor
A new instance of Differ.
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, = {} @expected = expected @actual = actual @options = puts caller.join("\n") end |
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
8 9 10 |
# File 'lib/pact/csv/differ.rb', line 8 def actual @actual end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
8 9 10 |
# File 'lib/pact/csv/differ.rb', line 8 def expected @expected end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/pact/csv/differ.rb', line 8 def @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, = {} new(expected, actual, ).call end |
Instance Method Details
#call ⇒ Object
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, ) 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, ) expected_table = Cucumber::Ast::Table.new(expected.map(&:to_hash)) actual_table = Cucumber::Ast::Table.new(actual.map(&:to_hash)) errors = [] begin p expected_table.diff!(actual_table, surplus_col: ["allow_unexpected_keys"]) rescue => e errors = [e.table] end errors end |