pact 0.1.28 → 1.3.3

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 (285) hide show
  1. data/.gitignore +2 -1
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +8 -0
  4. data/CHANGELOG.md +374 -0
  5. data/Gemfile +0 -1
  6. data/Gemfile.lock +58 -55
  7. data/README.md +214 -139
  8. data/Rakefile +4 -28
  9. data/bin/pact +2 -2
  10. data/config.ru +3 -0
  11. data/documentation/README.md +13 -0
  12. data/documentation/configuration.md +166 -0
  13. data/documentation/diff_formatter_embedded.png +0 -0
  14. data/documentation/diff_formatter_list.png +0 -0
  15. data/documentation/diff_formatter_unix.png +0 -0
  16. data/example/animal-service/Gemfile +14 -0
  17. data/example/animal-service/Gemfile.lock +69 -0
  18. data/example/animal-service/Rakefile +5 -0
  19. data/example/animal-service/config.ru +3 -0
  20. data/example/animal-service/db/animal_db.sqlite3 +0 -0
  21. data/example/animal-service/lib/animal_service/animal_repository.rb +12 -0
  22. data/example/animal-service/lib/animal_service/api.rb +28 -0
  23. data/example/animal-service/lib/animal_service/db.rb +5 -0
  24. data/example/animal-service/spec/service_consumers/pact_helper.rb +11 -0
  25. data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +26 -0
  26. data/example/zoo-app/Gemfile +12 -0
  27. data/example/zoo-app/Gemfile.lock +63 -0
  28. data/example/zoo-app/Rakefile +5 -0
  29. data/example/zoo-app/doc/pacts/markdown/README.md +3 -0
  30. data/example/zoo-app/doc/pacts/markdown/Zoo App - Animal Service.md +75 -0
  31. data/example/zoo-app/lib/zoo_app/animal_service_client.rb +40 -0
  32. data/example/zoo-app/lib/zoo_app/models/alligator.rb +15 -0
  33. data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +67 -0
  34. data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +71 -0
  35. data/example/zoo-app/spec/service_providers/pact_helper.rb +15 -0
  36. data/example/zoo-app/spec/spec_helper.rb +6 -0
  37. data/lib/pact/cli.rb +138 -0
  38. data/lib/pact/configuration.rb +169 -28
  39. data/lib/pact/consumer/app_manager.rb +10 -29
  40. data/lib/pact/consumer/configuration/configuration_extensions.rb +15 -0
  41. data/lib/pact/consumer/configuration/dsl.rb +12 -0
  42. data/lib/pact/consumer/configuration/mock_service.rb +91 -0
  43. data/lib/pact/consumer/configuration/service_consumer.rb +51 -0
  44. data/lib/pact/consumer/configuration/service_provider.rb +40 -0
  45. data/lib/pact/consumer/configuration.rb +11 -0
  46. data/lib/pact/consumer/consumer_contract_builder.rb +44 -47
  47. data/lib/pact/consumer/interaction_builder.rb +41 -0
  48. data/lib/pact/consumer/interactions_filter.rb +48 -0
  49. data/lib/pact/consumer/mock_service/app.rb +82 -0
  50. data/lib/pact/consumer/mock_service/interaction_delete.rb +33 -0
  51. data/lib/pact/consumer/mock_service/interaction_list.rb +76 -0
  52. data/lib/pact/consumer/mock_service/interaction_mismatch.rb +73 -0
  53. data/lib/pact/consumer/mock_service/interaction_post.rb +31 -0
  54. data/lib/pact/consumer/mock_service/interaction_replay.rb +139 -0
  55. data/lib/pact/consumer/mock_service/log_get.rb +28 -0
  56. data/lib/pact/consumer/mock_service/missing_interactions_get.rb +30 -0
  57. data/lib/pact/consumer/mock_service/mock_service_administration_endpoint.rb +31 -0
  58. data/lib/pact/consumer/mock_service/pact_post.rb +33 -0
  59. data/lib/pact/consumer/mock_service/rack_request_helper.rb +51 -0
  60. data/lib/pact/consumer/mock_service/verification_get.rb +68 -0
  61. data/lib/pact/consumer/mock_service.rb +1 -339
  62. data/lib/pact/consumer/mock_service_client.rb +65 -0
  63. data/lib/pact/consumer/mock_service_interaction_expectation.rb +37 -0
  64. data/lib/pact/consumer/request.rb +27 -0
  65. data/lib/pact/consumer/rspec.rb +9 -19
  66. data/lib/pact/consumer/server.rb +90 -0
  67. data/lib/pact/consumer/spec_hooks.rb +38 -0
  68. data/lib/pact/consumer/world.rb +37 -0
  69. data/lib/pact/consumer.rb +10 -7
  70. data/lib/pact/consumer_contract/consumer_contract.rb +115 -0
  71. data/lib/pact/consumer_contract/consumer_contract_writer.rb +84 -0
  72. data/lib/pact/consumer_contract/file_name.rb +19 -0
  73. data/lib/pact/consumer_contract/headers.rb +51 -0
  74. data/lib/pact/consumer_contract/interaction.rb +67 -0
  75. data/lib/pact/consumer_contract/pact_file.rb +24 -0
  76. data/lib/pact/consumer_contract/request.rb +73 -0
  77. data/lib/pact/consumer_contract/service_consumer.rb +28 -0
  78. data/lib/pact/consumer_contract/service_provider.rb +28 -0
  79. data/lib/pact/consumer_contract.rb +1 -110
  80. data/lib/pact/doc/doc_file.rb +40 -0
  81. data/lib/pact/doc/generate.rb +11 -0
  82. data/lib/pact/doc/generator.rb +82 -0
  83. data/lib/pact/doc/interaction_view_model.rb +114 -0
  84. data/lib/pact/doc/markdown/consumer_contract_renderer.rb +56 -0
  85. data/lib/pact/doc/markdown/generator.rb +26 -0
  86. data/lib/pact/doc/markdown/index_renderer.rb +41 -0
  87. data/lib/pact/doc/markdown/interaction.erb +14 -0
  88. data/lib/pact/doc/markdown/interaction_renderer.rb +38 -0
  89. data/lib/pact/doc/sort_interactions.rb +17 -0
  90. data/lib/pact/matchers/actual_type.rb +16 -0
  91. data/lib/pact/matchers/base_difference.rb +37 -0
  92. data/lib/pact/matchers/differ.rb +153 -0
  93. data/lib/pact/matchers/difference.rb +13 -0
  94. data/lib/pact/matchers/difference_indicator.rb +26 -0
  95. data/lib/pact/matchers/embedded_diff_formatter.rb +62 -0
  96. data/lib/pact/matchers/expected_type.rb +35 -0
  97. data/lib/pact/matchers/index_not_found.rb +15 -0
  98. data/lib/pact/matchers/list_diff_formatter.rb +101 -0
  99. data/lib/pact/matchers/matchers.rb +91 -37
  100. data/lib/pact/matchers/no_diff_indicator.rb +18 -0
  101. data/lib/pact/matchers/regexp_difference.rb +13 -0
  102. data/lib/pact/matchers/type_difference.rb +16 -0
  103. data/lib/pact/matchers/unexpected_index.rb +11 -0
  104. data/lib/pact/matchers/unexpected_key.rb +11 -0
  105. data/lib/pact/matchers/unix_diff_formatter.rb +114 -0
  106. data/lib/pact/project_root.rb +7 -0
  107. data/lib/pact/provider/configuration/configuration_extension.rb +58 -0
  108. data/lib/pact/provider/configuration/dsl.rb +13 -0
  109. data/lib/pact/provider/configuration/pact_verification.rb +46 -0
  110. data/lib/pact/provider/configuration/service_provider_config.rb +16 -0
  111. data/lib/pact/provider/configuration/service_provider_dsl.rb +59 -0
  112. data/lib/pact/provider/configuration.rb +7 -0
  113. data/lib/pact/provider/context.rb +0 -0
  114. data/lib/pact/provider/matchers/messages.rb +45 -0
  115. data/lib/pact/provider/pact_helper_locator.rb +22 -0
  116. data/lib/pact/provider/pact_spec_runner.rb +123 -0
  117. data/lib/pact/provider/pact_verification.rb +17 -0
  118. data/lib/pact/provider/print_missing_provider_states.rb +30 -0
  119. data/lib/pact/provider/request.rb +70 -0
  120. data/lib/pact/provider/rspec/backtrace_formatter.rb +43 -0
  121. data/lib/pact/provider/rspec/custom_options_file +0 -0
  122. data/lib/pact/provider/rspec/formatter_rspec_2.rb +65 -0
  123. data/lib/pact/provider/rspec/formatter_rspec_3.rb +96 -0
  124. data/lib/pact/provider/rspec/matchers.rb +97 -0
  125. data/lib/pact/provider/rspec.rb +181 -0
  126. data/lib/pact/provider/state/provider_state.rb +181 -0
  127. data/lib/pact/provider/state/provider_state_configured_modules.rb +13 -0
  128. data/lib/pact/provider/state/provider_state_manager.rb +42 -0
  129. data/lib/pact/provider/state/provider_state_proxy.rb +39 -0
  130. data/lib/pact/provider/test_methods.rb +47 -0
  131. data/lib/pact/provider/verification_report.rb +36 -0
  132. data/lib/pact/provider/world.rb +23 -0
  133. data/lib/pact/provider.rb +3 -0
  134. data/lib/pact/reification.rb +6 -4
  135. data/lib/pact/rspec.rb +53 -0
  136. data/lib/pact/shared/active_support_support.rb +51 -0
  137. data/lib/pact/shared/dsl.rb +76 -0
  138. data/lib/pact/shared/jruby_support.rb +18 -0
  139. data/lib/pact/shared/json_differ.rb +15 -0
  140. data/lib/pact/shared/key_not_found.rb +15 -0
  141. data/lib/pact/shared/null_expectation.rb +31 -0
  142. data/lib/pact/shared/request.rb +80 -0
  143. data/lib/pact/shared/text_differ.rb +14 -0
  144. data/lib/pact/something_like.rb +49 -0
  145. data/lib/pact/symbolize_keys.rb +12 -0
  146. data/lib/pact/tasks/task_helper.rb +36 -0
  147. data/lib/pact/tasks/verification_task.rb +87 -0
  148. data/lib/pact/tasks.rb +2 -0
  149. data/lib/pact/templates/provider_state.erb +14 -0
  150. data/lib/pact/term.rb +47 -2
  151. data/lib/pact/version.rb +1 -1
  152. data/lib/pact.rb +1 -1
  153. data/lib/tasks/pact.rake +25 -2
  154. data/pact.gemspec +13 -11
  155. data/{scratchpad.txt → scratchpad.rb} +18 -2
  156. data/spec/features/consumption_spec.rb +24 -56
  157. data/spec/features/production_spec.rb +19 -24
  158. data/spec/features/{producer_states → provider_states}/zebras.rb +3 -3
  159. data/spec/integration/consumer_spec.rb +212 -0
  160. data/spec/integration/pact/consumer_configuration_spec.rb +66 -0
  161. data/spec/integration/pact/provider_configuration_spec.rb +25 -0
  162. data/spec/lib/pact/cli_spec.rb +47 -0
  163. data/spec/lib/pact/configuration_spec.rb +269 -7
  164. data/spec/lib/pact/consumer/app_manager_spec.rb +3 -3
  165. data/spec/lib/pact/consumer/configuration_spec.rb +57 -0
  166. data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +52 -70
  167. data/spec/lib/pact/consumer/interaction_builder_spec.rb +91 -0
  168. data/spec/lib/pact/consumer/interactions_spec.rb +64 -0
  169. data/spec/lib/pact/consumer/mock_service/app_spec.rb +52 -0
  170. data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +78 -0
  171. data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +70 -0
  172. data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +12 -0
  173. data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +88 -0
  174. data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +142 -0
  175. data/spec/lib/pact/consumer/mock_service_client_spec.rb +88 -0
  176. data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +54 -0
  177. data/spec/lib/pact/consumer/request_spec.rb +24 -0
  178. data/spec/lib/pact/consumer/service_consumer_spec.rb +1 -1
  179. data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +58 -0
  180. data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +180 -0
  181. data/spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb +111 -0
  182. data/spec/lib/pact/consumer_contract/headers_spec.rb +107 -0
  183. data/spec/lib/pact/consumer_contract/interaction_spec.rb +107 -0
  184. data/spec/lib/pact/{request_spec.rb → consumer_contract/request_spec.rb} +80 -67
  185. data/spec/lib/pact/doc/generator_spec.rb +84 -0
  186. data/spec/lib/pact/doc/interaction_view_model_spec.rb +132 -0
  187. data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +29 -0
  188. data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +29 -0
  189. data/spec/lib/pact/matchers/differ_spec.rb +214 -0
  190. data/spec/lib/pact/matchers/difference_spec.rb +22 -0
  191. data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +90 -0
  192. data/spec/lib/pact/matchers/index_not_found_spec.rb +21 -0
  193. data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +114 -0
  194. data/spec/lib/pact/matchers/matchers_spec.rb +400 -254
  195. data/spec/lib/pact/matchers/regexp_difference_spec.rb +20 -0
  196. data/spec/lib/pact/matchers/type_difference_spec.rb +34 -0
  197. data/spec/lib/pact/matchers/unexpected_index_spec.rb +20 -0
  198. data/spec/lib/pact/matchers/unexpected_key_spec.rb +20 -0
  199. data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +216 -0
  200. data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +30 -0
  201. data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +43 -0
  202. data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +21 -0
  203. data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +108 -0
  204. data/spec/lib/pact/provider/configuration_spec.rb +50 -0
  205. data/spec/lib/pact/provider/matchers/messages_spec.rb +116 -0
  206. data/spec/lib/pact/provider/pact_helper_locator_spec.rb +54 -0
  207. data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +19 -0
  208. data/spec/lib/pact/provider/request_spec.rb +78 -0
  209. data/spec/lib/pact/provider/rspec/formatter_rspec_2_spec.rb +68 -0
  210. data/spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb +72 -0
  211. data/spec/lib/pact/provider/rspec_spec.rb +55 -0
  212. data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +89 -0
  213. data/spec/lib/pact/provider/state/provider_state_proxy_spec.rb +80 -0
  214. data/spec/lib/pact/provider/state/provider_state_spec.rb +213 -0
  215. data/spec/lib/pact/provider/world_spec.rb +41 -0
  216. data/spec/lib/pact/reification_spec.rb +24 -0
  217. data/spec/lib/pact/shared/dsl_spec.rb +86 -0
  218. data/spec/lib/pact/shared/json_differ_spec.rb +36 -0
  219. data/spec/lib/pact/shared/key_not_found_spec.rb +20 -0
  220. data/spec/lib/pact/shared/request_spec.rb +111 -0
  221. data/spec/lib/pact/shared/text_differ_spec.rb +54 -0
  222. data/spec/lib/pact/something_like_spec.rb +21 -0
  223. data/spec/lib/pact/tasks/task_helper_spec.rb +74 -0
  224. data/spec/lib/pact/tasks/verification_task_spec.rb +75 -0
  225. data/spec/lib/pact/term_spec.rb +57 -4
  226. data/spec/pact_specification/compliance-1.0.0.rb +47 -0
  227. data/spec/spec_helper.rb +17 -0
  228. data/spec/standalone/consumer_fail_test.rb +55 -0
  229. data/spec/standalone/consumer_pass_test.rb +51 -0
  230. data/spec/support/a_consumer-a_producer.json +2 -4
  231. data/spec/support/a_consumer-a_provider.json +32 -0
  232. data/spec/support/active_support_if_configured.rb +6 -0
  233. data/spec/support/app_for_config_ru.rb +4 -0
  234. data/spec/support/consumer_contract_template.json +24 -0
  235. data/spec/support/dsl_spec_support.rb +7 -0
  236. data/spec/support/factories.rb +82 -0
  237. data/spec/support/generated_index.md +4 -0
  238. data/spec/support/generated_markdown.md +55 -0
  239. data/spec/support/interaction_view_model.json +63 -0
  240. data/spec/support/interaction_view_model_with_terms.json +50 -0
  241. data/spec/support/markdown_pact.json +48 -0
  242. data/spec/support/missing_provider_states_output.txt +25 -0
  243. data/spec/support/options.json +21 -0
  244. data/spec/support/options_app.rb +15 -0
  245. data/spec/support/pact_helper.rb +57 -0
  246. data/spec/support/shared_examples_for_request.rb +94 -0
  247. data/spec/support/spec_support.rb +20 -0
  248. data/spec/support/stubbing.json +22 -0
  249. data/spec/support/stubbing_using_allow.rb +29 -0
  250. data/spec/support/term.json +48 -0
  251. data/spec/support/test_app_fail.json +41 -2
  252. data/spec/support/test_app_pass.json +19 -2
  253. data/spec/support/test_app_with_right_content_type_differ.json +23 -0
  254. data/tasks/pact-test.rake +98 -8
  255. data/tasks/spec.rake +8 -0
  256. metadata +393 -95
  257. data/lib/pact/app.rb +0 -32
  258. data/lib/pact/consumer/configuration_dsl.rb +0 -71
  259. data/lib/pact/consumer/dsl.rb +0 -98
  260. data/lib/pact/consumer/interaction.rb +0 -70
  261. data/lib/pact/consumer/run_condor.rb +0 -4
  262. data/lib/pact/consumer/run_mock_contract_service.rb +0 -13
  263. data/lib/pact/consumer/service_consumer.rb +0 -22
  264. data/lib/pact/consumer/service_producer.rb +0 -23
  265. data/lib/pact/json_warning.rb +0 -23
  266. data/lib/pact/producer/configuration_dsl.rb +0 -62
  267. data/lib/pact/producer/matchers.rb +0 -22
  268. data/lib/pact/producer/pact_spec_runner.rb +0 -57
  269. data/lib/pact/producer/producer_state.rb +0 -81
  270. data/lib/pact/producer/rspec.rb +0 -127
  271. data/lib/pact/producer/test_methods.rb +0 -89
  272. data/lib/pact/producer.rb +0 -1
  273. data/lib/pact/rake_task.rb +0 -64
  274. data/lib/pact/request.rb +0 -109
  275. data/lib/pact/verification_task.rb +0 -57
  276. data/spec/integration/pact/configuration_spec.rb +0 -65
  277. data/spec/lib/pact/consumer/dsl_spec.rb +0 -52
  278. data/spec/lib/pact/consumer/interaction_spec.rb +0 -108
  279. data/spec/lib/pact/consumer/mock_service_spec.rb +0 -147
  280. data/spec/lib/pact/consumer_contract_spec.rb +0 -125
  281. data/spec/lib/pact/producer/configuration_dsl_spec.rb +0 -101
  282. data/spec/lib/pact/producer/producer_state_spec.rb +0 -103
  283. data/spec/lib/pact/producer/rspec_spec.rb +0 -48
  284. data/spec/lib/pact/verification_task_spec.rb +0 -64
  285. data/spec/support/pact_rake_support.rb +0 -41
