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