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,31 +0,0 @@
1
- module Pact
2
- class NullExpectation
3
- def to_s
4
- "<No expectation>"
5
- end
6
-
7
- def ==(other_object)
8
- other_object.is_a? NullExpectation
9
- end
10
-
11
- def ===(other_object)
12
- other_object.is_a? NullExpectation
13
- end
14
-
15
- def eql?(other_object)
16
- self == other_object
17
- end
18
-
19
- def hash
20
- 2934820948209428748274238642672
21
- end
22
-
23
- def empty?
24
- true
25
- end
26
-
27
- def nil?
28
- true
29
- end
30
- end
31
- end
@@ -1,80 +0,0 @@
1
- require 'pact/matchers'
2
- require 'pact/symbolize_keys'
3
- require 'pact/consumer_contract/headers'
4
-
5
- module Pact
6
-
7
- module Request
8
-
9
- class Base
10
- include Pact::Matchers
11
- include Pact::SymbolizeKeys
12
- extend Pact::Matchers
13
-
14
- attr_reader :method, :path, :headers, :body, :query, :options
15
-
16
- def initialize(method, path, headers, body, query)
17
- @method = method.to_s
18
- @path = path.chomp('/')
19
- @headers = Hash === headers ? Headers.new(headers) : headers # Could be a NullExpectation - TODO make this more elegant
20
- @body = body
21
- @query = query
22
- end
23
-
24
- def to_json(options = {})
25
- as_json.to_json(options)
26
- end
27
-
28
- def as_json options = {}
29
- to_hash
30
- end
31
-
32
- def to_hash
33
- hash = {
34
- method: method,
35
- path: path,
36
- }
37
-
38
- hash.merge!(query: query) unless query.is_a? self.class.key_not_found.class
39
- hash.merge!(headers: headers) unless headers.is_a? self.class.key_not_found.class
40
- hash.merge!(body: body) unless body.is_a? self.class.key_not_found.class
41
- hash
42
- end
43
-
44
- def method_and_path
45
- "#{method.upcase} #{full_path}"
46
- end
47
-
48
- def full_path
49
- display_path + display_query
50
- end
51
-
52
- def content_type
53
- return nil if headers.is_a? self.class.key_not_found.class
54
- headers['Content-Type']
55
- end
56
-
57
- protected
58
-
59
- def self.key_not_found
60
- raise NotImplementedError
61
- end
62
-
63
- def to_hash_without_body
64
- keep_keys = [:method, :path, :headers, :query]
65
- as_json.reject{ |key, value| !keep_keys.include? key }.tap do | hash |
66
- hash[:method] = method.upcase
67
- end
68
- end
69
-
70
- def display_path
71
- path.empty? ? "/" : path
72
- end
73
-
74
- def display_query
75
- (query.nil? || query.empty?) ? '' : "?#{Pact::Reification.from_term(query)}"
76
- end
77
-
78
- end
79
- end
80
- end
@@ -1,14 +0,0 @@
1
- require 'pact/matchers/matchers'
2
- require 'pact/matchers/difference'
3
-
4
- module Pact
5
- class TextDiffer
6
-
7
- extend Matchers
8
-
9
- def self.call expected, actual, options = {}
10
- diff expected, actual, options
11
- end
12
-
13
- end
14
- end
@@ -1,49 +0,0 @@
1
- require 'pact/symbolize_keys'
2
- module Pact
3
-
4
- # Specifies that the actual object should be considered a match if
5
- # it includes the same keys, and the values of the keys are of the same class.
6
-
7
- class SomethingLike
8
- include SymbolizeKeys
9
-
10
- attr_reader :contents
11
-
12
- def initialize contents
13
- @contents = contents
14
- end
15
-
16
- def to_hash
17
- {
18
- :json_class => self.class.name,
19
- :contents => contents
20
- }
21
- end
22
-
23
- def as_json
24
- to_hash
25
- end
26
-
27
- def to_json opts = {}
28
- as_json.to_json opts
29
- end
30
-
31
- def self.json_create hash
32
- new(symbolize_keys(hash)[:contents])
33
- end
34
-
35
- def eq other
36
- self == other
37
- end
38
-
39
- def == other
40
- other.is_a?(SomethingLike) && other.contents == self.contents
41
- end
42
-
43
- def generate
44
- contents
45
- end
46
- end
47
- end
48
-
49
-
@@ -1,12 +0,0 @@
1
- module Pact
2
- module SymbolizeKeys
3
-
4
- def self.included(base)
5
- base.extend(self)
6
- end
7
-
8
- def symbolize_keys hash
9
- hash.inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo }
10
- end
11
- end
12
- end
data/lib/pact/term.rb DELETED
@@ -1,85 +0,0 @@
1
- require 'pact/shared/active_support_support'
2
- require 'json/add/regexp'
3
-
4
- module Pact
5
- class Term
6
-
7
- include Pact::ActiveSupportSupport
8
-
9
- attr_reader :generate, :matcher
10
-
11
- def self.json_create(obj)
12
- new(generate: obj['data']['generate'], matcher: obj['data']['matcher'])
13
- end
14
-
15
- def self.unpack_regexps source
16
- case source
17
- when Pact::Term then source.matcher
18
- when Array then unpack_regexps_from_array source
19
- when Hash then unpack_regexps_from_hash source
20
- else
21
- source
22
- end
23
- end
24
-
25
- def initialize(attributes = {})
26
- @generate = attributes[:generate]
27
- @matcher = attributes[:matcher]
28
- raise "Please specify a matcher for the Term" unless @matcher != nil
29
- raise "Please specify a value to generate for the Term" unless @generate != nil
30
- raise "Value to generate \"#{@generate}\" does not match regular expression #{@matcher}" unless @generate =~ @matcher
31
- end
32
-
33
- def to_hash
34
- { json_class: self.class.name, data: { generate: generate, matcher: fix_regexp(matcher)} }
35
- end
36
-
37
- def as_json(options = {})
38
- to_hash
39
- end
40
-
41
-
42
- def to_json(options = {})
43
- as_json.to_json(options)
44
- end
45
-
46
- def match(literal)
47
- literal.respond_to?(:to_s) ? matcher.match(literal.to_s) : nil
48
- end
49
-
50
- def ==(other)
51
- return false unless other.respond_to?(:generate) && other.respond_to?(:matcher)
52
- generate == other.generate && matcher == other.matcher
53
- end
54
-
55
- def to_s
56
- "Pact::Term matcher: #{matcher.inspect}" + (generate.nil? ? "" : " generate: \"#{generate}\"")
57
- end
58
-
59
- def diff_with_actual(actual)
60
- match(actual) ? nil : {
61
- expected: self,
62
- actual: actual
63
- }
64
- end
65
-
66
- def empty?
67
- false
68
- end
69
-
70
- private
71
-
72
- def self.unpack_regexps_from_array source
73
- source.each_with_object([]) do | item, destination |
74
- destination << unpack_regexps(item)
75
- end
76
- end
77
-
78
- def self.unpack_regexps_from_hash source
79
- source.keys.each_with_object({}) do | key, destination |
80
- destination[key] = unpack_regexps source[key]
81
- end
82
- end
83
-
84
- end
85
- end
data/scratchpad.rb DELETED
@@ -1,52 +0,0 @@
1
- Ideas for expectation DSL
2
-
3
- Unfortunately RSpec has already stolen the method "example".
4
- Could use:
5
- eg
6
- ex
7
-
8
- my_provider.
9
- given("a thing exists").
10
- upon_receiving("a request for a thing").with({:method => 'get', :path => '/thing'})
11
- will_respond_with({:body => {
12
- name: ex("Fred"),
13
- age: eg 29,
14
- mobile: eg("0415 134 234", /\d{4} \d{3} \d{3}/),
15
- dob: eg("1983-02-28", match: /\d\d\d\d-\d\d-\d\d/),
16
- driver_licence_number: eg(12345678, size: 8),
17
- children: eg([{name: 'Mary'}])
18
- }})
19
-
20
- eg([ {name: 'Mary'} ]) should match any array where every element has a name String
21
- eg([ {name: example('Mary', size: 4) } ]) should match any array where every element has a 4 letter name
22
-
23
- eg("Fred") could return Pact::Term.new(:matcher => /.+/, :generate => 'Fred')
24
- eg(29) could return Pact::Term.new(:matcher => /\d+/, :generate => 29)
25
-
26
- Need a way to specify a literal empty hash, rather than a hash that matches anything as {} currently does.
27
-
28
- {:something => literal({}) }
29
- {:something => actual({}) }
30
- {:something => empty_hash }
31
-
32
- # Slightly unintuitive behaviour: {} matches any hash, but [] only matches an empty array (or does now we've changed the code). Should [] match any array? How do we then specify an empty array?
33
-
34
- {:something => literal([]) }
35
- {:something => actual([]) }
36
- {:something => empty_array }
37
-
38
-
39
- Pact.build do
40
- {
41
- status: 200,
42
- headers: exactly({
43
-
44
- }),
45
- body: including({
46
- age: literal('12'),
47
- phoneNumber: example("0415 134 234", /\d{4} \d{3} \d{3}/),
48
- favouriteColors:
49
- })
50
- }
51
-
52
- end
@@ -1,114 +0,0 @@
1
- require 'net/http'
2
- require 'pact/consumer'
3
- require 'pact/consumer/rspec'
4
- load 'pact/consumer/world.rb'
5
-
6
- describe "A service consumer side of a pact", :pact => true do
7
-
8
- before do
9
- Pact.clear_configuration
10
- Pact.clear_consumer_world
11
- end
12
-
13
- describe "blah" do
14
- describe "thing" do
15
-
16
- it "goes a little something like this" do
17
-
18
- Pact.service_consumer "Consumer" do
19
- has_pact_with "Alice Service" do
20
- mock_service :alice_service do
21
- verify true
22
- port 1234
23
- end
24
- end
25
-
26
- has_pact_with "Bob" do
27
- mock_service :bob_service do
28
- verify false
29
- port 4321
30
- end
31
- end
32
- end
33
-
34
- alice_service.
35
- upon_receiving("a retrieve Mallory request").with({
36
- method: :get,
37
- path: '/mallory'
38
- }).
39
- will_respond_with({
40
- status: 200,
41
- headers: { 'Content-Type' => 'text/html' },
42
- body: Pact::Term.new(matcher: /Mallory/, generate: 'That is some good Mallory.')
43
- })
44
-
45
- bob_service.
46
- upon_receiving('a create donut request').with({
47
- method: :post,
48
- path: '/donuts',
49
- body: {
50
- "name" => Pact::Term.new(matcher: /Bob/, generate: 'Bob')
51
- },
52
- headers: {'Accept' => 'text/plain', "Content-Type" => 'application/json'}
53
- }).
54
- will_respond_with({
55
- status: 201,
56
- body: 'Donut created.'
57
- })
58
- bob_service.
59
- upon_receiving('a delete charlie request').with({
60
- method: :delete,
61
- path: '/charlie'
62
- }).
63
- will_respond_with({
64
- status: 200,
65
- body: /deleted/
66
- })
67
- bob_service.
68
- upon_receiving('an update alligators request').with({
69
- method: :put,
70
- path: '/alligators',
71
- body: [{"name" => 'Roger' }]
72
- }).
73
- will_respond_with({
74
- status: 200,
75
- body: [{"name" => "Roger", "age" => 20}]
76
- })
77
-
78
-
79
- alice_response = Net::HTTP.get_response(URI('http://localhost:1234/mallory'))
80
-
81
- expect(alice_response.code).to eql '200'
82
- expect(alice_response['Content-Type']).to eql 'text/html'
83
- expect(alice_response.body).to eql 'That is some good Mallory.'
84
-
85
- uri = URI('http://localhost:4321/donuts')
86
- post_req = Net::HTTP::Post.new(uri.path)
87
- post_req['Accept'] = "text/plain"
88
- post_req['Content-Type'] = "application/json"
89
- post_req.body = {"name" => "Bobby"}.to_json
90
- bob_post_response = Net::HTTP.start(uri.hostname, uri.port) do |http|
91
- http.request post_req
92
- end
93
-
94
- expect(bob_post_response.code).to eql '201'
95
- expect(bob_post_response.body).to eql 'Donut created.'
96
-
97
- uri = URI('http://localhost:4321/alligators')
98
- post_req = Net::HTTP::Put.new(uri.path)
99
- post_req['Content-Type'] = "application/json"
100
- post_req.body = [{"name" => "Roger"}].to_json
101
- bob_post_response = Net::HTTP.start(uri.hostname, uri.port) do |http|
102
- http.request post_req
103
- end
104
-
105
- expect(bob_post_response.code).to eql '200'
106
- expect(bob_post_response.body).to eql([{"name" => "Roger", "age" => 20}].to_json)
107
-
108
- expect{ bob_service.verify('goes a little something like this') }.to raise_error /do not match/
109
- end
110
-
111
- end
112
- end
113
- end
114
-
@@ -1,155 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/provider/rspec'
3
- require 'pact/consumer_contract'
4
- require 'features/provider_states/zebras'
5
-
6
-
7
- module Pact::Provider
8
-
9
- describe "A service production side of a pact" do
10
-
11
- class ServiceUnderTest
12
-
13
- def call(env)
14
- case env['PATH_INFO']
15
- when '/donuts'
16
- [201, {'Content-Type' => 'application/json'}, { message: "Donut created." }.to_json]
17
- when '/charlie'
18
- [200, {'Content-Type' => 'application/json'}, { message: "Your charlie has been deleted" }.to_json]
19
- end
20
- end
21
-
22
- end
23
-
24
- class ServiceUnderTestWithFixture
25
-
26
- def find_zebra_names
27
- #simulate loading data from a database
28
- data = JSON.load(File.read('tmp/a_mock_database.json'))
29
- data.collect{ | zebra | zebra['name'] }
30
- end
31
-
32
- def call(env)
33
- case env['PATH_INFO']
34
- when "/zebra_names"
35
- [200, {'Content-Type' => 'application/json'}, { names: find_zebra_names }.to_json]
36
- end
37
- end
38
-
39
- end
40
-
41
- pact = Pact::ConsumerContract.from_json <<-EOS
42
- {
43
- "consumer" : { "name" : "a consumer"},
44
- "provider" : { "name" : "a provider"},
45
- "interactions" : [
46
- {
47
- "description": "donut creation request",
48
- "request": {
49
- "method": "post",
50
- "path": "/donuts"
51
- },
52
- "response": {
53
- "body": {"message": "Donut created."},
54
- "status": 201
55
- }
56
- },
57
- {
58
- "description": "charlie deletion request",
59
- "request": {
60
- "method": "delete",
61
- "path": "/charlie"
62
- },
63
- "response": {
64
- "body": {
65
- "message": {
66
- "json_class": "Regexp",
67
- "o": 0,
68
- "s": "deleted"
69
- }
70
- },
71
- "status": 200
72
- }
73
- }
74
- ]
75
- }
76
- EOS
77
-
78
- before :all do
79
- Pact.service_provider "My Provider" do
80
- app { ServiceUnderTest.new }
81
- end
82
- end
83
-
84
- honour_consumer_contract pact
85
-
86
- end
87
-
88
- describe "with a provider_state" do
89
-
90
- context "that is a symbol" do
91
- consumer_contract = Pact::ConsumerContract.from_json <<-EOS
92
- {
93
- "consumer" : { "name" : "the-wild-beast-store"},
94
- "provider" : { "name" : "provider"},
95
- "interactions" : [
96
- {
97
- "description": "donut creation request",
98
- "request": {
99
- "method": "delete",
100
- "path": "/zebra_names"
101
- },
102
- "response": {
103
- "body": {"names": ["Jason", "Sarah"]},
104
- "status": 200
105
- },
106
- "provider_state" : "the_zebras_are_here"
107
- }
108
- ]
109
- }
110
- EOS
111
-
112
- before :all do
113
- Pact.service_provider "My Provider" do
114
- app { ServiceUnderTestWithFixture.new }
115
- end
116
- end
117
-
118
-
119
- honour_consumer_contract consumer_contract
120
- end
121
-
122
- context "that is a string" do
123
- consumer_contract = Pact::ConsumerContract.from_json <<-EOS
124
- {
125
- "consumer" : { "name" : "some consumer"},
126
- "provider" : { "name" : "provider"},
127
- "interactions" : [
128
- {
129
- "description": "donut creation request",
130
- "request": {
131
- "method": "post",
132
- "path": "/zebra_names"
133
- },
134
- "response": {
135
- "body": {"names": ["Mark", "Gertrude"]},
136
- "status": 200
137
- },
138
- "provider_state" : "some other zebras are here"
139
- }
140
- ]
141
- }
142
- EOS
143
-
144
- before :all do
145
- Pact.service_provider "ServiceUnderTestWithFixture" do
146
- app { ServiceUnderTestWithFixture.new }
147
- end
148
- end
149
-
150
-
151
- honour_consumer_contract consumer_contract
152
- end
153
-
154
- end
155
- end
@@ -1,28 +0,0 @@
1
- require 'json'
2
- require 'fileutils'
3
-
4
- Pact.provider_states_for 'the-wild-beast-store' do
5
-
6
- provider_state :the_zebras_are_here do
7
- set_up do
8
- FileUtils.mkdir_p 'tmp'
9
- some_data = [{'name' => 'Jason'},{'name' => 'Sarah'}]
10
- File.open("tmp/a_mock_database.json", "w") { |file| file << some_data.to_json }
11
- end
12
-
13
- tear_down do
14
- FileUtils.rm_rf("tmp/a_mock_database.json")
15
- end
16
- end
17
- end
18
-
19
- Pact.provider_state "some other zebras are here" do
20
- set_up do
21
- some_data = [{'name' => 'Mark'},{'name' => 'Gertrude'}]
22
- File.open("tmp/a_mock_database.json", "w") { |file| file << some_data.to_json }
23
- end
24
-
25
- tear_down do
26
- FileUtils.rm_rf("tmp/a_mock_database.json")
27
- end
28
- end