@@ -1,354 +1,500 @@
1
1
  require 'spec_helper'
2
- require 'pact/term'
3
2
  require 'pact/matchers'
3
+ require 'pact/consumer_contract/headers'
4
4
 
5
- describe Pact::Matchers do
6
- include Pact::Matchers
5
+ module Pact::Matchers
7
6
 
8
- describe 'structure_diff' do
9
- let(:expected) {
10
- {a: 'a string', b: 1, c: nil, d: [{e: 'thing'}], f: {g: 10}}
11
- }
7
+ describe Pact::Matchers do
8
+ include Pact::Matchers
12
9
 
13
- context "when the classes match" do
14
- let(:actual) { {a: 'another string', b: 2, c: nil, d: [{e: 'something'}], f: {g: 100}} }
15
- it "returns an empty hash" do
16
- expect(structure_diff(expected, actual)).to be_empty
17
- end
18
- end
10
+ # TODO this is an integration test
11
+ describe 'matching headers' do
12
+ let(:expected) { Pact::Headers.new('Content-Type' => 'application/hippo')}
19
13
 
20
- context "when a number is expected" do
21
- let(:expected) { {a: 1} }
22
- #let(:difference) { {a: {expected: 'Fixnum (eg. 1)', actual: 'String ("a string")'}} }
23
- let(:difference) { {a: {expected: {:class => Fixnum, eg: 1 } , actual: {:class => String, :value => 'a string'}}} }
14
+ context "when the headers match in a case insensitive way" do
24
15
 
