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.
Files changed (212) hide show
  1. data/CHANGELOG.md +37 -1
  2. data/lib/pact/cli.rb +0 -26
  3. data/lib/pact/consumer/configuration/configuration_extensions.rb +51 -0
  4. data/lib/pact/consumer/configuration/mock_service.rb +2 -1
  5. data/lib/pact/consumer/configuration.rb +0 -1
  6. data/lib/pact/consumer/consumer_contract_builder.rb +3 -3
  7. data/lib/pact/consumer/interaction_builder.rb +3 -5
  8. data/lib/pact/doc/interaction_view_model.rb +9 -6
  9. data/lib/pact/doc/sort_interactions.rb +1 -1
  10. data/lib/pact/provider/configuration/configuration_extension.rb +0 -9
  11. data/lib/pact/provider/rspec.rb +11 -9
  12. data/lib/pact/version.rb +1 -1
  13. data/lib/pact.rb +6 -5
  14. data/pact.gemspec +6 -2
  15. metadata +57 -304
  16. data/.gitignore +0 -29
  17. data/.rspec +0 -2
  18. data/.ruby-version +0 -1
  19. data/.travis.yml +0 -8
  20. data/Gemfile +0 -4
  21. data/Gemfile.lock +0 -86
  22. data/README.md +0 -313
  23. data/Rakefile +0 -9
  24. data/config.ru +0 -3
  25. data/documentation/README.md +0 -13
  26. data/documentation/configuration.md +0 -166
  27. data/documentation/diff_formatter_embedded.png +0 -0
  28. data/documentation/diff_formatter_list.png +0 -0
  29. data/documentation/diff_formatter_unix.png +0 -0
  30. data/example/animal-service/Gemfile +0 -14
  31. data/example/animal-service/Gemfile.lock +0 -69
  32. data/example/animal-service/Rakefile +0 -5
  33. data/example/animal-service/config.ru +0 -3
  34. data/example/animal-service/db/animal_db.sqlite3 +0 -0
  35. data/example/animal-service/lib/animal_service/animal_repository.rb +0 -12
  36. data/example/animal-service/lib/animal_service/api.rb +0 -28
  37. data/example/animal-service/lib/animal_service/db.rb +0 -5
  38. data/example/animal-service/spec/service_consumers/pact_helper.rb +0 -11
  39. data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +0 -26
  40. data/example/zoo-app/Gemfile +0 -12
  41. data/example/zoo-app/Gemfile.lock +0 -63
  42. data/example/zoo-app/Rakefile +0 -5
  43. data/example/zoo-app/doc/pacts/markdown/README.md +0 -3
  44. data/example/zoo-app/doc/pacts/markdown/Zoo App - Animal Service.md +0 -75
  45. data/example/zoo-app/lib/zoo_app/animal_service_client.rb +0 -40
  46. data/example/zoo-app/lib/zoo_app/models/alligator.rb +0 -15
  47. data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +0 -67
  48. data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +0 -71
  49. data/example/zoo-app/spec/service_providers/pact_helper.rb +0 -15
  50. data/example/zoo-app/spec/spec_helper.rb +0 -6
  51. data/lib/pact/configuration.rb +0 -195
  52. data/lib/pact/consumer/app_manager.rb +0 -158
  53. data/lib/pact/consumer/interactions_filter.rb +0 -48
  54. data/lib/pact/consumer/mock_service/app.rb +0 -82
  55. data/lib/pact/consumer/mock_service/interaction_delete.rb +0 -33
  56. data/lib/pact/consumer/mock_service/interaction_list.rb +0 -76
  57. data/lib/pact/consumer/mock_service/interaction_mismatch.rb +0 -73
  58. data/lib/pact/consumer/mock_service/interaction_post.rb +0 -31
  59. data/lib/pact/consumer/mock_service/interaction_replay.rb +0 -139
  60. data/lib/pact/consumer/mock_service/log_get.rb +0 -28
  61. data/lib/pact/consumer/mock_service/missing_interactions_get.rb +0 -30
  62. data/lib/pact/consumer/mock_service/mock_service_administration_endpoint.rb +0 -31
  63. data/lib/pact/consumer/mock_service/pact_post.rb +0 -33
  64. data/lib/pact/consumer/mock_service/rack_request_helper.rb +0 -51
  65. data/lib/pact/consumer/mock_service/verification_get.rb +0 -68
  66. data/lib/pact/consumer/mock_service.rb +0 -2
  67. data/lib/pact/consumer/mock_service_client.rb +0 -65
  68. data/lib/pact/consumer/mock_service_interaction_expectation.rb +0 -37
  69. data/lib/pact/consumer/request.rb +0 -27
  70. data/lib/pact/consumer/server.rb +0 -90
  71. data/lib/pact/consumer_contract/consumer_contract.rb +0 -115
  72. data/lib/pact/consumer_contract/consumer_contract_writer.rb +0 -84
  73. data/lib/pact/consumer_contract/file_name.rb +0 -19
  74. data/lib/pact/consumer_contract/headers.rb +0 -51
  75. data/lib/pact/consumer_contract/interaction.rb +0 -67
  76. data/lib/pact/consumer_contract/pact_file.rb +0 -24
  77. data/lib/pact/consumer_contract/request.rb +0 -73
  78. data/lib/pact/consumer_contract/service_consumer.rb +0 -28
  79. data/lib/pact/consumer_contract/service_provider.rb +0 -28
  80. data/lib/pact/consumer_contract.rb +0 -1
  81. data/lib/pact/logging.rb +0 -14
  82. data/lib/pact/matchers/actual_type.rb +0 -16
  83. data/lib/pact/matchers/base_difference.rb +0 -37
  84. data/lib/pact/matchers/differ.rb +0 -153
  85. data/lib/pact/matchers/difference.rb +0 -13
  86. data/lib/pact/matchers/difference_indicator.rb +0 -26
  87. data/lib/pact/matchers/embedded_diff_formatter.rb +0 -62
  88. data/lib/pact/matchers/expected_type.rb +0 -35
  89. data/lib/pact/matchers/index_not_found.rb +0 -15
  90. data/lib/pact/matchers/list_diff_formatter.rb +0 -101
  91. data/lib/pact/matchers/matchers.rb +0 -139
  92. data/lib/pact/matchers/no_diff_indicator.rb +0 -18
  93. data/lib/pact/matchers/regexp_difference.rb +0 -13
  94. data/lib/pact/matchers/type_difference.rb +0 -16
  95. data/lib/pact/matchers/unexpected_index.rb +0 -11
  96. data/lib/pact/matchers/unexpected_key.rb +0 -11
  97. data/lib/pact/matchers/unix_diff_formatter.rb +0 -114
  98. data/lib/pact/matchers.rb +0 -1
  99. data/lib/pact/reification.rb +0 -28
  100. data/lib/pact/rspec.rb +0 -53
  101. data/lib/pact/shared/active_support_support.rb +0 -51
  102. data/lib/pact/shared/dsl.rb +0 -76
  103. data/lib/pact/shared/jruby_support.rb +0 -18
  104. data/lib/pact/shared/json_differ.rb +0 -15
  105. data/lib/pact/shared/key_not_found.rb +0 -15
  106. data/lib/pact/shared/null_expectation.rb +0 -31
  107. data/lib/pact/shared/request.rb +0 -80
  108. data/lib/pact/shared/text_differ.rb +0 -14
  109. data/lib/pact/something_like.rb +0 -49
  110. data/lib/pact/symbolize_keys.rb +0 -12
  111. data/lib/pact/term.rb +0 -85
  112. data/scratchpad.rb +0 -52
  113. data/spec/features/consumption_spec.rb +0 -114
  114. data/spec/features/production_spec.rb +0 -155
  115. data/spec/features/provider_states/zebras.rb +0 -28
  116. data/spec/integration/consumer_spec.rb +0 -212
  117. data/spec/integration/pact/consumer_configuration_spec.rb +0 -66
  118. data/spec/integration/pact/provider_configuration_spec.rb +0 -25
  119. data/spec/lib/pact/cli_spec.rb +0 -47
  120. data/spec/lib/pact/configuration_spec.rb +0 -297
  121. data/spec/lib/pact/consumer/app_manager_spec.rb +0 -41
  122. data/spec/lib/pact/consumer/configuration_spec.rb +0 -57
  123. data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +0 -69
  124. data/spec/lib/pact/consumer/interaction_builder_spec.rb +0 -91
  125. data/spec/lib/pact/consumer/interactions_spec.rb +0 -64
  126. data/spec/lib/pact/consumer/mock_service/app_spec.rb +0 -52
  127. data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +0 -78
  128. data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +0 -70
  129. data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +0 -12
  130. data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +0 -88
  131. data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +0 -142
  132. data/spec/lib/pact/consumer/mock_service_client_spec.rb +0 -88
  133. data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +0 -54
  134. data/spec/lib/pact/consumer/request_spec.rb +0 -24
  135. data/spec/lib/pact/consumer/service_consumer_spec.rb +0 -11
  136. data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +0 -58
  137. data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -180
  138. data/spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb +0 -111
  139. data/spec/lib/pact/consumer_contract/headers_spec.rb +0 -107
  140. data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -107
  141. data/spec/lib/pact/consumer_contract/request_spec.rb +0 -329
  142. data/spec/lib/pact/doc/generator_spec.rb +0 -84
  143. data/spec/lib/pact/doc/interaction_view_model_spec.rb +0 -132
  144. data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +0 -29
  145. data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +0 -29
  146. data/spec/lib/pact/matchers/differ_spec.rb +0 -214
  147. data/spec/lib/pact/matchers/difference_spec.rb +0 -22
  148. data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +0 -90
  149. data/spec/lib/pact/matchers/index_not_found_spec.rb +0 -21
  150. data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +0 -114
  151. data/spec/lib/pact/matchers/matchers_spec.rb +0 -500
  152. data/spec/lib/pact/matchers/regexp_difference_spec.rb +0 -20
  153. data/spec/lib/pact/matchers/type_difference_spec.rb +0 -34
  154. data/spec/lib/pact/matchers/unexpected_index_spec.rb +0 -20
  155. data/spec/lib/pact/matchers/unexpected_key_spec.rb +0 -20
  156. data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +0 -216
  157. data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +0 -30
  158. data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +0 -43
  159. data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +0 -21
  160. data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +0 -108
  161. data/spec/lib/pact/provider/configuration_spec.rb +0 -50
  162. data/spec/lib/pact/provider/matchers/messages_spec.rb +0 -116
  163. data/spec/lib/pact/provider/pact_helper_locator_spec.rb +0 -54
  164. data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +0 -19
  165. data/spec/lib/pact/provider/request_spec.rb +0 -78
  166. data/spec/lib/pact/provider/rspec/formatter_rspec_2_spec.rb +0 -68
  167. data/spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb +0 -72
  168. data/spec/lib/pact/provider/rspec_spec.rb +0 -55
  169. data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +0 -89
  170. data/spec/lib/pact/provider/state/provider_state_proxy_spec.rb +0 -80
  171. data/spec/lib/pact/provider/state/provider_state_spec.rb +0 -213
  172. data/spec/lib/pact/provider/world_spec.rb +0 -41
  173. data/spec/lib/pact/reification_spec.rb +0 -67
  174. data/spec/lib/pact/shared/dsl_spec.rb +0 -86
  175. data/spec/lib/pact/shared/json_differ_spec.rb +0 -36
  176. data/spec/lib/pact/shared/key_not_found_spec.rb +0 -20
  177. data/spec/lib/pact/shared/request_spec.rb +0 -111
  178. data/spec/lib/pact/shared/text_differ_spec.rb +0 -54
  179. data/spec/lib/pact/something_like_spec.rb +0 -21
  180. data/spec/lib/pact/tasks/task_helper_spec.rb +0 -74
  181. data/spec/lib/pact/tasks/verification_task_spec.rb +0 -75
  182. data/spec/lib/pact/term_spec.rb +0 -89
  183. data/spec/pact_specification/compliance-1.0.0.rb +0 -47
  184. data/spec/spec_helper.rb +0 -22
  185. data/spec/standalone/consumer_fail_test.rb +0 -55
  186. data/spec/standalone/consumer_pass_test.rb +0 -51
  187. data/spec/support/a_consumer-a_producer.json +0 -32
  188. data/spec/support/a_consumer-a_provider.json +0 -32
  189. data/spec/support/active_support_if_configured.rb +0 -6
  190. data/spec/support/app_for_config_ru.rb +0 -4
  191. data/spec/support/consumer_contract_template.json +0 -24
  192. data/spec/support/dsl_spec_support.rb +0 -7
  193. data/spec/support/factories.rb +0 -82
  194. data/spec/support/generated_index.md +0 -4
  195. data/spec/support/generated_markdown.md +0 -55
  196. data/spec/support/interaction_view_model.json +0 -63
  197. data/spec/support/interaction_view_model_with_terms.json +0 -50
  198. data/spec/support/markdown_pact.json +0 -48
  199. data/spec/support/missing_provider_states_output.txt +0 -25
  200. data/spec/support/options.json +0 -21
  201. data/spec/support/options_app.rb +0 -15
  202. data/spec/support/pact_helper.rb +0 -57
  203. data/spec/support/shared_examples_for_request.rb +0 -94
  204. data/spec/support/spec_support.rb +0 -20
  205. data/spec/support/stubbing.json +0 -22
  206. data/spec/support/stubbing_using_allow.rb +0 -29
  207. data/spec/support/term.json +0 -48
  208. data/spec/support/test_app_fail.json +0 -61
  209. data/spec/support/test_app_pass.json +0 -38
  210. data/spec/support/test_app_with_right_content_type_differ.json +0 -23
  211. data/tasks/pact-test.rake +0 -109
  212. data/tasks/spec.rake +0 -8
