pact 1.3.3 → 1.4.0
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 +37 -1
- data/lib/pact/cli.rb +0 -26
- data/lib/pact/consumer/configuration/configuration_extensions.rb +51 -0
- data/lib/pact/consumer/configuration/mock_service.rb +2 -1
- data/lib/pact/consumer/configuration.rb +0 -1
- data/lib/pact/consumer/consumer_contract_builder.rb +3 -3
- data/lib/pact/consumer/interaction_builder.rb +3 -5
- data/lib/pact/doc/interaction_view_model.rb +9 -6
- data/lib/pact/doc/sort_interactions.rb +1 -1
- data/lib/pact/provider/configuration/configuration_extension.rb +0 -9
- data/lib/pact/provider/rspec.rb +11 -9
- data/lib/pact/version.rb +1 -1
- data/lib/pact.rb +6 -5
- data/pact.gemspec +6 -2
- metadata +57 -304
- data/.gitignore +0 -29
- data/.rspec +0 -2
- data/.ruby-version +0 -1
- data/.travis.yml +0 -8
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -86
- data/README.md +0 -313
- data/Rakefile +0 -9
- data/config.ru +0 -3
- data/documentation/README.md +0 -13
- data/documentation/configuration.md +0 -166
- data/documentation/diff_formatter_embedded.png +0 -0
- data/documentation/diff_formatter_list.png +0 -0
- data/documentation/diff_formatter_unix.png +0 -0
- data/example/animal-service/Gemfile +0 -14
- data/example/animal-service/Gemfile.lock +0 -69
- data/example/animal-service/Rakefile +0 -5
- data/example/animal-service/config.ru +0 -3
- data/example/animal-service/db/animal_db.sqlite3 +0 -0
- data/example/animal-service/lib/animal_service/animal_repository.rb +0 -12
- data/example/animal-service/lib/animal_service/api.rb +0 -28
- data/example/animal-service/lib/animal_service/db.rb +0 -5
- data/example/animal-service/spec/service_consumers/pact_helper.rb +0 -11
- data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +0 -26
- data/example/zoo-app/Gemfile +0 -12
- data/example/zoo-app/Gemfile.lock +0 -63
- data/example/zoo-app/Rakefile +0 -5
- data/example/zoo-app/doc/pacts/markdown/README.md +0 -3
- data/example/zoo-app/doc/pacts/markdown/Zoo App - Animal Service.md +0 -75
- data/example/zoo-app/lib/zoo_app/animal_service_client.rb +0 -40
- data/example/zoo-app/lib/zoo_app/models/alligator.rb +0 -15
- data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +0 -67
- data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +0 -71
- data/example/zoo-app/spec/service_providers/pact_helper.rb +0 -15
- data/example/zoo-app/spec/spec_helper.rb +0 -6
- 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/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.rb +0 -2
- 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/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/consumer_contract.rb +0 -1
- data/lib/pact/logging.rb +0 -14
- 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/matchers.rb +0 -1
- 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/scratchpad.rb +0 -52
- data/spec/features/consumption_spec.rb +0 -114
- data/spec/features/production_spec.rb +0 -155
- data/spec/features/provider_states/zebras.rb +0 -28
- data/spec/integration/consumer_spec.rb +0 -212
- data/spec/integration/pact/consumer_configuration_spec.rb +0 -66
- data/spec/integration/pact/provider_configuration_spec.rb +0 -25
- data/spec/lib/pact/cli_spec.rb +0 -47
- data/spec/lib/pact/configuration_spec.rb +0 -297
- data/spec/lib/pact/consumer/app_manager_spec.rb +0 -41
- data/spec/lib/pact/consumer/configuration_spec.rb +0 -57
- data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +0 -69
- data/spec/lib/pact/consumer/interaction_builder_spec.rb +0 -91
- data/spec/lib/pact/consumer/interactions_spec.rb +0 -64
- data/spec/lib/pact/consumer/mock_service/app_spec.rb +0 -52
- data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +0 -78
- data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +0 -70
- data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +0 -12
- data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +0 -88
- data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +0 -142
- data/spec/lib/pact/consumer/mock_service_client_spec.rb +0 -88
- data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +0 -54
- data/spec/lib/pact/consumer/request_spec.rb +0 -24
- data/spec/lib/pact/consumer/service_consumer_spec.rb +0 -11
- 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/consumer_contract_writer_spec.rb +0 -111
- 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/doc/generator_spec.rb +0 -84
- data/spec/lib/pact/doc/interaction_view_model_spec.rb +0 -132
- data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +0 -29
- data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +0 -29
- 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/provider/configuration/configuration_extension_spec.rb +0 -30
- data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +0 -43
- data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +0 -21
- data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +0 -108
- data/spec/lib/pact/provider/configuration_spec.rb +0 -50
- data/spec/lib/pact/provider/matchers/messages_spec.rb +0 -116
- data/spec/lib/pact/provider/pact_helper_locator_spec.rb +0 -54
- data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +0 -19
- data/spec/lib/pact/provider/request_spec.rb +0 -78
- data/spec/lib/pact/provider/rspec/formatter_rspec_2_spec.rb +0 -68
- data/spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb +0 -72
- data/spec/lib/pact/provider/rspec_spec.rb +0 -55
- data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +0 -89
- data/spec/lib/pact/provider/state/provider_state_proxy_spec.rb +0 -80
- data/spec/lib/pact/provider/state/provider_state_spec.rb +0 -213
- data/spec/lib/pact/provider/world_spec.rb +0 -41
- 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/tasks/task_helper_spec.rb +0 -74
- data/spec/lib/pact/tasks/verification_task_spec.rb +0 -75
- data/spec/lib/pact/term_spec.rb +0 -89
- data/spec/pact_specification/compliance-1.0.0.rb +0 -47
- data/spec/spec_helper.rb +0 -22
- data/spec/standalone/consumer_fail_test.rb +0 -55
- data/spec/standalone/consumer_pass_test.rb +0 -51
- data/spec/support/a_consumer-a_producer.json +0 -32
- data/spec/support/a_consumer-a_provider.json +0 -32
- data/spec/support/active_support_if_configured.rb +0 -6
- data/spec/support/app_for_config_ru.rb +0 -4
- data/spec/support/consumer_contract_template.json +0 -24
- data/spec/support/dsl_spec_support.rb +0 -7
- data/spec/support/factories.rb +0 -82
- data/spec/support/generated_index.md +0 -4
- data/spec/support/generated_markdown.md +0 -55
- data/spec/support/interaction_view_model.json +0 -63
- data/spec/support/interaction_view_model_with_terms.json +0 -50
- data/spec/support/markdown_pact.json +0 -48
- data/spec/support/missing_provider_states_output.txt +0 -25
- data/spec/support/options.json +0 -21
- data/spec/support/options_app.rb +0 -15
- data/spec/support/pact_helper.rb +0 -57
- data/spec/support/shared_examples_for_request.rb +0 -94
- data/spec/support/spec_support.rb +0 -20
- data/spec/support/stubbing.json +0 -22
- data/spec/support/stubbing_using_allow.rb +0 -29
- data/spec/support/term.json +0 -48
- data/spec/support/test_app_fail.json +0 -61
- data/spec/support/test_app_pass.json +0 -38
- data/spec/support/test_app_with_right_content_type_differ.json +0 -23
- data/tasks/pact-test.rake +0 -109
- data/tasks/spec.rake +0 -8
|
@@ -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
|
data/lib/pact/matchers.rb
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require_relative 'matchers/matchers'
|
data/lib/pact/reification.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'randexp'
|
|
2
|
-
|
|
3
|
-
module Pact
|
|
4
|
-
module Reification
|
|
5
|
-
|
|
6
|
-
def self.from_term(term)
|
|
7
|
-
case term
|
|
8
|
-
when Pact::Term, Regexp, Pact::SomethingLike
|
|
9
|
-
term.generate
|
|
10
|
-
when Hash
|
|
11
|
-
term.inject({}) do |mem, (key,term)|
|
|
12
|
-
mem[key] = from_term(term)
|
|
13
|
-
mem
|
|
14
|
-
end
|
|
15
|
-
when Array
|
|
16
|
-
term.inject([]) do |mem, term|
|
|
17
|
-
mem << from_term(term)
|
|
18
|
-
mem
|
|
19
|
-
end
|
|
20
|
-
when Pact::Request::Base
|
|
21
|
-
from_term(term.to_hash)
|
|
22
|
-
else
|
|
23
|
-
term
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
end
|
|
28
|
-
end
|
data/lib/pact/rspec.rb
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
require 'rspec'
|
|
2
|
-
# This is horrible, must work out a better way of doing this
|
|
3
|
-
module Pact
|
|
4
|
-
module RSpec
|
|
5
|
-
|
|
6
|
-
def self.color_enabled?
|
|
7
|
-
if ::RSpec.configuration.respond_to?(:color_enabled?)
|
|
8
|
-
::RSpec.configuration.color_enabled?(::RSpec.configuration.output_stream)
|
|
9
|
-
else
|
|
10
|
-
::RSpec.configuration.color_enabled?
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def self.formatter_class
|
|
15
|
-
if ::RSpec::Core::Formatters.respond_to?(:register)
|
|
16
|
-
require 'pact/provider/rspec/formatter_rspec_3'
|
|
17
|
-
Pact::Provider::RSpec::Formatter
|
|
18
|
-
else
|
|
19
|
-
require 'pact/provider/rspec/formatter_rspec_2'
|
|
20
|
-
Pact::Provider::RSpec::Formatter2
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def self.full_description example
|
|
26
|
-
example.respond_to?(:full_description) ? example.full_description : example.example.full_description
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def self.runner_defined?
|
|
30
|
-
defined?(::RSpec::Core::Runner)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def self.is_rspec_3
|
|
34
|
-
::RSpec::Core::Formatters.respond_to?(:register)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def self.is_rspec_2
|
|
38
|
-
!is_rspec_3
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def self.with_rspec_3
|
|
42
|
-
if is_rspec_3
|
|
43
|
-
yield
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def self.with_rspec_2
|
|
48
|
-
if is_rspec_2
|
|
49
|
-
yield
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
module Pact
|
|
2
|
-
module ActiveSupportSupport
|
|
3
|
-
|
|
4
|
-
extend self
|
|
5
|
-
|
|
6
|
-
def fix_all_the_things thing
|
|
7
|
-
if thing.is_a?(Regexp)
|
|
8
|
-
fix_regexp(thing)
|
|
9
|
-
elsif thing.is_a?(Array)
|
|
10
|
-
thing.each{ | it | fix_all_the_things it }
|
|
11
|
-
elsif thing.is_a?(Hash)
|
|
12
|
-
thing.values.each{ | it | fix_all_the_things it }
|
|
13
|
-
elsif thing.class.name.start_with?("Pact")
|
|
14
|
-
thing.instance_variables.collect{ | iv_name | thing.instance_variable_get(iv_name)}.each do | iv |
|
|
15
|
-
fix_all_the_things iv
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
thing
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# ActiveSupport JSON overwrites (i.e. TRAMPLES) the json methods of the Regexp class directly
|
|
22
|
-
# (beneath its destructive hooves of destruction).
|
|
23
|
-
# This does not seem to be able to be undone without affecting the JSON serialisation in the
|
|
24
|
-
# calling project, so the best way I've found to fix this issue is to reattach the
|
|
25
|
-
# original as_json to the Regexp instances in the ConsumerContract before we write them to the
|
|
26
|
-
# pact file. If anyone can find a better way, please submit a pull request ASAP!
|
|
27
|
-
def fix_regexp regexp
|
|
28
|
-
def regexp.as_json options = {}
|
|
29
|
-
{:json_class => 'Regexp', "o" => self.options, "s" => self.source }
|
|
30
|
-
end
|
|
31
|
-
regexp
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Having Active Support JSON loaded somehow kills the formatting of pretty_generate for objects.
|
|
35
|
-
# Don't ask me why, but it still seems to work for hashes, so the hacky work around is to
|
|
36
|
-
# reparse the generated JSON into a hash and pretty_generate that... sigh...
|
|
37
|
-
# Oh ActiveSupport, why....
|
|
38
|
-
def fix_json_formatting json
|
|
39
|
-
if json.include?("\n")
|
|
40
|
-
json
|
|
41
|
-
else
|
|
42
|
-
JSON.pretty_generate(JSON.parse(json, create_additions: false))
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def remove_unicode json
|
|
47
|
-
json.gsub(/\\u([0-9A-Za-z]{4})/) {|s| [$1.to_i(16)].pack("U")}
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
end
|
|
51
|
-
end
|
data/lib/pact/shared/dsl.rb
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
module Pact
|
|
2
|
-
|
|
3
|
-
class DslDelegator
|
|
4
|
-
|
|
5
|
-
def initialize delegation_target
|
|
6
|
-
@delegation_target = delegation_target
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def instance_eval_with_previous_context_available(*args, &block)
|
|
10
|
-
with_previous_context_available(block.binding) do
|
|
11
|
-
bind_block_as_instance_method_on_self(&block).call(*args)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
protected
|
|
16
|
-
|
|
17
|
-
def method_missing(method, *args, &block)
|
|
18
|
-
if delegation_target_responds_to? method
|
|
19
|
-
delegation_target.send(method, *args, &block)
|
|
20
|
-
else
|
|
21
|
-
previous_context.send(method, *args, &block)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
attr_accessor :delegation_target, :previous_context
|
|
28
|
-
|
|
29
|
-
def bind_block_as_instance_method_on_self(&block)
|
|
30
|
-
create_instance_method_from_block(&block).bind(self)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def create_instance_method_from_block &block
|
|
35
|
-
meth = self.class.class_eval do
|
|
36
|
-
define_method :block_as_instance_method_, &block
|
|
37
|
-
meth = instance_method :block_as_instance_method_
|
|
38
|
-
remove_method :block_as_instance_method_
|
|
39
|
-
meth
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def with_previous_context_available(binding, &block)
|
|
44
|
-
@previous_context = binding.eval('self')
|
|
45
|
-
result = block.call
|
|
46
|
-
@previous_context = nil
|
|
47
|
-
result
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def delegation_target_responds_to?(method)
|
|
51
|
-
delegation_target.respond_to? method
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# Ripped from http://blog.joecorcoran.co.uk/2013/09/04/simple-pattern-ruby-dsl
|
|
58
|
-
# and then fixed up by using http://www.skorks.com/2013/03/a-closure-is-not-always-a-closure-in-ruby/
|
|
59
|
-
# to access variables and methods defined in the calling scope.
|
|
60
|
-
module DSL
|
|
61
|
-
def build(*args, &block)
|
|
62
|
-
new_instance_of_delegation_target_class = self.new(*args)
|
|
63
|
-
dsl_delegator_class = self.const_get('DSL_DELEGATOR_CLASS')
|
|
64
|
-
dsl_delegator = dsl_delegator_class.new(new_instance_of_delegation_target_class)
|
|
65
|
-
dsl_delegator.instance_eval_with_previous_context_available(&block)
|
|
66
|
-
new_instance_of_delegation_target_class.finalize
|
|
67
|
-
new_instance_of_delegation_target_class
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def dsl(&block)
|
|
71
|
-
dsl_delegator_class = Class.new(DslDelegator, &block)
|
|
72
|
-
self.const_set('DSL_DELEGATOR_CLASS', dsl_delegator_class)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
end
|
|
76
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module Pact
|
|
2
|
-
module JRubySupport
|
|
3
|
-
|
|
4
|
-
# Under jruby, JSON.pretty_generate inserts a blank new line between the opening and closing
|
|
5
|
-
# brackets of an empty hash, like so:
|
|
6
|
-
# {
|
|
7
|
-
# "empty": {
|
|
8
|
-
#
|
|
9
|
-
# }
|
|
10
|
-
# }
|
|
11
|
-
# This screws up the UnixDiffFormatter, so we need to remove the blank lines.
|
|
12
|
-
|
|
13
|
-
def fix_blank_lines_in_empty_hashes json
|
|
14
|
-
json.gsub(/({\n)\n(\s*})/,'\1\2')
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
end
|