25
- context "and a string is found" do
26
- let(:actual) { {a: 'a string'}}
27
- it "returns the diff" do
28
- expect(structure_diff(expected, actual)).to eq difference
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
29
21
  end
30
- end
31
- context "and nil is found" do
32
- let(:actual) { {a: nil}}
33
- let(:difference ) { {a: {:expected => {:class => Fixnum, eg: 1}, :actual => nil} } }
34
- it "returns the diff" do
35
- expect(structure_diff(expected, actual)).to eq difference
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
36
29
  end
37
30
  end
38
- context "and a hash is found" do
39
- let(:actual) { {a: {b: 1}} }
40
- let(:difference) { {:a=>{:expected=>{:class=>Fixnum, :eg=>1}, :actual=>{:class=>Hash, :value=>{:b=>1}}}} }
41
- it "returns the diff" do
42
- expect(structure_diff(expected, actual)).to eq difference
43
- end
44
- end
45
- context "and an array is found" do
46
- let(:actual) { {a: [1] } }
47
- let(:difference) { {:a=>{:expected=>{:class=>Fixnum, :eg=>1}, :actual=>{:class=>Array, :value=>[1]}}} }
48
- it "returns the diff" do
49
- expect(structure_diff(expected, actual)).to eq difference
50
- 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
+
51
40
  end
