pact 1.3.3 → 1.4.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +16 -1
- data/Gemfile +5 -0
- data/Gemfile.lock +34 -13
- data/README.md +3 -2
- data/example/animal-service/lib/animal_service/api.rb +1 -0
- data/example/zoo-app/lib/zoo_app/animal_service_client.rb +0 -9
- data/example/zoo-app/lib/zoo_app/models/alligator.rb +2 -0
- data/lib/pact.rb +6 -5
- data/lib/pact/cli.rb +0 -26
- data/lib/pact/consumer/configuration.rb +0 -1
- data/lib/pact/consumer/configuration/configuration_extensions.rb +51 -0
- data/lib/pact/consumer/consumer_contract_builder.rb +1 -2
- data/lib/pact/consumer/interaction_builder.rb +2 -4
- data/lib/pact/doc/interaction_view_model.rb +9 -6
- data/lib/pact/doc/sort_interactions.rb +1 -1
- data/lib/pact/provider/rspec.rb +11 -9
- data/lib/pact/version.rb +1 -1
- data/pact.gemspec +5 -0
- data/spec/lib/pact/consumer/interaction_builder_spec.rb +4 -8
- data/spec/support/case-insensitive-response-header-matching.json +21 -0
- data/spec/support/case-insensitive-response-header-matching.rb +15 -0
- data/tasks/pact-test.rake +5 -0
- metadata +42 -122
- data/lib/pact/configuration.rb +0 -195
- data/lib/pact/consumer/app_manager.rb +0 -158
- data/lib/pact/consumer/interactions_filter.rb +0 -48
- data/lib/pact/consumer/mock_service.rb +0 -2
- data/lib/pact/consumer/mock_service/app.rb +0 -82
- data/lib/pact/consumer/mock_service/interaction_delete.rb +0 -33
- data/lib/pact/consumer/mock_service/interaction_list.rb +0 -76
- data/lib/pact/consumer/mock_service/interaction_mismatch.rb +0 -73
- data/lib/pact/consumer/mock_service/interaction_post.rb +0 -31
- data/lib/pact/consumer/mock_service/interaction_replay.rb +0 -139
- data/lib/pact/consumer/mock_service/log_get.rb +0 -28
- data/lib/pact/consumer/mock_service/missing_interactions_get.rb +0 -30
- data/lib/pact/consumer/mock_service/mock_service_administration_endpoint.rb +0 -31
- data/lib/pact/consumer/mock_service/pact_post.rb +0 -33
- data/lib/pact/consumer/mock_service/rack_request_helper.rb +0 -51
- data/lib/pact/consumer/mock_service/verification_get.rb +0 -68
- data/lib/pact/consumer/mock_service_client.rb +0 -65
- data/lib/pact/consumer/mock_service_interaction_expectation.rb +0 -37
- data/lib/pact/consumer/request.rb +0 -27
- data/lib/pact/consumer/server.rb +0 -90
- data/lib/pact/consumer_contract.rb +0 -1
- data/lib/pact/consumer_contract/consumer_contract.rb +0 -115
- data/lib/pact/consumer_contract/consumer_contract_writer.rb +0 -84
- data/lib/pact/consumer_contract/file_name.rb +0 -19
- data/lib/pact/consumer_contract/headers.rb +0 -51
- data/lib/pact/consumer_contract/interaction.rb +0 -67
- data/lib/pact/consumer_contract/pact_file.rb +0 -24
- data/lib/pact/consumer_contract/request.rb +0 -73
- data/lib/pact/consumer_contract/service_consumer.rb +0 -28
- data/lib/pact/consumer_contract/service_provider.rb +0 -28
- data/lib/pact/logging.rb +0 -14
- data/lib/pact/matchers.rb +0 -1
- data/lib/pact/matchers/actual_type.rb +0 -16
- data/lib/pact/matchers/base_difference.rb +0 -37
- data/lib/pact/matchers/differ.rb +0 -153
- data/lib/pact/matchers/difference.rb +0 -13
- data/lib/pact/matchers/difference_indicator.rb +0 -26
- data/lib/pact/matchers/embedded_diff_formatter.rb +0 -62
- data/lib/pact/matchers/expected_type.rb +0 -35
- data/lib/pact/matchers/index_not_found.rb +0 -15
- data/lib/pact/matchers/list_diff_formatter.rb +0 -101
- data/lib/pact/matchers/matchers.rb +0 -139
- data/lib/pact/matchers/no_diff_indicator.rb +0 -18
- data/lib/pact/matchers/regexp_difference.rb +0 -13
- data/lib/pact/matchers/type_difference.rb +0 -16
- data/lib/pact/matchers/unexpected_index.rb +0 -11
- data/lib/pact/matchers/unexpected_key.rb +0 -11
- data/lib/pact/matchers/unix_diff_formatter.rb +0 -114
- data/lib/pact/reification.rb +0 -28
- data/lib/pact/rspec.rb +0 -53
- data/lib/pact/shared/active_support_support.rb +0 -51
- data/lib/pact/shared/dsl.rb +0 -76
- data/lib/pact/shared/jruby_support.rb +0 -18
- data/lib/pact/shared/json_differ.rb +0 -15
- data/lib/pact/shared/key_not_found.rb +0 -15
- data/lib/pact/shared/null_expectation.rb +0 -31
- data/lib/pact/shared/request.rb +0 -80
- data/lib/pact/shared/text_differ.rb +0 -14
- data/lib/pact/something_like.rb +0 -49
- data/lib/pact/symbolize_keys.rb +0 -12
- data/lib/pact/term.rb +0 -85
- data/spec/lib/pact/consumer/request_spec.rb +0 -24
- data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +0 -58
- data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -180
- data/spec/lib/pact/consumer_contract/headers_spec.rb +0 -107
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -107
- data/spec/lib/pact/consumer_contract/request_spec.rb +0 -329
- data/spec/lib/pact/matchers/differ_spec.rb +0 -214
- data/spec/lib/pact/matchers/difference_spec.rb +0 -22
- data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +0 -90
- data/spec/lib/pact/matchers/index_not_found_spec.rb +0 -21
- data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +0 -114
- data/spec/lib/pact/matchers/matchers_spec.rb +0 -500
- data/spec/lib/pact/matchers/regexp_difference_spec.rb +0 -20
- data/spec/lib/pact/matchers/type_difference_spec.rb +0 -34
- data/spec/lib/pact/matchers/unexpected_index_spec.rb +0 -20
- data/spec/lib/pact/matchers/unexpected_key_spec.rb +0 -20
- data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +0 -216
- data/spec/lib/pact/reification_spec.rb +0 -67
- data/spec/lib/pact/shared/dsl_spec.rb +0 -86
- data/spec/lib/pact/shared/json_differ_spec.rb +0 -36
- data/spec/lib/pact/shared/key_not_found_spec.rb +0 -20
- data/spec/lib/pact/shared/request_spec.rb +0 -111
- data/spec/lib/pact/shared/text_differ_spec.rb +0 -54
- data/spec/lib/pact/something_like_spec.rb +0 -21
- data/spec/lib/pact/term_spec.rb +0 -89
- data/spec/support/dsl_spec_support.rb +0 -7
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'pact/matchers/difference_indicator'
|
|
2
|
-
|
|
3
|
-
module Pact
|
|
4
|
-
class ExpectedType < Pact::DifferenceIndicator
|
|
5
|
-
|
|
6
|
-
def initialize value
|
|
7
|
-
@value = value
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def type
|
|
11
|
-
@value.class.name
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def to_json options = {}
|
|
15
|
-
type
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def as_json options = {}
|
|
19
|
-
type
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def eq? other
|
|
23
|
-
self.class == other.class && other.type == type
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def == other
|
|
27
|
-
eq? other
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def to_s
|
|
31
|
-
type
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
end
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
module Pact
|
|
2
|
-
module Matchers
|
|
3
|
-
class ListDiffFormatter
|
|
4
|
-
|
|
5
|
-
attr_reader :diff
|
|
6
|
-
|
|
7
|
-
def initialize diff, options = {}
|
|
8
|
-
@diff = diff
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def self.call diff, options = {}
|
|
12
|
-
new(diff, options).call
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def to_hash
|
|
16
|
-
diff
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def call
|
|
20
|
-
to_s
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def to_s
|
|
24
|
-
diff_descriptions(diff).join("\n")
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def diff_descriptions obj, path = [], descriptions = []
|
|
28
|
-
case obj
|
|
29
|
-
when Hash then handle_hash obj, path, descriptions
|
|
30
|
-
when Array then handle_array obj, path, descriptions
|
|
31
|
-
when Difference then handle_difference obj, path, descriptions
|
|
32
|
-
when TypeDifference then handle_mismatched_type obj, path, descriptions
|
|
33
|
-
when RegexpDifference then handle_mismatched_regexp obj, path, descriptions
|
|
34
|
-
when NoDiffIndicator then nil
|
|
35
|
-
else
|
|
36
|
-
raise "Invalid diff, expected Hash, Array, NoDiffIndicator or Difference, found #{obj.class}"
|
|
37
|
-
end
|
|
38
|
-
descriptions
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def handle_hash hash, path, descriptions
|
|
42
|
-
hash.each_pair do | key, value |
|
|
43
|
-
diff_descriptions value, path + [key.inspect], descriptions
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def handle_array array, path, descriptions
|
|
48
|
-
array.each_with_index do | obj, index |
|
|
49
|
-
diff_descriptions obj, path + [index], descriptions
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def handle_difference difference, path, descriptions
|
|
54
|
-
case difference.expected
|
|
55
|
-
when Pact::UnexpectedKey then handle_unexpected_key(difference, path, descriptions)
|
|
56
|
-
when Pact::UnexpectedIndex then handle_unexpected_index(difference, path, descriptions)
|
|
57
|
-
else
|
|
58
|
-
case difference.actual
|
|
59
|
-
when Pact::KeyNotFound then handle_key_not_found(difference, path, descriptions)
|
|
60
|
-
when Pact::IndexNotFound then handle_index_not_found(difference, path, descriptions)
|
|
61
|
-
else
|
|
62
|
-
handle_mismatched_value(difference, path, descriptions)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def handle_unexpected_index difference, path, descriptions
|
|
68
|
-
descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tArray contained unexpected item:\n\t\t#{difference.actual.ai}"
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def handle_mismatched_value difference, path, descriptions
|
|
72
|
-
descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tExpected:\n\t\t#{difference.expected.ai}\n\tActual:\n\t\t#{difference.actual.ai}"
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def handle_mismatched_regexp difference, path, descriptions
|
|
76
|
-
descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tExpected to match:\n\t\t#{difference.expected.inspect}\n\tActual:\n\t\t#{difference.actual.ai}"
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def handle_mismatched_type difference, path, descriptions
|
|
80
|
-
descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tExpected type:\n\t\t#{difference.expected}\n\tActual type:\n\t\t#{difference.actual}"
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def handle_index_not_found difference, path, descriptions
|
|
84
|
-
descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tMissing index with value:\n\t\t#{difference.expected.ai}"
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def handle_key_not_found difference, path, descriptions
|
|
88
|
-
descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tMissing key with value:\n\t\t#{difference.expected.ai}"
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def handle_unexpected_key difference, path, descriptions
|
|
92
|
-
descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tHash contained unexpected key with value:\n\t\t#{difference.actual.ai}"
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def path_to_s path
|
|
96
|
-
"[" + path.join("][") + "]"
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
require 'awesome_print'
|
|
2
|
-
require 'pact/term'
|
|
3
|
-
require 'pact/something_like'
|
|
4
|
-
require 'pact/shared/null_expectation'
|
|
5
|
-
require 'pact/shared/key_not_found'
|
|
6
|
-
require 'pact/matchers/unexpected_key'
|
|
7
|
-
require 'pact/matchers/unexpected_index'
|
|
8
|
-
require 'pact/matchers/index_not_found'
|
|
9
|
-
require 'pact/matchers/difference'
|
|
10
|
-
require 'pact/matchers/regexp_difference'
|
|
11
|
-
require 'pact/matchers/type_difference'
|
|
12
|
-
require 'pact/matchers/expected_type'
|
|
13
|
-
require 'pact/matchers/actual_type'
|
|
14
|
-
require 'pact/matchers/no_diff_indicator'
|
|
15
|
-
|
|
16
|
-
module Pact
|
|
17
|
-
module Matchers
|
|
18
|
-
|
|
19
|
-
NO_DIFF_INDICATOR = NoDiffIndicator.new
|
|
20
|
-
DEFAULT_OPTIONS = {allow_unexpected_keys: true, type: false}.freeze
|
|
21
|
-
|
|
22
|
-
def diff expected, actual, opts = {}
|
|
23
|
-
calculate_diff(Pact::Term.unpack_regexps(expected), actual, DEFAULT_OPTIONS.merge(opts))
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def type_diff expected, actual, opts = {}
|
|
27
|
-
calculate_diff Pact::Term.unpack_regexps(expected), actual, DEFAULT_OPTIONS.merge(opts).merge(type: true)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
def calculate_diff expected, actual, opts = {}
|
|
33
|
-
options = DEFAULT_OPTIONS.merge(opts)
|
|
34
|
-
case expected
|
|
35
|
-
when Hash then hash_diff(expected, actual, options)
|
|
36
|
-
when Array then array_diff(expected, actual, options)
|
|
37
|
-
when Regexp then regexp_diff(expected, actual, options)
|
|
38
|
-
when Pact::SomethingLike then calculate_diff(expected.contents, actual, options.merge(:type => true))
|
|
39
|
-
else object_diff(expected, actual, options)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
alias_method :structure_diff, :type_diff # Backwards compatibility
|
|
44
|
-
|
|
45
|
-
def regexp_diff regexp, actual, options
|
|
46
|
-
if actual.is_a?(String) && regexp.match(actual)
|
|
47
|
-
{}
|
|
48
|
-
else
|
|
49
|
-
RegexpDifference.new regexp, actual
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def array_diff expected, actual, options
|
|
54
|
-
if actual.is_a? Array
|
|
55
|
-
actual_array_diff expected, actual, options
|
|
56
|
-
else
|
|
57
|
-
Difference.new expected, actual
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def actual_array_diff expected, actual, options
|
|
62
|
-
difference = []
|
|
63
|
-
diff_found = false
|
|
64
|
-
length = [expected.length, actual.length].max
|
|
65
|
-
length.times do | index|
|
|
66
|
-
expected_item = expected.fetch(index, Pact::UnexpectedIndex.new)
|
|
67
|
-
actual_item = actual.fetch(index, Pact::IndexNotFound.new)
|
|
68
|
-
if (item_diff = calculate_diff(expected_item, actual_item, options)).any?
|
|
69
|
-
diff_found = true
|
|
70
|
-
difference << item_diff
|
|
71
|
-
else
|
|
72
|
-
difference << NO_DIFF_INDICATOR
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
diff_found ? difference : {}
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def actual_hash_diff expected, actual, options
|
|
79
|
-
difference = expected.keys.inject({}) do |calculate_diff, key|
|
|
80
|
-
if (diff_at_key = calculate_diff(expected[key], actual.fetch(key, Pact::KeyNotFound.new), options)).any?
|
|
81
|
-
calculate_diff[key] = diff_at_key
|
|
82
|
-
end
|
|
83
|
-
calculate_diff
|
|
84
|
-
end
|
|
85
|
-
difference.merge(check_for_unexpected_keys(expected, actual, options))
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def check_for_unexpected_keys expected, actual, options
|
|
89
|
-
if options[:allow_unexpected_keys]
|
|
90
|
-
{}
|
|
91
|
-
else
|
|
92
|
-
(actual.keys - expected.keys).inject({}) do | calculate_diff, key |
|
|
93
|
-
calculate_diff[key] = Difference.new(UnexpectedKey.new, actual[key])
|
|
94
|
-
calculate_diff
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def hash_diff expected, actual, options
|
|
100
|
-
if actual.is_a? Hash
|
|
101
|
-
actual_hash_diff expected, actual, options
|
|
102
|
-
else
|
|
103
|
-
Difference.new expected, actual
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def type_difference expected, actual
|
|
108
|
-
if types_match? expected, actual
|
|
109
|
-
{}
|
|
110
|
-
else
|
|
111
|
-
TypeDifference.new type_diff_expected_display(expected), type_diff_actual_display(actual)
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def type_diff_actual_display actual
|
|
116
|
-
actual.is_a?(KeyNotFound) ? actual : ActualType.new(actual)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def type_diff_expected_display expected
|
|
120
|
-
ExpectedType.new(expected)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def types_match? expected, actual
|
|
124
|
-
#There must be a more elegant way to do this
|
|
125
|
-
expected.class == actual.class ||
|
|
126
|
-
(expected.is_a?(TrueClass) && actual.is_a?(FalseClass)) ||
|
|
127
|
-
(expected.is_a?(FalseClass) && actual.is_a?(TrueClass))
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def object_diff expected, actual, options
|
|
131
|
-
return type_difference(expected, actual) if options[:type]
|
|
132
|
-
if expected != actual
|
|
133
|
-
Difference.new expected, actual
|
|
134
|
-
else
|
|
135
|
-
{}
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require 'pact/matchers/base_difference'
|
|
2
|
-
|
|
3
|
-
module Pact
|
|
4
|
-
module Matchers
|
|
5
|
-
class TypeDifference < BaseDifference
|
|
6
|
-
|
|
7
|
-
def as_json options = {}
|
|
8
|
-
if KeyNotFound === actual
|
|
9
|
-
{:EXPECTED_TYPE => expected.as_json, :ACTUAL => actual.as_json }
|
|
10
|
-
else
|
|
11
|
-
{:EXPECTED_TYPE => expected.as_json, :ACTUAL_TYPE => actual.as_json }
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
require 'pact/shared/jruby_support'
|
|
2
|
-
require 'pact/matchers/differ'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
module Matchers
|
|
6
|
-
|
|
7
|
-
class UnixDiffFormatter
|
|
8
|
-
|
|
9
|
-
include JRubySupport
|
|
10
|
-
|
|
11
|
-
def initialize diff, options = {}
|
|
12
|
-
@diff = diff
|
|
13
|
-
@colour = options.fetch(:colour, false)
|
|
14
|
-
@differ = Pact::Matchers::Differ.new(@colour)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def self.call diff, options = {colour: Pact.configuration.color_enabled}
|
|
18
|
-
new(diff, options).call
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def call
|
|
22
|
-
to_s
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def to_s
|
|
26
|
-
expected = generate_string(diff, :expected)
|
|
27
|
-
actual = generate_string(diff, :actual)
|
|
28
|
-
@differ.diff_as_string(actual, expected).lstrip + "\n" + key
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
def handle thing, target
|
|
34
|
-
case thing
|
|
35
|
-
when Hash then copy_hash(thing, target)
|
|
36
|
-
when Array then copy_array(thing, target)
|
|
37
|
-
when Difference then copy_diff(thing, target)
|
|
38
|
-
when TypeDifference then copy_diff(thing, target)
|
|
39
|
-
when RegexpDifference then copy_diff(thing, target)
|
|
40
|
-
when NoDiffIndicator then copy_no_diff(thing, target)
|
|
41
|
-
else copy_object(thing, target)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def generate_string diff, target
|
|
46
|
-
comparable = handle(diff, target)
|
|
47
|
-
begin
|
|
48
|
-
# Can't think of an elegant way to check if we can pretty generate other than to try it and maybe fail
|
|
49
|
-
fix_blank_lines_in_empty_hashes JSON.pretty_generate(comparable)
|
|
50
|
-
rescue JSON::GeneratorError
|
|
51
|
-
comparable.to_s
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def copy_hash hash, target
|
|
56
|
-
hash.keys.each_with_object({}) do | key, new_hash |
|
|
57
|
-
value = handle hash[key], target
|
|
58
|
-
new_hash[key] = value unless (KeyNotFound === value || UnexpectedKey === value)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def copy_array array, target
|
|
63
|
-
array.each_index.each_with_object([]) do | index, new_array |
|
|
64
|
-
value = handle array[index], target
|
|
65
|
-
new_array[index] = value unless (UnexpectedIndex === value || IndexNotFound === value)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def copy_no_diff(thing, target)
|
|
70
|
-
thing
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def copy_diff difference, target
|
|
74
|
-
if target == :actual
|
|
75
|
-
handle difference.actual, target
|
|
76
|
-
else
|
|
77
|
-
handle difference.expected, target
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def copy_object object, target
|
|
82
|
-
if Regexp === object
|
|
83
|
-
RegexpDecorator.new(object)
|
|
84
|
-
else
|
|
85
|
-
object
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def key
|
|
90
|
-
"Key: " + @differ.red("-") + @differ.red(" means \"expected, but was not found\". \n") +
|
|
91
|
-
@differ.green(" +") + @differ.green(" means \"actual, should not be found\". \n") +
|
|
92
|
-
" Values where the expected matches the actual are not shown.\n"
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
class RegexpDecorator
|
|
96
|
-
|
|
97
|
-
def initialize regexp
|
|
98
|
-
@regexp = regexp
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def to_json options={}
|
|
102
|
-
@regexp.inspect
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def as_json
|
|
106
|
-
@regexp.inspect
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
attr_reader :diff
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
end
|
|
114
|
-
end
|