@@ -1,132 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/doc/interaction_view_model'
3
-
4
- module Pact
5
- module Doc
6
- describe InteractionViewModel do
7
-
8
- let(:consumer_contract) { Pact::ConsumerContract.from_uri './spec/support/interaction_view_model.json'}
9
-
10
- let(:interaction_with_request_with_body_and_headers) { consumer_contract.find_interaction description: "a request with a body and headers" }
11
- let(:interaction_with_request_without_body_and_headers) { consumer_contract.find_interaction description: "a request with an empty body and empty headers" }
12
- let(:interaction_with_response_with_body_and_headers) { consumer_contract.find_interaction description: "a response with a body and headers" }
13
- let(:interaction_with_response_without_body_and_headers) { consumer_contract.find_interaction description: "a response with an empty body and empty headers" }
14
-
15
-
16
- subject { InteractionViewModel.new interaction, consumer_contract}
17
-
18
- describe "request" do
19
-
20
- let(:interaction) { interaction_with_request_with_body_and_headers }
21
-
22
- it "includes the method" do
23
- expect(subject.request).to include('"method"')
24
- expect(subject.request).to include('"get"')
25
- end
26
-
27
- it "includes the body" do
28
- expect(subject.request).to include('"body"')
29
- expect(subject.request).to include('"a body"')
30
- end
31
-
32
- it "includes the headers" do
33
- expect(subject.request).to include('"headers"')
34
- expect(subject.request).to include('"a header"')
35
- end
36
-
37
- it "includes the query" do
38
- expect(subject.request).to include('"query"')
39
- expect(subject.request).to include('"some=thing"')
40
- end
41
-
42
- it "includes the path" do
43
- expect(subject.request).to include('"path"')
44
- expect(subject.request).to include('"/path"')
45
- end
46
-
47
- it "renders the keys in a meaningful order" do
48
- expect(subject.request).to match /"method".*"path".*"query".*"headers".*"body"/m
49
- end
50
-
51
- context "when the body hash is empty" do
52
-
53
- let(:interaction) { interaction_with_request_without_body_and_headers }
54
-
55
- it "includes the body" do
56
- expect(subject.request).to include("body")
57
- end
58
- end
59
- context "when the headers hash is empty" do
60
-
61
- let(:interaction) { interaction_with_request_without_body_and_headers }
62
-
63
- it "does not include the headers" do
64
- expect(subject.request).to_not include("headers")
65
- end
66
- end
67
-
68
- context "when a Pact::Term is present" do
69
- let(:consumer_contract) { Pact::ConsumerContract.from_uri './spec/support/interaction_view_model_with_terms.json'}
70
- let(:interaction) { consumer_contract.interactions.first }
71
-
72
- it "uses the generated value" do
73
- expect(subject.request).to_not include("Term")
74
- expect(subject.request).to include("sunny")
75
- end
76
- end
77
- end
78
-
79
- describe "response" do
80
-
81
- let(:interaction) { interaction_with_response_with_body_and_headers }
82
-
83
- it "includes the status" do
84
- expect(subject.response).to include('"status"')
85
- end
86
-
87
- it "includes the body" do
88
- expect(subject.response).to include('"body"')
89
- expect(subject.response).to include('"a body"')
90
- end
91
- it "includes the headers" do
92
- expect(subject.response).to include('"headers"')
93
- expect(subject.response).to include('"a header"')
94
- end
95
-
96
- it "renders the keys in a meaningful order" do
97
- expect(subject.response).to match /"status".*"headers".*"body"/m
98
- end
99
-
100
- context "when the body hash is empty" do
101
-
102
- let(:interaction) { interaction_with_response_without_body_and_headers }
103
-
104
- it "does not include the body" do
105
- expect(subject.response).to_not include("body")
106
- end
107
- end
108
-
109
- context "when the headers hash is empty" do
110
-
111
- let(:interaction) { interaction_with_response_without_body_and_headers }
112
-
113
- it "does not include the headers" do
114
- expect(subject.response).to_not include("headers")
115
- end
116
- end
117
-
118
- context "when a Pact::Term is present" do
119
- let(:consumer_contract) { Pact::ConsumerContract.from_uri './spec/support/interaction_view_model_with_terms.json'}
120
- let(:interaction) { consumer_contract.interactions.first }
121
-
122
- it "uses the generated value" do
123
- expect(subject.response).to_not include("Term")
124
- expect(subject.response).to include("rainy")
125
- end
126
- end
127
- end
128
-
129
-
130
- end
131
- end
132
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/doc/markdown/consumer_contract_renderer'
3
-
4
- module Pact
5
- module Doc
6
- module Markdown
7
- describe ConsumerContractRenderer do
8
-
9
- subject { ConsumerContractRenderer.new(consumer_contract) }
10
- let(:consumer_contract) { Pact::ConsumerContract.from_uri './spec/support/markdown_pact.json' }
11
-
12
- let(:expected_output) { File.read("./spec/support/generated_markdown.md") }
13
-
14
- describe "#call" do
15
- it "renders an interaction" do
16
- expect(subject.call).to eq(expected_output)
17
- end
18
- end
19
-
20
- describe ".call" do
21
- it "renders an interaction" do
22
- expect(ConsumerContractRenderer.call consumer_contract).to eq(expected_output)
23
- end
24
- end
25
-
26
- end
27
- end
28
- end
29
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/doc/markdown/index_renderer'
3
-
4
- module Pact
5
- module Doc
6
- module Markdown
7
- describe IndexRenderer do
8
-
9
- let(:consumer_name) { "Some Consumer" }
10
- let(:docs) { {"Some Provider" => "Some Provider.md", "Some other provider" => "Some other provider.md"} }
11
- let(:subject) { IndexRenderer.new(consumer_name, docs) }
12
- let(:expected_content) { File.read('./spec/support/generated_index.md')}
13
-
14
- describe "#call" do
15
- it "renders the index" do
16
- expect(subject.call).to eq expected_content
17
- end
18
- end
19
-
20
- describe ".call" do
21
- it "renders the index" do
22
- expect(IndexRenderer.call(consumer_name, docs) ).to eq expected_content
23
- end
24
- end
25
-
26
- end
27
- end
28
- end
29
- end
@@ -1,214 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # Ripped from spec/rspec/expectations/differ_spec.rb in rspec-expectations 2.14.3
4
-
5
- require 'spec_helper'
6
- require 'ostruct'
7
-
8
- module Pact
9
- module Matchers
10
- describe Differ do
11
- context "without --color" do
12
-
13
- let(:differ) { Pact::Matchers::Differ.new }
14
-
15
- # color disabled context
16
-
17
- describe '#diff_as_string' do
18
- subject { differ.diff_as_string(@expected, @actual) }
19
- it "outputs unified diff of two strings" do
20
- @expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
21
- @actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
22
- expect(subject).to eql(<<-'EOD')
23
-
24
-
25
- @@ -1,6 +1,6 @@
26
- foo
27
- -zap
28
- bar
29
- +zap
30
- this
31
- is
32
- soo
33
- @@ -9,6 +9,5 @@
34
- equal
35
- insert
36
- a
37
- -another
38
- line
39
- EOD
40
-
41
- end
42
- if RUBY_VERSION.to_f > 1.9
43
- it 'copes with encoded strings', :pending => (Diff::LCS::VERSION < '1.2.2') do
44
- @expected="Tu avec carté {count} itém has".encode('UTF-16LE')
45
- @actual="Tu avec carte {count} item has".encode('UTF-16LE')
46
- expect(subject).to eql(<<-EOD.encode('UTF-16LE'))
47
-
48
- @@ -1,2 +1,2 @@
49
- -Tu avec carte {count} item has
50
- +Tu avec carté {count} itém has
51
- EOD
52
- end
53
- it 'copes with encoded strings', :pending => (Diff::LCS::VERSION >= '1.2.2') do
54
- @expected="Tu avec carté {count} itém has".encode('UTF-16LE')
55
- @actual="Tu avec carte {count} item has".encode('UTF-16LE')
56
- expect(subject).to eql 'Could not produce a diff because of the encoding of the string (UTF-16LE)'
57
- end
58
- it 'ouputs a message when encountering differently encoded strings' do
59
- @expected="Tu avec carté {count} itém has".encode('UTF-16LE')
60
- @actual="Tu avec carte {count} item has"
61
- expect(subject).to eql 'Could not produce a diff because the encoding of the actual string (UTF-8) differs from the encoding of the expected string (UTF-16LE)'
62
- end
63
- end
64
- end
65
-
66
- describe '#diff_as_object' do
67
- it "outputs unified diff message of two objects" do
68
- animal_class = Class.new do
69
- def initialize(name, species)
70
- @name, @species = name, species
71
- end
72
-
73
- def inspect
74
- <<-EOA
75
- <Animal
76
- name=#{@name},
77
- species=#{@species}
78
- >
79
- EOA
80
- end
81
- end
82
-
83
- expected = animal_class.new "bob", "giraffe"
84
- actual = animal_class.new "bob", "tortoise"
85
-
86
- expected_diff = <<'EOD'
87
-
88
- @@ -1,5 +1,5 @@
89
- <Animal
90
- name=bob,
91
- - species=tortoise
92
- + species=giraffe
93
- >
94
- EOD
95
-
96
- diff = differ.diff_as_object(expected,actual)
97
- expect(diff).to eq expected_diff
98
- end
99
-
100
- it "outputs unified diff message of two arrays" do
101
- expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
102
- actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
103
-
104
- expected_diff = <<'EOD'
105
-
106
-
107
- @@ -5,7 +5,7 @@
108
- :metasyntactic,
109
- "variable",
110
- :delta,
111
- - "tango",
112
- + "charlie",
113
- :width,
114
- - "very wide"]
115
- + "quite wide"]
116
- EOD
117
-
118
- diff = differ.diff_as_object(expected,actual)
119
- expect(diff).to eq expected_diff
120
- end
121
-
122
- it "outputs unified diff message of two hashes" do
123
- expected = { :foo => 'bar', :baz => 'quux', :metasyntactic => 'variable', :delta => 'charlie', :width =>'quite wide' }
124
- actual = { :foo => 'bar', :metasyntactic => 'variable', :delta => 'charlotte', :width =>'quite wide' }
125
-
126
- expected_diff = <<'EOD'
127
-
128
- @@ -1,4 +1,5 @@
129
- -:delta => "charlotte",
130
- +:baz => "quux",
131
- +:delta => "charlie",
132
- :foo => "bar",
133
- :metasyntactic => "variable",
134
- :width => "quite wide"
135
- EOD
136
-
137
- diff = differ.diff_as_object(expected,actual)
138
- expect(diff).to eq expected_diff
139
- end
140
-
141
- it 'outputs unified diff messaoge of two hashes with differing encoding' do
142
- expected_diff = %Q{
143
- @@ -1,2 +1,2 @@
144
- -"a" => "a"
145
- #{ (RUBY_VERSION.to_f > 1.8) ? %Q{+"ö" => "ö"} : '+"\303\266" => "\303\266"' }
146
- }
147
-
148
- diff = differ.diff_as_object({'ö' => 'ö'}, {'a' => 'a'})
149
- expect(diff).to eq expected_diff
150
- end
151
-
152
- it "outputs unified diff message of two hashes with object keys" do
153
- expected_diff = %Q{
154
- @@ -1,2 +1,2 @@
155
- -["a", "c"] => "b"
156
- +["d", "c"] => "b"
157
- }
158
-
159
- diff = differ.diff_as_object({ ['d','c'] => 'b'}, { ['a','c'] => 'b' })
160
- expect(diff).to eq expected_diff
161
- end
162
-
163
- it "outputs unified diff of single line strings" do
164
- expected = "this is one string"
165
- actual = "this is another string"
166
-
167
- expected_diff = <<'EOD'
168
-
169
- @@ -1,2 +1,2 @@
170
- -"this is another string"
171
- +"this is one string"
172
- EOD
173
-
174
- diff = differ.diff_as_object(expected,actual)
175
- expect(diff).to eq expected_diff
176
- end
177
-
178
- it "outputs unified diff of multi line strings" do
179
- expected = "this is:\n one string"
180
- actual = "this is:\n another string"
181
-
182
- expected_diff = <<'EOD'
183
-
184
- @@ -1,3 +1,3 @@
185
- this is:
186
- - another string
187
- + one string
188
- EOD
189
-
190
- diff = differ.diff_as_object(expected,actual)
191
- expect(diff).to eq expected_diff
192
- end
193
- end
194
- end
195
-
196
- context "with --color" do
197
-
198
- let(:differ) { Pact::Matchers::Differ.new(true) }
199
-
200
- it "outputs colored diffs" do
201
- expected = "foo bar baz"
202
- actual = "foo bang baz"
203
- expected_diff = "\n\e[34m@@ -1,2 +1,2 @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"
204
-
205
-
206
- diff = differ.diff_as_string(expected,actual)
207
- expect(diff).to eq expected_diff
208
- end
209
- end
210
-
211
- end
212
- end
213
- end
214
-
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers/difference'
3
-
4
- module Pact
5
- module Matchers
6
- describe Difference do
7
-
8
- describe "#as_json" do
9
-
10
- context "when something other than a regexp is expected" do
11
-
12
- subject { Difference.new("apple", 'pear').as_json }
13
-
14
- it "indicates that the actual was intended 'to eq'" do
15
- expect(subject).to eq({:EXPECTED => "apple", :ACTUAL => "pear"})
16
- end
17
- end
18
-
19
- end
20
- end
21
- end
22
- end
@@ -1,90 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers/embedded_diff_formatter'
3
- require 'pact/matchers/type_difference'
4
- require 'pact/matchers/expected_type'
5
- require 'pact/matchers/actual_type'
6
-
7
- module Pact
8
- module Matchers
9
- describe EmbeddedDiffFormatter do
10
-
11
- let(:diff) do
12
- {
13
- :something => TypeDifference.new(ExpectedType.new("Fred"), ActualType.new(1))
14
- }
15
- end
16
-
17
- subject { EmbeddedDiffFormatter.call(diff, options) }
18
-
19
- let(:options) { { colour: colour }}
20
- let(:expected_coloured) { '"' + ::Term::ANSIColor.red("expected_type") + '":'}
21
- let(:actual_coloured) { '"' + ::Term::ANSIColor.green("actual_type") + '":'}
22
-
23
- describe ".call" do
24
-
25
- let(:colour) { false }
26
-
27
- context "when color_enabled is true" do
28
-
29
- let(:colour) { true }
30
-
31
- it "returns nicely formatted json" do
32
- expect(subject.split("\n").size).to eq 6
33
- end
34
-
35
- it "returns a string displaying the diff in colour" do
36
- expect(subject).to include expected_coloured
37
- expect(subject).to include actual_coloured
38
- end
39
- end
40
-
41
- context "when color_enabled is false" do
42
-
43
- let(:colour) { false }
44
-
45
- it "returns nicely formatted json" do
46
- expect(subject.split("\n").size).to eq 6
47
- end
48
-
49
- it "returns a string displaying the diff without colour" do
50
- expect(subject).to_not include expected_coloured
51
- expect(subject).to_not include actual_coloured
52
- end
53
- end
54
-
55
- context "with a Pact::Term" do
56
- let(:diff) { {thing: Difference.new(Pact::Term.new(generate: "Joe", matcher: /Jo/), "Mary")} }
57
-
58
- xit "displays the matcher from the Pact::Term" do
59
- expect(subject).to_not include("Pact::Term")
60
- expect(subject).to include("/Jo/")
61
- end
62
-
63
- end
64
-
65
- context "when no options are specified" do
66
- subject { EmbeddedDiffFormatter.call(diff) }
67
-
68
- context "when Pact.configuration.color_enabled is true" do
69
- it "returns a string displaying the diff in colour" do
70
- expect(Pact.configuration).to receive(:color_enabled).and_return(true)
71
- expect(subject).to include expected_coloured
72
- expect(subject).to include actual_coloured
73
- end
74
- end
75
-
76
- context "when Pact.configuration.color_enabled is false" do
77
- it "returns a string displaying the diff without colour" do
78
- expect(Pact.configuration).to receive(:color_enabled).and_return(false)
79
- expect(subject).to_not include expected_coloured
80
- expect(subject).to_not include actual_coloured
81
- end
82
- end
83
-
84
- end
85
- end
86
-
87
- end
88
-
89
- end
90
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers/index_not_found'
3
-
4
- module Pact
5
- describe IndexNotFound do
6
-
7
- describe "#as_json" do
8
- it "returns a string representation of the object" do
9
- expect(subject.as_json).to eq subject.to_s
10
- end
11
- end
12
-
13
- describe "#to_json" do
14
- it "serialises the object to JSON" do
15
- expect(subject.to_json).to eq "\"#{subject.to_s}\""
16
- end
17
- end
18
-
19
- end
20
-
21
- end
@@ -1,114 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers/list_diff_formatter'
3
- require 'pact/matchers/matchers'
4
-
5
- module Pact
6
- module Matchers
7
- describe ListDiffFormatter do
8
-
9
- describe ".call" do
10
- subject{ ListDiffFormatter.call(diff, {}) }
11
-
12
- context "when using class based matching" do
13
- let(:diff) { {root: TypeDifference.new(ExpectedType.new("Fred"), ActualType.new(1)) } }
14
- let(:expected_output) { <<-EOS
15
- \tAt:
16
- \t\t[:root]
17
- \tExpected type:
18
- \t\tString
19
- \tActual type:
20
- \t\tFixnum
21
- EOS
22
- }
23
-
24
- it "shows the expected and actual classes" do
25
- expect(subject + "\n").to eq(expected_output)
26
- end
27
-
28
- end
29
-
30
- context "when there is an unmatched regexp" do
31
- let(:diff) { {root: RegexpDifference.new(/fr.*ed/, "mary") } }
32
- let(:expected_output) { <<-EOS
33
- \tAt:
34
- \t\t[:root]
35
- \tExpected to match:
36
- \t\t/fr.*ed/
37
- \tActual:
38
- \t\t"mary"
39
- EOS
40
- }
41
- it "shows the expected regexp" do
42
- expect(subject + "\n").to eq(expected_output)
43
- end
44
- end
45
-
46
- context "when there is a mismatched value" do
47
- let(:diff) { {root: {"blah" => { 1 => Difference.new("alphabet", "woozle")}}} }
48
- let(:expected_output) { ""}
49
-
50
- it "includes the expected value" do
51
- expect(subject).to match(/Expected:.*"alphabet"/m)
52
- end
53
- it "includes the actual value" do
54
- expect(subject).to match(/Actual:.*"woozle"/m)
55
- end
56
-
57
- it "includes the path" do
58
- expect(subject).to include('[:root]["blah"][1]')
59
- end
60
- end
61
-
62
- context "when there is a missing key" do
63
- let(:expected_hash) { {"abc" => {"def" => [1,2]}}}
64
- let(:diff) { {root: {"blah" => { 1 => Difference.new(expected_hash, Pact::KeyNotFound.new )}}} }
65
- let(:expected_output) { ""}
66
-
67
- it "includes the expected value" do
68
- expect(subject).to match(/Missing key with value\:.*\{/m)
69
- end
70
-
71
- it "includes the path" do
72
- expect(subject).to include('[:root]["blah"][1]')
73
- end
74
- end
75
-
76
- context "when there is a missing index" do
77
- let(:diff) { [NoDiffIndicator.new, Difference.new(1, IndexNotFound.new )]}
78
- it "includes the expected value" do
79
- expect(subject).to match(/Missing.*1/m)
80
- end
81
-
82
- it "includes the path" do
83
- expect(subject).to include('[1]')
84
- end
85
- end
86
-
87
- context "when there is an unexpected index" do
88
- let(:diff) { [NoDiffIndicator.new, Difference.new(UnexpectedIndex.new, 2), Difference.new(UnexpectedIndex.new, "b")]}
89
- it "includes the unexpected value" do
90
- expect(subject).to include("Array contained unexpected item:")
91
- end
92
-
93
- it "includes the path" do
94
- expect(subject).to include('[1]')
95
- expect(subject).to include('[2]')
96
- end
97
- end
98
-
99
- context "when there is an unexpected key" do
100
- let(:diff) { {"blah" => Difference.new(UnexpectedKey.new, "b")}}
101
- it "includes the unexpected key" do
102
- expect(subject).to include("Hash contained unexpected key with value:")
103
- end
104
-
105
- it "includes the path" do
106
- expect(subject).to include('["blah"]')
107
- end
108
- end
109
-
110
- end
111
-
112
- end
113
- end
114
- end