41
+
52
42
  end
53
43
 
54
- context "when an array is expected" do
55
- let(:expected) { [{name: 'Fred'}, {name: 'Mary'}] }
56
- context "when an item with differing class values is found" do
57
- let(:actual) { [{name: 'Fred'}, {name: 1}] }
58
- let(:difference) { [
59
- Pact::Matchers::NO_DIFF_INDICATOR,
60
- {:name => {
61
- :expected=> { :class=>String, :eg=>"Mary" },
62
- :actual=> { :class=>Fixnum, :value=>1} }
63
- }
64
- ]
65
- }
66
- it "returns the diff" do
67
- expect(structure_diff(expected, actual)).to eq difference
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({})
68
52
  end
53
+
69
54
  end
55
+
70
56
  end
71
57
 
58
+ describe 'option {allow_unexpected_keys: false}' do
59
+ context "when an unexpected key is found" do
60
+ let(:expected) { {:a => 1} }
61
+ let(:actual) { {:a => 1, :b => 2} }
62
+ let(:difference) { {:b => Difference.new(Pact::UnexpectedKey.new, 2 )} }
63
+ it "returns it in the diff" do
64
+ expect(diff(expected, actual, allow_unexpected_keys: false)).to eq difference
65
+ end
66
+ end
67
+ end
72
68
 
73
- context "when nil is expected" do
69
+ describe "expecting key to be present with nil value and not finding key" do
74
70
  let(:expected) { {a: nil} }
75
- context "and a string is found" do
76
- let(:actual) { {a: 'a string'} }
77
- let(:difference) { {:a=>{:expected=>nil, :actual=>{:class=>String, :value=>"a string"}}} }
78
- it "returns the diff" do
79
- expect(structure_diff(expected, actual)).to eq difference
80
- end
71
+ let(:actual) { {} }
72
+ let(:difference) { {a: Difference.new(nil, Pact::KeyNotFound.new )} }
73
+ it "returns the key in the diff" do
74
+ expect(diff(expected, actual)).to eq difference
81
75
  end
82
76
  end
83
77
 
84
- context "when a term is expected" do
85
- let(:expected) { {a: Pact::Term.new(:matcher => /p/, :generate => 'apple')} }
86
- context "and a non matching string is found" do
87
- let(:actual) { {a: 'banana'} }
88
- let(:difference) { {:a=>{:expected=>/p/, :actual=>"banana"}} }
89
- it "returns the diff" do
90
- expect(structure_diff(expected, actual)).to eq difference
91
- end
92
- end
78
+ describe "expecting a string matching a regexp and not finding key" do
79
+ let(:expected) { {a: /b/} }
80
+ let(:actual) { {} }
81
+ let(:difference) { {:a=> RegexpDifference.new(/b/, Pact::KeyNotFound.new) } }
82
+ it "returns the diff" do
83
+ expect(diff(expected, actual)).to eq difference
84
+ end
93
85
  end
