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.
- data/CHANGELOG.md +37 -1
- data/lib/pact/cli.rb +0 -26
- data/lib/pact/consumer/configuration/configuration_extensions.rb +51 -0
- data/lib/pact/consumer/configuration/mock_service.rb +2 -1
- data/lib/pact/consumer/configuration.rb +0 -1
- data/lib/pact/consumer/consumer_contract_builder.rb +3 -3
- data/lib/pact/consumer/interaction_builder.rb +3 -5
- data/lib/pact/doc/interaction_view_model.rb +9 -6
- data/lib/pact/doc/sort_interactions.rb +1 -1
- data/lib/pact/provider/configuration/configuration_extension.rb +0 -9
- data/lib/pact/provider/rspec.rb +11 -9
- data/lib/pact/version.rb +1 -1
- data/lib/pact.rb +6 -5
- data/pact.gemspec +6 -2
- metadata +57 -304
- data/.gitignore +0 -29
- data/.rspec +0 -2
- data/.ruby-version +0 -1
- data/.travis.yml +0 -8
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -86
- data/README.md +0 -313
- data/Rakefile +0 -9
- data/config.ru +0 -3
- data/documentation/README.md +0 -13
- data/documentation/configuration.md +0 -166
- data/documentation/diff_formatter_embedded.png +0 -0
- data/documentation/diff_formatter_list.png +0 -0
- data/documentation/diff_formatter_unix.png +0 -0
- data/example/animal-service/Gemfile +0 -14
- data/example/animal-service/Gemfile.lock +0 -69
- data/example/animal-service/Rakefile +0 -5
- data/example/animal-service/config.ru +0 -3
- data/example/animal-service/db/animal_db.sqlite3 +0 -0
- data/example/animal-service/lib/animal_service/animal_repository.rb +0 -12
- data/example/animal-service/lib/animal_service/api.rb +0 -28
- data/example/animal-service/lib/animal_service/db.rb +0 -5
- data/example/animal-service/spec/service_consumers/pact_helper.rb +0 -11
- data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +0 -26
- data/example/zoo-app/Gemfile +0 -12
- data/example/zoo-app/Gemfile.lock +0 -63
- data/example/zoo-app/Rakefile +0 -5
- data/example/zoo-app/doc/pacts/markdown/README.md +0 -3
- data/example/zoo-app/doc/pacts/markdown/Zoo App - Animal Service.md +0 -75
- data/example/zoo-app/lib/zoo_app/animal_service_client.rb +0 -40
- data/example/zoo-app/lib/zoo_app/models/alligator.rb +0 -15
- data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +0 -67
- data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +0 -71
- data/example/zoo-app/spec/service_providers/pact_helper.rb +0 -15
- data/example/zoo-app/spec/spec_helper.rb +0 -6
- data/lib/pact/configuration.rb +0 -195
- data/lib/pact/consumer/app_manager.rb +0 -158
- data/lib/pact/consumer/interactions_filter.rb +0 -48
- data/lib/pact/consumer/mock_service/app.rb +0 -82
- data/lib/pact/consumer/mock_service/interaction_delete.rb +0 -33
- data/lib/pact/consumer/mock_service/interaction_list.rb +0 -76
- data/lib/pact/consumer/mock_service/interaction_mismatch.rb +0 -73
- data/lib/pact/consumer/mock_service/interaction_post.rb +0 -31
- data/lib/pact/consumer/mock_service/interaction_replay.rb +0 -139
- data/lib/pact/consumer/mock_service/log_get.rb +0 -28
- data/lib/pact/consumer/mock_service/missing_interactions_get.rb +0 -30
- data/lib/pact/consumer/mock_service/mock_service_administration_endpoint.rb +0 -31
- data/lib/pact/consumer/mock_service/pact_post.rb +0 -33
- data/lib/pact/consumer/mock_service/rack_request_helper.rb +0 -51
- data/lib/pact/consumer/mock_service/verification_get.rb +0 -68
- data/lib/pact/consumer/mock_service.rb +0 -2
- data/lib/pact/consumer/mock_service_client.rb +0 -65
- data/lib/pact/consumer/mock_service_interaction_expectation.rb +0 -37
- data/lib/pact/consumer/request.rb +0 -27
- data/lib/pact/consumer/server.rb +0 -90
- data/lib/pact/consumer_contract/consumer_contract.rb +0 -115
- data/lib/pact/consumer_contract/consumer_contract_writer.rb +0 -84
- data/lib/pact/consumer_contract/file_name.rb +0 -19
- data/lib/pact/consumer_contract/headers.rb +0 -51
- data/lib/pact/consumer_contract/interaction.rb +0 -67
- data/lib/pact/consumer_contract/pact_file.rb +0 -24
- data/lib/pact/consumer_contract/request.rb +0 -73
- data/lib/pact/consumer_contract/service_consumer.rb +0 -28
- data/lib/pact/consumer_contract/service_provider.rb +0 -28
- data/lib/pact/consumer_contract.rb +0 -1
- data/lib/pact/logging.rb +0 -14
- data/lib/pact/matchers/actual_type.rb +0 -16
- data/lib/pact/matchers/base_difference.rb +0 -37
- data/lib/pact/matchers/differ.rb +0 -153
- data/lib/pact/matchers/difference.rb +0 -13
- data/lib/pact/matchers/difference_indicator.rb +0 -26
- data/lib/pact/matchers/embedded_diff_formatter.rb +0 -62
- data/lib/pact/matchers/expected_type.rb +0 -35
- data/lib/pact/matchers/index_not_found.rb +0 -15
- data/lib/pact/matchers/list_diff_formatter.rb +0 -101
- data/lib/pact/matchers/matchers.rb +0 -139
- data/lib/pact/matchers/no_diff_indicator.rb +0 -18
- data/lib/pact/matchers/regexp_difference.rb +0 -13
- data/lib/pact/matchers/type_difference.rb +0 -16
- data/lib/pact/matchers/unexpected_index.rb +0 -11
- data/lib/pact/matchers/unexpected_key.rb +0 -11
- data/lib/pact/matchers/unix_diff_formatter.rb +0 -114
- data/lib/pact/matchers.rb +0 -1
- data/lib/pact/reification.rb +0 -28
- data/lib/pact/rspec.rb +0 -53
- data/lib/pact/shared/active_support_support.rb +0 -51
- data/lib/pact/shared/dsl.rb +0 -76
- data/lib/pact/shared/jruby_support.rb +0 -18
- data/lib/pact/shared/json_differ.rb +0 -15
- data/lib/pact/shared/key_not_found.rb +0 -15
- data/lib/pact/shared/null_expectation.rb +0 -31
- data/lib/pact/shared/request.rb +0 -80
- data/lib/pact/shared/text_differ.rb +0 -14
- data/lib/pact/something_like.rb +0 -49
- data/lib/pact/symbolize_keys.rb +0 -12
- data/lib/pact/term.rb +0 -85
- data/scratchpad.rb +0 -52
- data/spec/features/consumption_spec.rb +0 -114
- data/spec/features/production_spec.rb +0 -155
- data/spec/features/provider_states/zebras.rb +0 -28
- data/spec/integration/consumer_spec.rb +0 -212
- data/spec/integration/pact/consumer_configuration_spec.rb +0 -66
- data/spec/integration/pact/provider_configuration_spec.rb +0 -25
- data/spec/lib/pact/cli_spec.rb +0 -47
- data/spec/lib/pact/configuration_spec.rb +0 -297
- data/spec/lib/pact/consumer/app_manager_spec.rb +0 -41
- data/spec/lib/pact/consumer/configuration_spec.rb +0 -57
- data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +0 -69
- data/spec/lib/pact/consumer/interaction_builder_spec.rb +0 -91
- data/spec/lib/pact/consumer/interactions_spec.rb +0 -64
- data/spec/lib/pact/consumer/mock_service/app_spec.rb +0 -52
- data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +0 -78
- data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +0 -70
- data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +0 -12
- data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +0 -88
- data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +0 -142
- data/spec/lib/pact/consumer/mock_service_client_spec.rb +0 -88
- data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +0 -54
- data/spec/lib/pact/consumer/request_spec.rb +0 -24
- data/spec/lib/pact/consumer/service_consumer_spec.rb +0 -11
- data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +0 -58
- data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -180
- data/spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb +0 -111
- data/spec/lib/pact/consumer_contract/headers_spec.rb +0 -107
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -107
- data/spec/lib/pact/consumer_contract/request_spec.rb +0 -329
- data/spec/lib/pact/doc/generator_spec.rb +0 -84
- data/spec/lib/pact/doc/interaction_view_model_spec.rb +0 -132
- data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +0 -29
- data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +0 -29
- data/spec/lib/pact/matchers/differ_spec.rb +0 -214
- data/spec/lib/pact/matchers/difference_spec.rb +0 -22
- data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +0 -90
- data/spec/lib/pact/matchers/index_not_found_spec.rb +0 -21
- data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +0 -114
- data/spec/lib/pact/matchers/matchers_spec.rb +0 -500
- data/spec/lib/pact/matchers/regexp_difference_spec.rb +0 -20
- data/spec/lib/pact/matchers/type_difference_spec.rb +0 -34
- data/spec/lib/pact/matchers/unexpected_index_spec.rb +0 -20
- data/spec/lib/pact/matchers/unexpected_key_spec.rb +0 -20
- data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +0 -216
- data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +0 -30
- data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +0 -43
- data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +0 -21
- data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +0 -108
- data/spec/lib/pact/provider/configuration_spec.rb +0 -50
- data/spec/lib/pact/provider/matchers/messages_spec.rb +0 -116
- data/spec/lib/pact/provider/pact_helper_locator_spec.rb +0 -54
- data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +0 -19
- data/spec/lib/pact/provider/request_spec.rb +0 -78
- data/spec/lib/pact/provider/rspec/formatter_rspec_2_spec.rb +0 -68
- data/spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb +0 -72
- data/spec/lib/pact/provider/rspec_spec.rb +0 -55
- data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +0 -89
- data/spec/lib/pact/provider/state/provider_state_proxy_spec.rb +0 -80
- data/spec/lib/pact/provider/state/provider_state_spec.rb +0 -213
- data/spec/lib/pact/provider/world_spec.rb +0 -41
- data/spec/lib/pact/reification_spec.rb +0 -67
- data/spec/lib/pact/shared/dsl_spec.rb +0 -86
- data/spec/lib/pact/shared/json_differ_spec.rb +0 -36
- data/spec/lib/pact/shared/key_not_found_spec.rb +0 -20
- data/spec/lib/pact/shared/request_spec.rb +0 -111
- data/spec/lib/pact/shared/text_differ_spec.rb +0 -54
- data/spec/lib/pact/something_like_spec.rb +0 -21
- data/spec/lib/pact/tasks/task_helper_spec.rb +0 -74
- data/spec/lib/pact/tasks/verification_task_spec.rb +0 -75
- data/spec/lib/pact/term_spec.rb +0 -89
- data/spec/pact_specification/compliance-1.0.0.rb +0 -47
- data/spec/spec_helper.rb +0 -22
- data/spec/standalone/consumer_fail_test.rb +0 -55
- data/spec/standalone/consumer_pass_test.rb +0 -51
- data/spec/support/a_consumer-a_producer.json +0 -32
- data/spec/support/a_consumer-a_provider.json +0 -32
- data/spec/support/active_support_if_configured.rb +0 -6
- data/spec/support/app_for_config_ru.rb +0 -4
- data/spec/support/consumer_contract_template.json +0 -24
- data/spec/support/dsl_spec_support.rb +0 -7
- data/spec/support/factories.rb +0 -82
- data/spec/support/generated_index.md +0 -4
- data/spec/support/generated_markdown.md +0 -55
- data/spec/support/interaction_view_model.json +0 -63
- data/spec/support/interaction_view_model_with_terms.json +0 -50
- data/spec/support/markdown_pact.json +0 -48
- data/spec/support/missing_provider_states_output.txt +0 -25
- data/spec/support/options.json +0 -21
- data/spec/support/options_app.rb +0 -15
- data/spec/support/pact_helper.rb +0 -57
- data/spec/support/shared_examples_for_request.rb +0 -94
- data/spec/support/spec_support.rb +0 -20
- data/spec/support/stubbing.json +0 -22
- data/spec/support/stubbing_using_allow.rb +0 -29
- data/spec/support/term.json +0 -48
- data/spec/support/test_app_fail.json +0 -61
- data/spec/support/test_app_pass.json +0 -38
- data/spec/support/test_app_with_right_content_type_differ.json +0 -23
- data/tasks/pact-test.rake +0 -109
- 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
|
data/lib/pact/shared/request.rb
DELETED
|
@@ -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
|
data/lib/pact/something_like.rb
DELETED
|
@@ -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
|
-
|
data/lib/pact/symbolize_keys.rb
DELETED
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
|