pact-support 1.11.0 → 1.12.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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/lib/pact/consumer_contract/consumer_contract.rb +11 -0
  4. data/lib/pact/consumer_contract/interaction.rb +4 -1
  5. data/lib/pact/consumer_contract/interaction_v2_parser.rb +9 -1
  6. data/lib/pact/consumer_contract/interaction_v3_parser.rb +10 -1
  7. data/lib/pact/support/version.rb +1 -1
  8. metadata +4 -227
  9. data/.github/ISSUE_TEMPLATE.md +0 -33
  10. data/.gitignore +0 -32
  11. data/.rspec +0 -3
  12. data/.travis.yml +0 -29
  13. data/Appraisals +0 -7
  14. data/Gemfile +0 -4
  15. data/RELEASING.md +0 -5
  16. data/Rakefile +0 -4
  17. data/gemfiles/default.gemfile +0 -5
  18. data/gemfiles/ruby_under_22.gemfile +0 -8
  19. data/pact-support.gemspec +0 -39
  20. data/script/release.sh +0 -9
  21. data/script/update-pact-specification-v2 +0 -9
  22. data/spec/fixtures/interaction-with-matching-rules.json +0 -27
  23. data/spec/fixtures/multipart-form-diff.txt +0 -9
  24. data/spec/fixtures/not-a-pact.json +0 -3
  25. data/spec/fixtures/pact-http-v2.json +0 -36
  26. data/spec/fixtures/pact-http-v3.json +0 -36
  27. data/spec/integration/matching_rules_extract_and_merge_spec.rb +0 -127
  28. data/spec/lib/pact/array_like_spec.rb +0 -37
  29. data/spec/lib/pact/configuration_spec.rb +0 -61
  30. data/spec/lib/pact/consumer/request_spec.rb +0 -25
  31. data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +0 -58
  32. data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -142
  33. data/spec/lib/pact/consumer_contract/file_name_spec.rb +0 -24
  34. data/spec/lib/pact/consumer_contract/headers_spec.rb +0 -107
  35. data/spec/lib/pact/consumer_contract/http_consumer_contract_parser_spec.rb +0 -25
  36. data/spec/lib/pact/consumer_contract/interaction_parser_spec.rb +0 -62
  37. data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -121
  38. data/spec/lib/pact/consumer_contract/interaction_v2_parser_spec.rb +0 -54
  39. data/spec/lib/pact/consumer_contract/interaction_v3_parser_spec.rb +0 -48
  40. data/spec/lib/pact/consumer_contract/pact_file_spec.rb +0 -204
  41. data/spec/lib/pact/consumer_contract/query_hash_spec.rb +0 -154
  42. data/spec/lib/pact/consumer_contract/query_string_spec.rb +0 -131
  43. data/spec/lib/pact/consumer_contract/request_spec.rb +0 -486
  44. data/spec/lib/pact/consumer_contract/response_spec.rb +0 -82
  45. data/spec/lib/pact/helpers_spec.rb +0 -143
  46. data/spec/lib/pact/matchers/differ_spec.rb +0 -215
  47. data/spec/lib/pact/matchers/difference_spec.rb +0 -22
  48. data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +0 -90
  49. data/spec/lib/pact/matchers/extract_diff_messages_spec.rb +0 -78
  50. data/spec/lib/pact/matchers/index_not_found_spec.rb +0 -21
  51. data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +0 -121
  52. data/spec/lib/pact/matchers/matchers_array_like_spec.rb +0 -222
  53. data/spec/lib/pact/matchers/matchers_messages_hash_and_array_spec.rb +0 -146
  54. data/spec/lib/pact/matchers/matchers_messages_mismatched_value_spec.rb +0 -72
  55. data/spec/lib/pact/matchers/matchers_messages_regexp_spec.rb +0 -103
  56. data/spec/lib/pact/matchers/matchers_spec.rb +0 -561
  57. data/spec/lib/pact/matchers/multipart_form_diff_formatter_spec.rb +0 -36
  58. data/spec/lib/pact/matchers/no_diff_at_index_spec.rb +0 -15
  59. data/spec/lib/pact/matchers/regexp_difference_spec.rb +0 -20
  60. data/spec/lib/pact/matchers/type_difference_spec.rb +0 -36
  61. data/spec/lib/pact/matchers/unexpected_index_spec.rb +0 -20
  62. data/spec/lib/pact/matchers/unexpected_key_spec.rb +0 -20
  63. data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +0 -235
  64. data/spec/lib/pact/matching_rules/extract_spec.rb +0 -216
  65. data/spec/lib/pact/matching_rules/merge_spec.rb +0 -436
  66. data/spec/lib/pact/matching_rules/v3/extract_spec.rb +0 -238
  67. data/spec/lib/pact/matching_rules/v3/merge_spec.rb +0 -485
  68. data/spec/lib/pact/matching_rules_spec.rb +0 -82
  69. data/spec/lib/pact/reification_spec.rb +0 -172
  70. data/spec/lib/pact/shared/dsl_spec.rb +0 -100
  71. data/spec/lib/pact/shared/form_differ_spec.rb +0 -71
  72. data/spec/lib/pact/shared/json_differ_spec.rb +0 -36
  73. data/spec/lib/pact/shared/key_not_found_spec.rb +0 -20
  74. data/spec/lib/pact/shared/multipart_form_differ_spec.rb +0 -49
  75. data/spec/lib/pact/shared/request_spec.rb +0 -235
  76. data/spec/lib/pact/shared/text_differ_spec.rb +0 -54
  77. data/spec/lib/pact/something_like_spec.rb +0 -23
  78. data/spec/lib/pact/support_spec.rb +0 -9
  79. data/spec/lib/pact/symbolize_keys_spec.rb +0 -15
  80. data/spec/lib/pact/term_spec.rb +0 -89
  81. data/spec/pact_specification/compliance-2.0.rb +0 -66
  82. data/spec/spec_helper.rb +0 -18
  83. data/spec/support/a_consumer-a_producer.json +0 -32
  84. data/spec/support/a_consumer-a_provider.json +0 -32
  85. data/spec/support/active_support_if_configured.rb +0 -6
  86. data/spec/support/case-insensitive-response-header-matching.json +0 -21
  87. data/spec/support/consumer_contract_template.json +0 -24
  88. data/spec/support/dsl_spec_support.rb +0 -7
  89. data/spec/support/factories.rb +0 -87
  90. data/spec/support/generated_index.md +0 -4
  91. data/spec/support/generated_markdown.md +0 -55
  92. data/spec/support/interaction_view_model.json +0 -63
  93. data/spec/support/interaction_view_model_with_terms.json +0 -50
  94. data/spec/support/markdown_pact.json +0 -48
  95. data/spec/support/missing_provider_states_output.txt +0 -25
  96. data/spec/support/options.json +0 -21
  97. data/spec/support/ruby_version_helpers.rb +0 -23
  98. data/spec/support/shared_examples_for_request.rb +0 -132
  99. data/spec/support/spec_support.rb +0 -29
  100. data/spec/support/stubbing.json +0 -22
  101. data/spec/support/term.json +0 -48
  102. data/spec/support/test_app_fail.json +0 -61
  103. data/spec/support/test_app_pass.json +0 -38
  104. data/spec/support/test_app_with_right_content_type_differ.json +0 -23
  105. data/tasks/release.rake +0 -5
  106. data/tasks/spec.rake +0 -14