94
- end
95
86
 
96
- describe 'diffing' do
87
+ describe 'type_diff' do
88
+ let(:expected) {
89
+ {a: 'a string', b: 1, c: nil, d: [{e: 'thing'}], f: {g: 10}, h: false}
90
+ }
97
91
 
98
- context 'where an expected value is a non-empty string' do
99
-
100
- subject { {:a => 'a', :b => 'b'} }
92
+ context "when the classes match" do
93
+ let(:actual) { {a: 'another string', b: 2, c: nil, d: [{e: 'something'}], f: {g: 100}, h: true} }
94
+ let(:difference) { {} }
95
+ it "returns an empty hash" do
96
+ expect(type_diff(expected, actual)).to eq difference
97
+ end
98
+ end
101
99
 
102
- context 'and the actual value is an empty string' do
100
+ context "when a key is not found" do
101
+ let(:actual) { {a: 'blah'} }
102
+ let(:expected) { {b: 'blah'} }
103
+ let(:difference) { {:b=>TypeDifference.new(Pact::ExpectedType.new("blah"), Pact::KeyNotFound.new)} }
104
+ it "returns the difference" do
105
+ expect(type_diff(expected, actual)).to eq difference
106
+ end
107
+ end
103
108
 
104
- let(:actual) { {:a => 'a', :b => ''} }
109
+ context "when a number is expected" do
110
+ let(:expected) { {a: 1} }
111
+ let(:difference) { {a: TypeDifference.new(Pact::ExpectedType.new(1) , Pact::ActualType.new('a string'))} }
105
112
 
106
- it 'includes this in the diff' do
107
- expect(diff(subject, actual)).to eql({:b => {:expected => 'b', :actual => ''}})
113
+ context "and a string is found" do
114
+ let(:actual) { {a: 'a string'}}
115
+ it "returns the diff" do
116
+ expect(type_diff(expected, actual)).to eq difference
117
+ end
108
118
  end
119
+ context "and nil is found" do
120
+ let(:actual) { {a: nil}}
121
+ let(:difference ) { {a: TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new(nil)) } }
122
+ it "returns the diff" do
123
+ expect(type_diff(expected, actual)).to eq difference
124
+ end
125
+ end
126
+ context "and a hash is found" do
127
+ let(:actual) { {a: {b: 1}} }
128
+ let(:difference) { {:a=>TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new({:b=>1})) } }
129
+ it "returns the diff" do
130
+ expect(type_diff(expected, actual)).to eq difference
131
+ end
132
+ end
133
+ context "and an array is found" do
134
+ let(:actual) { {a: [1] } }
135
+ let(:difference) { {:a=>TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new([1]))}}
136
+ it "returns the diff" do
137
+ expect(type_diff(expected, actual)).to eq difference
138
+ end
139
+ end
140
+ end
109
141
 
142
+ context "when an array is expected" do
143
+ let(:expected) { [{name: 'Fred'}, {name: 'Mary'}] }
144
+ context "when an item with differing class values is found" do
145
+ let(:actual) { [{name: 'Fred'}, {name: 1}] }
146
+ let(:difference) { [
147
+ Pact::Matchers::NO_DIFF_INDICATOR,
148
+ {:name =>
149
+ TypeDifference.new(Pact::ExpectedType.new("Mary"), Pact::ActualType.new(1))
150
+ }
151
+ ]
152
+ }
153
+ it "returns the diff" do
154
+ expect(type_diff(expected, actual)).to eq difference
155
+ end
156
+ end
110
157
  end
111
158
 
112
- end
113
159
 
114
- context "when the expected value is a hash" do
115
- subject { {a: 'b'} }
116
- context "when the actual value is an array" do
117
- let(:actual) { [1] }
118
- let(:difference) { {expected: subject, actual: actual} }
119
- it "should return the diff" do
120
- expect(diff(subject, actual)).to eql(difference)
160
+ context "when nil is expected" do
161
+ let(:expected) { {a: nil} }
162
+ context "and a string is found" do
163
+ let(:actual) { {a: 'a string'} }
164
+ let(:difference) { {:a=>TypeDifference.new(Pact::ExpectedType.new(nil), Pact::ActualType.new("a string")) } }
165
+ it "returns the diff" do
166
+ expect(type_diff(expected, actual)).to eq difference
167
+ end
121
168
  end
122
169
  end
123
- context "when the actual value is an hash" do
124
- let(:actual) { {b: 'c'} }
125
- let(:difference) { { a: {expected:"b", actual: nil}} }
126
- it "should return the diff" do
127
- expect(diff(subject, actual)).to eql(difference)
170
+
171
+ context "when a term is expected" do
172
+ let(:expected) { {a: Pact::Term.new(:matcher => /p/, :generate => 'apple')} }
173
+ context "and a non matching string is found" do
174
+ let(:actual) { {a: 'banana'} }
175
+ let(:difference) { {:a=>Pact::Matchers::RegexpDifference.new(/p/,"banana")} }
176
+ it "returns the diff" do
177
+ expect(type_diff(expected, actual)).to eq difference
178
+ end
128
179
  end
129
180
  end
130
- context "when the actual value is an number" do
131
- let(:actual) { 1 }
132
- let(:difference) { {expected: {a: "b"}, actual: 1} }
133
- it "should return the diff" do
134
- expect(diff(subject, actual)).to eql(difference)
181
+
182
+ context "when a term is expected inside a missing hash" do
183
+ let(:expected) { {a: {b: Pact::Term.new(:matcher => /p/, :generate => 'apple')}} }
184
+ context "and a non matching value is found" do
185
+ let(:actual) { {a: nil} }
186
+ let(:difference) { {a: Difference.new({b: /p/}, nil)} }
187
+ it "returns the diff with the regexp unpacked" do
188
+ expect(type_diff(expected, actual)).to eq difference
189
+ end
135
190
  end
136
191
  end
137
- context "when the actual value is a string" do
138
- let(:actual) { "Thing" }
139
- let(:difference) { {expected: subject, actual: actual} }
140
- it "should return the diff" do
141
- expect(diff(subject, actual)).to eql(difference)
192
+
193
+ context "when unexpected keys are allowed" do
194
+ let(:expected) { { a: 'b' } }
195
+ let(:actual) { {a: 'c', d: 'e'} }
196
+ let(:difference) { {} }
197
+ it "returns the diff" do
198
+ expect(type_diff(expected, actual, allow_unexpected_keys: true)).to eq difference
142
199
  end
143
200
  end
144
- context "when the actual value is the same" do
145
- let (:actual) { {a: 'b'} }
146
- it "should return an empty hash" do
147
- expect(diff(subject, actual)).to eql({})
201
+
202
+ context "when unexpected keys are not allowed" do
203
+ let(:expected) { { a: 'b' } }
204
+ let(:actual) { {a: 'c', d: 'e'} }
205
+ let(:difference) { {d: Difference.new(Pact::UnexpectedKey.new, 'e')} }
206
+ it "returns the diff" do
207
+ expect(type_diff(expected, actual, allow_unexpected_keys: false)).to eq difference
148
208
  end
149
209
  end
150
210
  end
151
211
 
152
- context "when the expected value is an array" do
153
- subject { [1] }
154
- context "when the actual value is an array" do
155
- let(:actual) { [2] }
156
- let(:difference) { {expected: subject, actual: actual} }
157
- it "should return the diff" do
158
- expect(diff(subject, actual)).to eql([{expected: 1, actual: 2}])
212
+ describe 'diffing' do
213
+
214
+ context "when expected is longer than the actual" do
215
+ subject { [1,2,3] }
216
+ let(:actual) { [1,2]}
217
+ let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(3, Pact::IndexNotFound.new)] }
218
+ it 'returns the diff' do
219
+ expect(diff(subject, actual)).to eq(difference)
159
220
  end
160
221
  end
161
- context "when the actual value is an hash" do
162
- let(:actual) { {b: 'c'} }
163
- let(:difference) { {expected: subject, actual: actual} }
164
- it "should return the diff" do
165
- expect(diff(subject, actual)).to eql(difference)
222
+
223
+ context "when the different index is in the middle of an array" do
224
+ subject { [1,2,3] }
225
+ let(:actual) { [1,7,3]}
226
+ let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(2, 7), Pact::Matchers::NO_DIFF_INDICATOR] }
227
+ it 'returns the diff' do
228
+ expect(diff(subject, actual)).to eq(difference)
166
229
  end
167
230
  end
168
- context "when the actual value is an number" do
169
- let(:actual) { 1 }
170
- let(:difference) { {expected: subject, actual: actual} }
171
- it "should return the diff" do
172
- expect(diff(subject, actual)).to eql(difference)
231
+
232
+ context "when actual array is longer than the expected" do
233
+ subject { [1] }
234
+ let(:actual) { [1,2]}
235
+ let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(Pact::UnexpectedIndex.new, 2)] }
236
+ it 'returns the diff' do
237
+ expect(diff(subject, actual)).to eq(difference)
173
238
  end
174
239
  end
175
- context "when the actual value is a string" do
176
- let(:actual) { "Thing" }
177
- let(:difference) { {expected: subject, actual: actual} }
178
- it "should return the diff" do
179
- expect(diff(subject, actual)).to eql(difference)
240
+
241
+ context 'where an expected value is a non-empty string' do
242
+
243
+ subject { {:a => 'a', :b => 'b'} }
244
+
245
+ context 'and the actual value is an empty string' do
246
+
247
+ let(:actual) { {:a => 'a', :b => ''} }
248
+
249
+ it 'includes this in the diff' do
250
+ expect(diff(subject, actual)).to eq({:b => Difference.new('b', '')})
251
+ end
252
+
180
253
  end
254
+
181
255
  end
182
- context "when the actual value is the same" do
183
- let (:actual) { [1] }
184
- it "should return an empty hash" do
185
- expect(diff(subject, actual)).to eql({})
256
+
257
+ context "when the expected value is a hash" do
258
+ subject { {a: 'b'} }
259
+ context "when the actual value is an array" do
260
+ let(:actual) { [1] }
261
+ let(:difference) { Difference.new(subject, actual) }
262
+ it "should return the diff" do
263
+ expect(diff(subject, actual)).to eq(difference)
264
+ end
265
+ end
266
+ context "when the actual value is an hash" do
267
+ let(:actual) { {b: 'c'} }
268
+ let(:difference) { { a: Difference.new("b",Pact::KeyNotFound.new)} }
269
+ it "should return the diff" do
270
+ expect(diff(subject, actual)).to eq(difference)
271
+ end
272
+ end
273
+ context "when the actual value is an number" do
274
+ let(:actual) { 1 }
275
+ let(:difference) { Difference.new({a: "b"}, 1) }
276
+ it "should return the diff" do
277
+ expect(diff(subject, actual)).to eq(difference)
278
+ end
279
+ end
280
+ context "when the actual value is a string" do
281
+ let(:actual) { "Thing" }
282
+ let(:difference) { Difference.new(subject, actual) }
283
+ it "should return the diff" do
284
+ expect(diff(subject, actual)).to eq(difference)
285
+ end
286
+ end
287
+ context "when the actual value is the same" do
288
+ let (:actual) { {a: 'b'} }
289
+ it "should return an empty hash" do
290
+ expect(diff(subject, actual)).to eq({})
291
+ end
186
292
  end
187
293
  end
188
- end
189
294
 
190
- context "when the expected value is a string" do
191
- subject { "Thing"}
192
- context "when the actual value is an array" do
193
- let(:actual) { [2] }
194
- let(:difference) { {expected: subject, actual: actual} }
195
- it "should return the diff" do
196
- expect(diff(subject, actual)).to eql(difference)
295
+ context "when the expected value is an array" do
296
+ subject { [1] }
297
+ context "when the actual value is an array" do
298
+ let(:actual) { [2] }
299
+ let(:difference) { [Difference.new(1, 2)] }
300
+ it "should return the diff" do
301
+ expect(diff(subject, actual)).to eq difference
302
+ end
197
303
  end