@@ -1,146 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers'
3
- require 'pact/consumer_contract/headers'
4
-
5
- module Pact::Matchers
6
-
7
- describe Pact::Matchers do
8
- include Pact::Matchers
9
-
10
- describe "diff" do
11
- STRING = "foo"
12
- INT = 1
13
- FLOAT = 1.0
14
- HASH = {foo: "bar"}
15
- ARRAY = ["foo"]
16
-
17
- context "with a Hash" do
18
-
19
- context "with a missing key when the actual is an empty Hash" do
20
- let(:expected) { {thing: "foo"} }
21
- let(:actual) { {} }
22
- let(:difference) { diff(expected, actual) }
23
-
24
- it "returns a message" do
25
- expect(difference[:thing].message).to eq "Could not find key \"thing\" in empty Hash at <parent_path>"
26
- end
27
- end
28
-
29
- context "with a missing key when the actual is a populated Hash" do
30
- let(:expected) { {thing: "foo"} }
31
- let(:actual) { {a_thing: "foo", other_thing: "foo"} }
32
- let(:difference) { diff(expected, actual) }
33
-
34
- it "returns a message" do
35
- expect(difference[:thing].message).to eq "Could not find key \"thing\" (keys present are: a_thing, other_thing) at <parent_path>"
36
- end
37
- end
38
-
39
- context "with an unexpected key" do
40
- let(:expected) { {thing: "foo"} }
41
- let(:actual) { {thing: "foo", another_thing: "foo"} }
42
- let(:difference) { diff(expected, actual, {allow_unexpected_keys: false}) }
43
-
44
- it "returns a message" do
45
- expect(difference[:another_thing].message).to eq "Did not expect the key \"another_thing\" to exist at <parent_path>"
46
- end
47
- end
48
- end
49
-
50
- context "with an Array" do
51
-
52
- context "with not enough Integer items" do
53
- let(:expected) { {thing: [1, 2]} }
54
- let(:actual) { {thing: [1]} }
55
- let(:difference) { diff(expected, actual) }
56
-
57
- it "returns a message" do
58
- expect(difference[:thing][1].message).to eq "Actual array is too short and should have contained 2 at <path>"
59
- end
60
- end
61
-
62
- context "with not enough String items" do
63
- let(:expected) { {thing: [1, STRING]} }
64
- let(:actual) { {thing: [1]} }
65
- let(:difference) { diff(expected, actual) }
66
-
67
- it "returns a message" do
68
- expect(difference[:thing][1].message).to eq "Actual array is too short and should have contained \"foo\" at <path>"
69
- end
70
- end
71
-
72
- context "with not enough Hash items" do
73
- let(:expected) { {thing: [1, HASH]} }
74
- let(:actual) { {thing: [1]} }
75
- let(:difference) { diff(expected, actual) }
76
-
77
- it "returns a message" do
78
- expect(difference[:thing][1].message).to eq "Actual array is too short and should have contained a Hash at <path>"
79
- end
80
- end
81
-
82
- context "with not enough Array items" do
83
- let(:expected) { {thing: [1, ARRAY]} }
84
- let(:actual) { {thing: [1]} }
85
- let(:difference) { diff(expected, actual) }
86
-
87
- it "returns a message" do
88
- expect(difference[:thing][1].message).to eq "Actual array is too short and should have contained an Array at <path>"
89
- end
90
- end
91
-
92
- context "with an extra item that is an Integer" do
93
- let(:expected) { {thing: [1]} }
94
- let(:actual) { {thing: [1, 2]} }
95
- let(:difference) { diff(expected, actual) }
96
-
97
- it "returns a message" do
98
- expect(difference[:thing][1].message).to eq "Actual array is too long and should not contain 2 at <path>"
99
- end
100
- end
101
-
102
- context "with an extra item that is a String" do
103
- let(:expected) { {thing: [1]} }
104
- let(:actual) { {thing: [1, "foo"]} }
105
- let(:difference) { diff(expected, actual) }
106
-
107
- it "returns a message" do
108
- expect(difference[:thing][1].message).to eq "Actual array is too long and should not contain \"foo\" at <path>"
109
- end
110
- end
111
-
112
- context "with an extra item that is a Hash" do
113
- let(:expected) { {thing: [1]} }
114
- let(:actual) { {thing: [1, HASH]} }
115
- let(:difference) { diff(expected, actual) }
116
-
117
- it "returns a message" do
118
- expect(difference[:thing][1].message).to eq "Actual array is too long and should not contain a Hash at <path>"
119
- end
120
- end
121
-
122
- context "with an extra item that is an Array" do
123
- let(:expected) { {thing: [1]} }
124
- let(:actual) { {thing: [1, ARRAY]} }
125
- let(:difference) { diff(expected, actual) }
126
-
127
- it "returns a message" do
128
- expect(difference[:thing][1].message).to eq "Actual array is too long and should not contain an Array at <path>"
129
- end
130
- end
131
- end
132
-
133
- context "with an ArrayLike" do
134
- context "with an extra item that is an Integer" do
135
- let(:expected) { {thing: Pact.like([1])} }
136
- let(:actual) { {thing: [1, 2]} }
137
- let(:difference) { diff(expected, actual) }
138
-
139
- it "returns a message" do
140
- expect(difference[:thing][1].message).to eq "Actual array is too long and should not contain 2 at <path>"
141
- end
142
- end
143
- end
144
- end
145
- end
146
- end
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers'
3
- require 'pact/consumer_contract/headers'
4
- require 'support/ruby_version_helpers'
5
-
6
- module Pact::Matchers
7
-
8
- describe Pact::Matchers do
9
- include Pact::Matchers
10
- extend RubyVersionHelpers
11
-
12
- describe "diff" do
13
- STRING = "foo"
14
- INT = 1
15
- FLOAT = 1.0
16
- HASH = {foo: "bar"}
17
- ARRAY = ["foo"]
18
-
19
- COMBINATIONS = [
20
- [STRING, "bar", "Expected \"foo\" but got \"bar\" at <path>"],
21
- [STRING, nil, "Expected \"foo\" but got nil at <path>"],
22
- [STRING, INT, "Expected \"foo\" but got 1 at <path>"],
23
- [STRING, FLOAT, "Expected \"foo\" but got 1.0 at <path>"],
24
- [STRING, HASH, "Expected \"foo\" but got a Hash at <path>"],
25
- [STRING, ARRAY, "Expected \"foo\" but got an Array at <path>"],
26
- [Pact.like(STRING), "bar", nil],
27
- [Pact.like(STRING), nil, "Expected a String (like \"foo\") but got nil at <path>"],
28
- [Pact.like(STRING), INT, "Expected a String (like \"foo\") but got #{a_numeric} (1) at <path>"],
29
- [Pact.like(STRING), FLOAT, "Expected a String (like \"foo\") but got a Float (1.0) at <path>"],
30
- [Pact.like(STRING), HASH, "Expected a String (like \"foo\") but got a Hash at <path>"],
31
- [Pact.like(STRING), ARRAY, "Expected a String (like \"foo\") but got an Array at <path>"],
32
- [INT, 2, "Expected 1 but got 2 at <path>"],
33
- [INT, nil, "Expected 1 but got nil at <path>"],
34
- [INT, STRING, "Expected 1 but got \"foo\" at <path>"],
35
- [INT, FLOAT, nil],
36
- [INT, HASH, "Expected 1 but got a Hash at <path>"],
37
- [INT, ARRAY, "Expected 1 but got an Array at <path>"],
38
- [Pact.like(INT), 2, nil],
39
- [Pact.like(INT), nil, "Expected #{a_numeric} (like 1) but got nil at <path>"],
40
- [Pact.like(INT), STRING, "Expected #{a_numeric} (like 1) but got a String (\"foo\") at <path>"],
41
- [Pact.like(INT), FLOAT, "Expected #{a_numeric} (like 1) but got a Float (1.0) at <path>", { treat_all_number_classes_as_equivalent: false }],
42
- [Pact.like(INT), FLOAT, nil, { treat_all_number_classes_as_equivalent: true }],
43
- [Pact.like(INT), HASH, "Expected #{a_numeric} (like 1) but got a Hash at <path>"],
44
- [Pact.like(INT), ARRAY, "Expected #{a_numeric} (like 1) but got an Array at <path>"],
45
- [HASH, HASH, nil],
46
- [HASH, nil, "Expected a Hash but got nil at <path>"],
47
- [HASH, STRING, "Expected a Hash but got a String (\"foo\") at <path>"],
48
- [HASH, INT, "Expected a Hash but got #{a_numeric} (1) at <path>"],
49
- [HASH, FLOAT, "Expected a Hash but got a Float (1.0) at <path>"],
50
- [HASH, ARRAY, "Expected a Hash but got an Array at <path>"],
51
- [Pact.like(HASH), STRING, "Expected a Hash but got a String (\"foo\") at <path>"],
52
- [ARRAY, ARRAY, nil],
53
- [ARRAY, nil, "Expected an Array but got nil at <path>"],
54
- [ARRAY, STRING, "Expected an Array but got a String (\"foo\") at <path>"],
55
- [ARRAY, INT, "Expected an Array but got #{a_numeric} (1) at <path>"],
56
- [ARRAY, FLOAT, "Expected an Array but got a Float (1.0) at <path>"],
57
- [ARRAY, HASH, "Expected an Array but got a Hash at <path>"]
58
- ]
59
-
60
- COMBINATIONS.each do | expected, actual, expected_message, diff_options |
61
- context "when expected is #{expected.inspect} and actual is #{actual.inspect}" do
62
- let(:difference) { diff({thing: expected}, {thing: actual}, diff_options || {}) }
63
- let(:message) { difference[:thing] ? difference[:thing].message : nil }
64
-
65
- it "returns the message '#{expected_message}'" do
66
- expect(message).to eq expected_message
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,103 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers'
3
- require 'pact/consumer_contract/headers'
4
- require 'support/ruby_version_helpers'
5
-
6
- module Pact::Matchers
7
-
8
- describe Pact::Matchers do
9
- include Pact::Matchers
10
- include RubyVersionHelpers
11
-
12
- describe "diff" do
13
- STRING = "foo"
14
- INT = 1
15
- FLOAT = 1.0
16
- HASH = {foo: "bar"}
17
- ARRAY = ["foo"]
18
-
19
-
20
- let(:term) { Pact.term(/foo/, "food") }
21
- let(:regexp) { /foo/ }
22
- let(:actual) { "drink" }
23
- let(:difference) { diff({thing: expected}, {thing: actual}) }
24
-
25
- context "with a Pact::Term" do
26
- let(:expected) { term }
27
-
28
- context "when the Pact::Term does not match" do
29
- it "returns a message" do
30
- expect(difference[:thing].message).to eq "Expected a String matching /foo/ (like \"food\") but got \"drink\" at <path>"
31
- end
32
- end
33
-
34
- context "when the actual is a numeric" do
35
- let(:actual) { INT }
36
- it "returns a message" do
37
- expect(difference[:thing].message).to eq "Expected a String matching /foo/ (like \"food\") but got #{a_numeric} (1) at <path>"
38
- end
39
- end
40
-
41
- context "when the actual is Hash" do
42
- let(:actual) { HASH }
43
- it "returns a message" do
44
- expect(difference[:thing].message).to eq "Expected a String matching /foo/ (like \"food\") but got a Hash at <path>"
45
- end
46
- end
47
-
48
- context "when the actual is a numeric" do
49
- let(:actual) { INT }
50
- it "returns a message" do
51
- expect(difference[:thing].message).to eq "Expected a String matching /foo/ (like \"food\") but got #{a_numeric} (1) at <path>"
52
- end
53
- end
54
-
55
- context "when the actual is nil" do
56
- let(:actual) { nil }
57
- it "returns a message" do
58
- expect(difference[:thing].message).to eq "Expected a String matching /foo/ (like \"food\") but got nil at <path>"
59
- end
60
- end
61
- end
62
-
63
- context "with a Regexp" do
64
-
65
- let(:expected) { regexp }
66
-
67
- context "when the Pact::Term does not match" do
68
- it "returns a message" do
69
- expect(difference[:thing].message).to eq "Expected a String matching /foo/ but got \"drink\" at <path>"
70
- end
71
- end
72
-
73
- context "when the actual is a numeric" do
74
- let(:actual) { INT }
75
- it "returns a message" do
76
- expect(difference[:thing].message).to eq "Expected a String matching /foo/ but got #{a_numeric} (1) at <path>"
77
- end
78
- end
79
-
80
- context "when the actual is Hash" do
81
- let(:actual) { HASH }
82
- it "returns a message" do
83
- expect(difference[:thing].message).to eq "Expected a String matching /foo/ but got a Hash at <path>"
84
- end
85
- end
86
-
87
- context "when the actual is a numeric" do
88
- let(:actual) { INT }
89
- it "returns a message" do
90
- expect(difference[:thing].message).to eq "Expected a String matching /foo/ but got #{a_numeric} (1) at <path>"
91
- end
92
- end
93
-
94
- context "when the actual is nil" do
95
- let(:actual) { nil }
96
- it "returns a message" do
97
- expect(difference[:thing].message).to eq "Expected a String matching /foo/ but got nil at <path>"
98
- end
99
- end
100
- end
101
- end
102
- end
103
- end
@@ -1,561 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers'
3
- require 'pact/consumer_contract/headers'
4
-
5
- module Pact::Matchers
6
-
7
- describe Pact::Matchers do
8
- include Pact::Matchers
9
-
10
- # TODO this is an integration test
11
- describe 'matching headers' do
12
- let(:expected) { Pact::Headers.new('Content-Type' => 'application/hippo')}
13
-
14
- context "when the headers match in a case insensitive way" do
15
-
16
- context "when the values match" do
17
- let(:actual) { Pact::Headers.new('CONTENT-TYPE' => 'application/hippo')}
18
- it "returns an empty diff" do
19
- expect(diff(expected, actual)).to be_empty
20
- end
21
- end
22
-
23
- context "when the header values do not match" do
24
- let(:actual) { Pact::Headers.new('CONTENT-TYPE' => 'application/alligator')}
25
- let(:difference) { {"Content-Type" => Difference.new('application/hippo', 'application/alligator')} }
26
- it "returns the diff" do
27
- expect(diff(expected, actual)).to eq difference
28
- end
29
- end
30
- end
31
-
32
- context "when the headers do not match" do
33
- let(:actual) { Pact::Headers.new('Content-Length' => '1')}
34
- let(:difference) { {"Content-Type" => Difference.new('application/hippo', Pact::KeyNotFound.new)} }
35
- it "returns a diff" do
36
- expect(diff(expected, actual)).to eq difference
37
- end
38
- end
39
- end
40
-
41
-
42
- context 'when treat_all_number_classes_as_equivalent is true' do
43
- let(:options) { { treat_all_number_classes_as_equivalent: true } }
44
-
45
- describe 'matching numbers with something like' do
46
- let(:expected) { Pact::SomethingLike.new( { a: 1.1 } ) }
47
- let(:actual) { { a: 2 } }
48
-
49
- it 'returns an empty diff' do
50
- expect(diff(expected, actual, options)).to eq({})
51
- end
52
- end
53
-
54
- describe 'with exact matching' do
55
- let(:expected) { { a: 1 } }
56
- let(:actual) { { a: 1.0 } }
57
-
58
- it 'returns an empty diff' do
59
- expect(diff(expected, actual, options)).to eq({})
60
- end
61
- end
62
- end
63
-
64
- context 'when treat_all_number_classes_as_equivalent is false' do
65
- let(:options) { { treat_all_number_classes_as_equivalent: false } }
66
-
67
- describe 'matching numbers with something like' do
68
- let(:expected) { Pact::SomethingLike.new( { a: 1.1 } ) }
69
- let(:actual) { { a: 2 } }
70
-
71
- it 'returns a diff' do
72
- expect(diff(expected, actual, options)).to_not eq({})
73
- end
74
- end
75
-
76
- describe 'with exact matching' do
77
- let(:expected) { { a: 1 } }
78
- let(:actual) { { a: 1.0 } }
79
-
80
- it 'returns an empty diff because in Ruby 1.0 == 1' do
81
- expect(diff(expected, actual)).to eq({})
82
- end
83
- end
84
- end
85
-
86
- describe 'matching with something like' do
87
- context 'when the actual is something like the expected' do
88
- let(:expected) { Pact::SomethingLike.new( { a: 1 } ) }
89
- let(:actual) { { a: 2 } }
90
-
91
- it 'returns an empty diff' do
92
- expect(diff(expected, actual)).to eq({})
93
- end
94
- end
95
-
96
- context 'when the there is a mismatch of a parent, and a child contains a SomethingLike' do
97
- let(:expected) { {thing: {foo: Pact::SomethingLike.new(1)}} }
98
- let(:actual) { {thing: [1]} }
99
- let(:difference) { {thing: Difference.new({foo: 1}, [1]) } }
100
-
101
- it "reifies the children" do
102
- expect(diff(expected, actual)).to eq difference
103
- end
104
- end
105
- end
106
-
107
- describe 'option {allow_unexpected_keys: false}' do
108
- context "when an unexpected key is found" do
109
- let(:expected) { {:a => 1} }
110
- let(:actual) { {:a => 1, :b => 2} }
111
- let(:difference) { {:b => Difference.new(Pact::UnexpectedKey.new, 2 )} }
112
- it "returns it in the diff" do
113
- expect(diff(expected, actual, allow_unexpected_keys: false)).to eq difference
114
- end
115
- end
116
- end
117
-
118
- describe "expecting key to be present with nil value and not finding key" do
119
- let(:expected) { {a: nil} }
120
- let(:actual) { {} }
121
- let(:difference) { {a: Difference.new(nil, Pact::KeyNotFound.new )} }
122
- it "returns the key in the diff" do
123
- expect(diff(expected, actual)).to eq difference
124
- end
125
- end
126
-
127
- describe "expecting a string matching a regexp and not finding key" do
128
- let(:expected) { {a: /b/} }
129
- let(:actual) { {} }
130
- let(:difference) { {:a=> RegexpDifference.new(/b/, Pact::KeyNotFound.new) } }
131
- it "returns the diff" do
132
- expect(diff(expected, actual)).to eq difference
133
- end
134
- end
135
-
136
- describe 'type_diff' do
137
- let(:expected) {
138
- {a: 'a string', b: 1, c: nil, d: [{e: 'thing'}], f: {g: 10}, h: false}
139
- }
140
-
141
- context "when the classes match" do
142
- let(:actual) { {a: 'another string', b: 2, c: nil, d: [{e: 'something'}], f: {g: 100}, h: true} }
143
- let(:difference) { {} }
144
- it "returns an empty hash" do
145
- expect(type_diff(expected, actual)).to eq difference
146
- end
147
- end
148
-
149
- context "when a key is not found" do
150
- let(:actual) { {a: 'blah'} }
151
- let(:expected) { {b: 'blah'} }
152
- let(:difference) { {:b=>TypeDifference.new(Pact::ExpectedType.new("blah"), Pact::KeyNotFound.new)} }
153
- it "returns the difference" do
154
- expect(type_diff(expected, actual)).to eq difference
155
- end
156
- end
157
-
158
- context "when a number is expected" do
159
- let(:expected) { {a: 1} }
160
- let(:difference) { {a: TypeDifference.new(Pact::ExpectedType.new(1) , Pact::ActualType.new('a string'))} }
161
-
162
- context "and a string is found" do
163
- let(:actual) { {a: 'a string'}}
164
- it "returns the diff" do
165
- expect(type_diff(expected, actual)).to eq difference
166
- end
167
- end
168
- context "and nil is found" do
169
- let(:actual) { {a: nil} }
170
- let(:difference ) { {a: TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new(nil)) } }
171
- it "returns the diff" do
172
- expect(type_diff(expected, actual)).to eq difference
173
- end
174
- end
175
- context "and a hash is found" do
176
- let(:actual) { {a: {b: 1}} }
177
- let(:difference) { {a: TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new({:b=>1})) } }
178
- it "returns the diff" do
179
- expect(type_diff(expected, actual)).to eq difference
180
- end
181
- end
182
- context "and an array is found" do
183
- let(:actual) { {a: [1] } }
184
- let(:difference) { {a: TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new([1]))}}
185
- it "returns the diff" do
186
- expect(type_diff(expected, actual)).to eq difference
187
- end
188
- end
189
- end
190
-
191
- context "when an array is expected" do
192
- let(:expected) { [{name: 'Fred'}, {name: 'Mary'}] }
193
- context "when an item with differing class values is found" do
194
- let(:actual) { [{name: 'Fred'}, {name: 1}] }
195
- let(:difference) {
196
- [
197
- NoDiffAtIndex.new,
198
- {
199
- name: TypeDifference.new(Pact::ExpectedType.new("Mary"), Pact::ActualType.new(1))
200
- }
201
- ]
202
- }
203
- it "returns the diff" do
204
- expect(type_diff(expected, actual)).to eq difference
205
- end
206
- end
207
- end
208
-
209
-
210
- context "when nil is expected" do
211
- let(:expected) { {a: nil} }
212
- context "and a string is found" do
213
- let(:actual) { {a: 'a string'} }
214
- let(:difference) { {a: TypeDifference.new(Pact::ExpectedType.new(nil), Pact::ActualType.new("a string")) } }
215
- it "returns the diff" do
216
- expect(type_diff(expected, actual)).to eq difference
217
- end
218
- end
219
- end
220
-
221
- context "when a term is expected" do
222
- let(:expected) { {a: Pact::Term.new(:matcher => /p/, :generate => 'apple')} }
223
- context "and a non matching string is found" do
224
- let(:actual) { {a: 'banana'} }
225
- let(:difference) { {:a=>Pact::Matchers::RegexpDifference.new(/p/,"banana")} }
226
- it "returns the diff" do
227
- expect(type_diff(expected, actual)).to eq difference
228
- end
229
- end
230
- end
231
-
232
- context "when a term is expected inside a missing hash" do
233
- let(:expected) { {a: {b: Pact::Term.new(:matcher => /p/, :generate => 'apple')}} }
234
- context "and a non matching value is found" do
235
- let(:actual) { {a: nil} }
236
- let(:difference) { {a: Difference.new({b: "apple"}, nil)} }
237
- it "returns the diff with the term reified" do
238
- expect(type_diff(expected, actual)).to eq difference
239
- end
240
- end
241
- end
242
-
243
- context "when unexpected keys are allowed" do
244
- let(:expected) { { a: 'b' } }
245
- let(:actual) { {a: 'c', d: 'e'} }
246
- let(:difference) { {} }
247
- it "returns the diff" do
248
- expect(type_diff(expected, actual, allow_unexpected_keys: true)).to eq difference
249
- end
250
- end
251
-
252
- context "when unexpected keys are not allowed" do
253
- let(:expected) { { a: 'b' } }
254
- let(:actual) { {a: 'c', d: 'e'} }
255
- let(:difference) { {d: Difference.new(Pact::UnexpectedKey.new, 'e')} }
256
- it "returns the diff" do
257
- expect(type_diff(expected, actual, allow_unexpected_keys: false)).to eq difference
258
- end
259
- end
260
- end
261
-
262
- describe 'diffing' do
263
-
264
- context "when expected is longer than the actual" do
265
- subject { [1, 2, 3] }
266
- let(:actual) { [1, 2] }
267
- let(:difference) { [NoDiffAtIndex.new, NoDiffAtIndex.new, Difference.new(3, Pact::IndexNotFound.new)] }
268
- it 'returns the diff' do
269
- expect(diff(subject, actual)).to eq(difference)
270
- end
271
- end
272
-
273
- context "when the different index is in the middle of an array" do
274
- subject { [1,2,3] }
275
- let(:actual) { [1,7,3]}
276
- let(:difference) { [NoDiffAtIndex.new, Difference.new(2, 7), NoDiffAtIndex.new] }
277
- it 'returns the diff' do
278
- expect(diff(subject, actual)).to eq(difference)
279
- end
280
- end
281
-
282
- context "when actual array is longer than the expected" do
283
- subject { [1] }
284
- let(:actual) { [1,2]}
285
- let(:difference) { [NoDiffAtIndex.new, Difference.new(Pact::UnexpectedIndex.new, 2)] }
286
- it 'returns the diff' do
287
- expect(diff(subject, actual)).to eq(difference)
288
- end
289
- end
290
-
291
- context 'where an expected value is a non-empty string' do
292
-
293
- subject { {:a => 'a', :b => 'b'} }
294
-
295
- context 'and the actual value is an empty string' do
296
-
297
- let(:actual) { {:a => 'a', :b => ''} }
298
-
299
- it 'includes this in the diff' do
300
- expect(diff(subject, actual)).to eq({:b => Difference.new('b', '')})
301
- end
302
-
303
- end
304
-
305
- end
306
-
307
- context "when the expected value is a hash" do
308
- subject { {a: 'b'} }
309
- context "when the actual value is an array" do
310
- let(:actual) { [1] }
311
- let(:difference) { Difference.new(subject, actual) }
312
- it "should return the diff" do
313
- expect(diff(subject, actual)).to eq(difference)
314
- end
315
- end
316
-
317
- context "when the actual value is an array, and both expected and actual contain SomethingLike" do
318
- subject { {a: {foo: Pact.like("b")}} }
319
- let(:actual) { {a: [1] } }
320
- let(:difference) { {a: Difference.new({foo: "b"}, [1]) } }
321
-
322
- it "should return the diff with the reified likes" do
323
- expect(diff(subject, actual)).to eq(difference)
324
- end
325
- end
326
-
327
- context "when the actual value is an hash" do
328
- let(:actual) { {b: 'c'} }
329
- let(:difference) { { a: Difference.new("b",Pact::KeyNotFound.new)} }
330
- it "should return the diff" do
331
- expect(diff(subject, actual)).to eq(difference)
332
- end
333
- end
334
- context "when the actual value is an number" do
335
- let(:actual) { 1 }
336
- let(:difference) { Difference.new({a: "b"}, 1) }
337
- it "should return the diff" do
338
- expect(diff(subject, actual)).to eq(difference)
339
- end
340
- end
341
- context "when the actual value is a string" do
342
- let(:actual) { "Thing" }
343
- let(:difference) { Difference.new(subject, actual) }
344
- it "should return the diff" do
345
- expect(diff(subject, actual)).to eq(difference)
346
- end
347
- end
348
- context "when the actual value is the same" do
349
- let (:actual) { {a: 'b'} }
350
- it "should return an empty hash" do
351
- expect(diff(subject, actual)).to eq({})
352
- end
353
- end
354
- end
355
-
356
- context "when the expected value is an array" do
357
- subject { [1] }
358
- context "when the actual value is an array" do
359
- let(:actual) { [2] }
360
- let(:difference) { [Difference.new(1, 2)] }
361
- it "should return the diff" do
362
- expect(diff(subject, actual)).to eq difference
363
- end
364
- end
365
- context "when the actual value is an hash" do
366
- let(:actual) { {b: 'c'} }
367
- let(:difference) { Difference.new(subject, actual) }
368
- it "should return the diff" do
369
- expect(diff(subject, actual)).to eq(difference)
370
- end
371
- end
372
- context "when the actual value is an number" do
373
- let(:actual) { 1 }
374
- let(:difference) { Difference.new(subject, actual) }
375
- it "should return the diff" do
376
- expect(diff(subject, actual)).to eq(difference)
377
- end
378
- end
379
- context "when the actual value is a string" do
380
- let(:actual) { "Thing" }
381
- let(:difference) { Difference.new(subject, actual) }
382
- it "should return the diff" do
383
- expect(diff(subject, actual)).to eq(difference)
384
- end
385
- end
386
- context "when the actual value is the same" do
387
- let (:actual) { [1] }
388
- it "should return an empty hash" do
389
- expect(diff(subject, actual)).to eql({})
390
- end
391
- end
392
- end
393
-
394
- context "when the expected value is a string" do
395
- subject { "Thing"}
396
- context "when the actual value is an array" do
397
- let(:actual) { [2] }
398
- let(:difference) { Difference.new(subject, actual) }
399
- it "should return the diff" do
400
- expect(diff(subject, actual)).to eq(difference)
401
- end
402
- end
403
- context "when the actual value is an hash" do
404
- let(:actual) { {b: 'c'} }
405
- let(:difference) { Difference.new(subject, actual) }
406
- it "should return the diff" do
407
- expect(diff(subject, actual)).to eq(difference)
408
- end
409
- end
410
- context "when the actual value is an number" do
411
- let(:actual) { 1 }
412
- let(:difference) { Difference.new(subject, actual) }
413
- it "should return the diff" do
414
- expect(diff(subject, actual)).to eq(difference)
415
- end
416
- end
417
- context "when the actual value is a string" do
418
- let(:actual) { "Another Thing" }
419
- let(:difference) { Difference.new(subject, actual) }
420
- it "should return the diff" do
421
- expect(diff(subject, actual)).to eq(difference)
422
- end
423
- end
424
- context "when the actual value is the same" do
425
- let (:actual) { "Thing" }
426
- it "should return an empty hash" do
427
- expect(diff(subject, actual)).to eq({})
428
- end
429
- end
430
- end
431
-
432
- context "when the expected value is a number" do
433
- subject { 1 }
434
- let(:difference) { Difference.new(subject, actual) }
435
- context "when the actual value is an array" do
436
- let(:actual) { [2] }
437
- it "should return the diff" do
438
- expect(diff(subject, actual)).to eq(difference)
439
- end
440
- end
441
- context "when the actual value is an hash" do
442
- let(:actual) { {b: 'c'} }
443
- it "should return the diff" do
444
- expect(diff(subject, actual)).to eq(difference)
445
- end
446
- end
447
- context "when the actual value is an number" do
448
- let(:actual) { 2 }
449
- it "should return the diff" do
450
- expect(diff(subject, actual)).to eq(difference)
451
- end
452
- end
453
- context "when the actual value is a string" do
454
- let(:actual) { "Another Thing" }
455
- it "should return the diff" do
456
- expect(diff(subject, actual)).to eq(difference)
457
- end
458
- end
459
- context "when the actual value is the same" do
460
- let (:actual) { 1 }
461
- it "should return an empty hash" do
462
- expect(diff(subject, actual)).to eq({})
463
- end
464
- end
465
- end
466
-
467
- context "when the expected value is a String matcher" do
468
-
469
- end
470
-
471
- context "when the expected value is a Number matcher" do
472
-
473
- end
474
- context "when the expected value is an array with a matcher" do
475
-
476
- end
477
- context "when the expected value is a hash with a matcher" do
478
-
479
- end
480
-
481
- context "when an expected value is nil but not nil is found" do
482
- subject { {a: nil} }
483
- let(:actual) { {a: 'blah'} }
484
- let(:difference) { {:a=>Difference.new(nil, "blah")} }
485
- it "should return the diff" do
486
- expect(diff(subject, actual)).to eq(difference)
487
- end
488
- end
489
-
490
- context "a deep mismatch" do
491
- subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/, generate: 'apple')}}, f: 1, g: {h: 99}} }
492
- let(:actual) { {a: {b: { c: [1,2]}, d: { e: 'food'}}, f: "thing"} }
493
- let(:difference) { {:a=>{:d=>{:e=> RegexpDifference.new(/a/, "food")}},
494
- :f=> Difference.new(1, "thing"),
495
- :g=>Difference.new({:h=>99}, Pact::KeyNotFound.new)} }
496
-
497
- it 'should return the diff' do
498
- expect(diff(subject, actual)).to eq(difference)
499
- end
500
- end
501
-
502
-
503
- context "where a Pact::Term is found that matches the actual value" do
504
- subject { {:a => Pact::Term.new(:matcher => /a/, :generate => 'apple')} }
505
- let(:actual) { {:a => "apple" } }
506
-
507
- it 'does not include this in the diff' do
508
- expect(diff(subject, actual)).to eq({})
509
- end
510
- end
511
-
512
- context "where an array is expected at a key inside a hash, but a hash is found" do
513
- subject { {:a => [1,2,3]} }
514
- let(:actual) { {:a => {:b => 1} } }
515
-
516
- it 'includes this in the diff' do
517
- expect(diff(subject, actual)).to eq({:a => Difference.new([1,2,3], {:b => 1})})
518
- end
519
- end
520
-
521
- context "where an array is expected, but a hash is found" do
522
- subject { {:a => :b} }
523
- let(:actual) { [4, 5, 6] }
524
-
525
- it 'includes this in the diff' do
526
- expect(diff(subject, actual)).to eq(Difference.new({:a => :b}, [4,5,6] ))
527
- end
528
- end
529
-
530
- context "where a hash is expected, but array is found" do
531
- subject { [4,5,6] }
532
- let(:actual) { {:a => :b} }
533
-
534
- it 'includes this in the diff' do
535
- expect(diff(subject, actual)).to eq(Difference.new([4,5,6],{:a => :b}))
536
- end
537
- end
538
-
539
- context "when two different arrays are found" do
540
- subject { [4,5,6] }
541
- let(:actual) { [4, 6, 7] }
542
- let(:difference) { [NoDiffAtIndex.new, Difference.new(5, 6), Difference.new(6, 7)] }
543
-
544
- it 'includes this in the diff' do
545
- expect(diff(subject, actual)).to eq(difference)
546
- end
547
- end
548
-
549
- context "when an array that matches the Pact::Term is found" do
550
- subject { [Pact::Term.new(:matcher => /4/, :generate => '4'),"5","6"] }
551
- let(:actual) { ["4", "5", "6"] }
552
-
553
- it 'includes this in the diff' do
554
- expect(diff(subject, actual)).to eq({})
555
- end
556
- end
557
-
558
- end
559
-
560
- end
561
- end