198
- end
199
- context "when the actual value is an hash" do
200
- let(:actual) { {b: 'c'} }
201
- let(:difference) { {expected: subject, actual: actual} }
202
- it "should return the diff" do
203
- expect(diff(subject, actual)).to eql(difference)
304
+ context "when the actual value is an hash" do
305
+ let(:actual) { {b: 'c'} }
306
+ let(:difference) { Difference.new(subject, actual) }
307
+ it "should return the diff" do
308
+ expect(diff(subject, actual)).to eq(difference)
309
+ end
204
310
  end
205
- end
206
- context "when the actual value is an number" do
207
- let(:actual) { 1 }
208
- let(:difference) { {expected: subject, actual: actual} }
209
- it "should return the diff" do
210
- expect(diff(subject, actual)).to eql(difference)
311
+ context "when the actual value is an number" do
312
+ let(:actual) { 1 }
313
+ let(:difference) { Difference.new(subject, actual) }
314
+ it "should return the diff" do
315
+ expect(diff(subject, actual)).to eq(difference)
316
+ end
211
317
  end
212
- end
213
- context "when the actual value is a string" do
214
- let(:actual) { "Another Thing" }
215
- let(:difference) { {expected: subject, actual: actual} }
216
- it "should return the diff" do
217
- expect(diff(subject, actual)).to eql(difference)
318
+ context "when the actual value is a string" do
319
+ let(:actual) { "Thing" }
320
+ let(:difference) { Difference.new(subject, actual) }
321
+ it "should return the diff" do
322
+ expect(diff(subject, actual)).to eq(difference)
323
+ end
218
324
  end
219
- end
220
- context "when the actual value is the same" do
221
- let (:actual) { "Thing" }
222
- it "should return an empty hash" do
223
- expect(diff(subject, actual)).to eql({})
325
+ context "when the actual value is the same" do
326
+ let (:actual) { [1] }
327
+ it "should return an empty hash" do
328
+ expect(diff(subject, actual)).to eql({})
329
+ end
224
330
  end
225
331
  end
226
- end
227
332
 
228
- context "when the expected value is a number" do
229
- subject { 1 }
230
- let(:difference) { {expected: subject, actual: actual} }
231
- context "when the actual value is an array" do
232
- let(:actual) { [2] }
233
- it "should return the diff" do
234
- expect(diff(subject, actual)).to eql(difference)
333
+ context "when the expected value is a string" do
334
+ subject { "Thing"}
335
+ context "when the actual value is an array" do
336
+ let(:actual) { [2] }
337
+ let(:difference) { Difference.new(subject, actual) }
338
+ it "should return the diff" do
339
+ expect(diff(subject, actual)).to eq(difference)
340
+ end
235
341
  end
236
- end
237
- context "when the actual value is an hash" do
238
- let(:actual) { {b: 'c'} }
239
- it "should return the diff" do
240
- expect(diff(subject, actual)).to eql(difference)
342
+ context "when the actual value is an hash" do
343
+ let(:actual) { {b: 'c'} }
344
+ let(:difference) { Difference.new(subject, actual) }
345
+ it "should return the diff" do
346
+ expect(diff(subject, actual)).to eq(difference)
347
+ end
241
348
  end
242
- end
243
- context "when the actual value is an number" do
244
- let(:actual) { 2 }
245
- it "should return the diff" do
246
- expect(diff(subject, actual)).to eql(difference)
349
+ context "when the actual value is an number" do
350
+ let(:actual) { 1 }
351
+ let(:difference) { Difference.new(subject, actual) }
352
+ it "should return the diff" do
353
+ expect(diff(subject, actual)).to eq(difference)
354
+ end
247
355
  end
248
- end
249
- context "when the actual value is a string" do
250
- let(:actual) { "Another Thing" }
251
- it "should return the diff" do
252
- expect(diff(subject, actual)).to eql(difference)
356
+ context "when the actual value is a string" do
357
+ let(:actual) { "Another Thing" }
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 the same" do
364
+ let (:actual) { "Thing" }
365
+ it "should return an empty hash" do
366
+ expect(diff(subject, actual)).to eq({})
367
+ end
253
368
  end
254
369
  end
255
- context "when the actual value is the same" do
256
- let (:actual) { 1 }
257
- it "should return an empty hash" do
258
- expect(diff(subject, actual)).to eql({})
370
+
371
+ context "when the expected value is a number" do
372
+ subject { 1 }
373
+ let(:difference) { Difference.new(subject, actual) }
374
+ context "when the actual value is an array" do
375
+ let(:actual) { [2] }
376
+ it "should return the diff" do
377
+ expect(diff(subject, actual)).to eq(difference)
378
+ end
379
+ end
380
+ context "when the actual value is an hash" do
381
+ let(:actual) { {b: 'c'} }
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 an number" do
387
+ let(:actual) { 2 }
388
+ it "should return the diff" do
389
+ expect(diff(subject, actual)).to eq(difference)
390
+ end
391
+ end
392
+ context "when the actual value is a string" do
393
+ let(:actual) { "Another Thing" }
394
+ it "should return the diff" do
395
+ expect(diff(subject, actual)).to eq(difference)
396
+ end
397
+ end
398
+ context "when the actual value is the same" do
399
+ let (:actual) { 1 }
400
+ it "should return an empty hash" do
401
+ expect(diff(subject, actual)).to eq({})
402
+ end
259
403
  end
260
404
  end
261
- end
262
405
 
263
- context "when the expected value is a String matcher" do
264
-
265
- end
406
+ context "when the expected value is a String matcher" do
266
407
 
267
- context "when the expected value is a Number matcher" do
268
-
269
- end
270
- context "when the expected value is an array with a matcher" do
271
-
272
- end
273
- context "when the expected value is a hash with a matcher" do
274
-
275
- end
408
+ end
409
+
410
+ context "when the expected value is a Number matcher" do
276
411
 
277
- context "when an expected value is nil but not nil is found" do
278
- subject { {a: nil} }
279
- let(:actual) { {a: 'blah'} }
280
- let(:difference) { {:a=>{:expected=>nil, :actual=>"blah"}} }
281
- it "should return the diff" do
282
- expect(diff(subject, actual)).to eql(difference)
283
412
  end
284
- end
413
+ context "when the expected value is an array with a matcher" do
285
414
 
286
- context "a deep mismatch" do
287
- subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/)}}, f: 1, g: {h: 99}} }
288
- let(:actual) { {a: {b: { c: [1,2]}, d: { e: 'food'}}, f: "thing"} }
289
- let(:difference) { {:a=>{:d=>{:e=>{:expected=>/a/, :actual=>"food"}}}, :f=>{:expected=>1, :actual=>"thing"}, :g=>{:expected=>{:h=>99}, :actual=>nil}} }
415
+ end
416
+ context "when the expected value is a hash with a matcher" do
290
417
 
291
- it 'should return the diff' do
292
- expect(diff(subject, actual)).to eql(difference)
293
418
  end
294
- end
295
419
 
420
+ context "when an expected value is nil but not nil is found" do
421
+ subject { {a: nil} }
422
+ let(:actual) { {a: 'blah'} }
423
+ let(:difference) { {:a=>Difference.new(nil, "blah")} }
424
+ it "should return the diff" do
425
+ expect(diff(subject, actual)).to eq(difference)
426
+ end
427
+ end
296
428
 
297
- context "where a Pact::Term is found that matches the actual value" do
298
- subject { {:a => Pact::Term.new(:matcher => /a/)} }
299
- let(:actual) { {:a => "apple" } }
429
+ context "a deep mismatch" do
430
+ subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/, generate: 'apple')}}, f: 1, g: {h: 99}} }
431
+ let(:actual) { {a: {b: { c: [1,2]}, d: { e: 'food'}}, f: "thing"} }
432
+ let(:difference) { {:a=>{:d=>{:e=> RegexpDifference.new(/a/, "food")}},
433
+ :f=> Difference.new(1, "thing"),
434
+ :g=>Difference.new({:h=>99}, Pact::KeyNotFound.new)} }
300
435
 
301
- it 'does not include this in the diff' do
302
- expect(diff(subject, actual)).to eql({})
436
+ it 'should return the diff' do
437
+ expect(diff(subject, actual)).to eq(difference)
438
+ end
303
439
  end
304
- end
305
440
 
306
- context "where an array is expected at a key inside a hash, but a hash is found" do
307
- subject { {:a => [1,2,3]} }
308
- let(:actual) { {:a => {:b => 1} } }
309
441
 
310
- it 'includes this in the diff' do
311
- expect(diff(subject, actual)).to eql({:a => {:expected => [1,2,3], :actual => {:b => 1}}})
442
+ context "where a Pact::Term is found that matches the actual value" do
443
+ subject { {:a => Pact::Term.new(:matcher => /a/, :generate => 'apple')} }
444
+ let(:actual) { {:a => "apple" } }
445
+
446
+ it 'does not include this in the diff' do
447
+ expect(diff(subject, actual)).to eq({})
448
+ end
312
449
  end
313
- end
314
450
 
315
- context "where an array is expected, but a hash is found" do
316
- subject { {:a => :b} }
317
- let(:actual) { [4,5,6] }
451
+ context "where an array is expected at a key inside a hash, but a hash is found" do
452
+ subject { {:a => [1,2,3]} }
453
+ let(:actual) { {:a => {:b => 1} } }
318
454
 
319
- it 'includes this in the diff' do
320
- expect(diff(subject, actual)).to eql({:expected => {:a => :b}, :actual => [4,5,6] })
455
+ it 'includes this in the diff' do
456
+ expect(diff(subject, actual)).to eq({:a => Difference.new([1,2,3], {:b => 1})})
457
+ end
321
458
  end
322
- end
323
459
 
324
- context "where a hash is expected, but array is found" do
325
- subject { [4,5,6] }
326
- let(:actual) { {:a => :b} }
460
+ context "where an array is expected, but a hash is found" do
461
+ subject { {:a => :b} }
462
+ let(:actual) { [4,5,6] }
327
463
 
328
- it 'includes this in the diff' do
329
- expect(diff(subject, actual)).to eql({:expected => [4,5,6], :actual => {:a => :b} })
464
+ it 'includes this in the diff' do
465
+ expect(diff(subject, actual)).to eq(Difference.new({:a => :b}, [4,5,6] ))
466
+ end
330
467
  end
331
- end
332
468
 
333
- context "when two different arrays are found" do
334
- subject { [4,5,6] }
335
- let(:actual) { [4,6,7] }
336
- let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, {:expected=>5, :actual=>6}, {:expected=>6, :actual=>7}] }
469
+ context "where a hash is expected, but array is found" do
470
+ subject { [4,5,6] }
471
+ let(:actual) { {:a => :b} }
337
472
 
338
- it 'includes this in the diff' do
339
- expect(diff(subject, actual)).to eql(difference)
473
+ it 'includes this in the diff' do
474
+ expect(diff(subject, actual)).to eq(Difference.new([4,5,6],{:a => :b}))
475
+ end
340
476
  end
341
- end
342
477
 
343
- context "when an array that matches the Pact::Term is found" do
344
- subject { [Pact::Term.new(:matcher => /4/),"5","6"] }
345
- let(:actual) { ["4","5","6"] }
478
+ context "when two different arrays are found" do
479
+ subject { [4,5,6] }
480
+ let(:actual) { [4,6,7] }
481
+ let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(5, 6), Difference.new(6, 7)] }
346
482
 
347
- it 'includes this in the diff' do
348
- expect(diff(subject, actual)).to eql({})
483
+ it 'includes this in the diff' do
484
+ expect(diff(subject, actual)).to eq(difference)
485
+ end
349
486
  end
487
+
488
+ context "when an array that matches the Pact::Term is found" do
489
+ subject { [Pact::Term.new(:matcher => /4/, :generate => '4'),"5","6"] }
490
+ let(:actual) { ["4","5","6"] }
491
+
492
+ it 'includes this in the diff' do
493
+ expect(diff(subject, actual)).to eq({})
494
+ end
495
+ end
496
+
350
497
  end
351
498
 
352
499
  end
353
-
354
500
  end