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.
- data/.gitignore +2 -1
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +374 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +58 -55
- data/README.md +214 -139
- data/Rakefile +4 -28
- data/bin/pact +2 -2
- data/config.ru +3 -0
- data/documentation/README.md +13 -0
- data/documentation/configuration.md +166 -0
- 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 +14 -0
- data/example/animal-service/Gemfile.lock +69 -0
- data/example/animal-service/Rakefile +5 -0
- data/example/animal-service/config.ru +3 -0
- data/example/animal-service/db/animal_db.sqlite3 +0 -0
- data/example/animal-service/lib/animal_service/animal_repository.rb +12 -0
- data/example/animal-service/lib/animal_service/api.rb +28 -0
- data/example/animal-service/lib/animal_service/db.rb +5 -0
- data/example/animal-service/spec/service_consumers/pact_helper.rb +11 -0
- data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +26 -0
- data/example/zoo-app/Gemfile +12 -0
- data/example/zoo-app/Gemfile.lock +63 -0
- data/example/zoo-app/Rakefile +5 -0
- data/example/zoo-app/doc/pacts/markdown/README.md +3 -0
- data/example/zoo-app/doc/pacts/markdown/Zoo App - Animal Service.md +75 -0
- data/example/zoo-app/lib/zoo_app/animal_service_client.rb +40 -0
- data/example/zoo-app/lib/zoo_app/models/alligator.rb +15 -0
- data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +67 -0
- data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +71 -0
- data/example/zoo-app/spec/service_providers/pact_helper.rb +15 -0
- data/example/zoo-app/spec/spec_helper.rb +6 -0
- data/lib/pact/cli.rb +138 -0
- data/lib/pact/configuration.rb +169 -28
- data/lib/pact/consumer/app_manager.rb +10 -29
- data/lib/pact/consumer/configuration/configuration_extensions.rb +15 -0
- data/lib/pact/consumer/configuration/dsl.rb +12 -0
- data/lib/pact/consumer/configuration/mock_service.rb +91 -0
- data/lib/pact/consumer/configuration/service_consumer.rb +51 -0
- data/lib/pact/consumer/configuration/service_provider.rb +40 -0
- data/lib/pact/consumer/configuration.rb +11 -0
- data/lib/pact/consumer/consumer_contract_builder.rb +44 -47
- data/lib/pact/consumer/interaction_builder.rb +41 -0
- data/lib/pact/consumer/interactions_filter.rb +48 -0
- data/lib/pact/consumer/mock_service/app.rb +82 -0
- data/lib/pact/consumer/mock_service/interaction_delete.rb +33 -0
- data/lib/pact/consumer/mock_service/interaction_list.rb +76 -0
- data/lib/pact/consumer/mock_service/interaction_mismatch.rb +73 -0
- data/lib/pact/consumer/mock_service/interaction_post.rb +31 -0
- data/lib/pact/consumer/mock_service/interaction_replay.rb +139 -0
- data/lib/pact/consumer/mock_service/log_get.rb +28 -0
- data/lib/pact/consumer/mock_service/missing_interactions_get.rb +30 -0
- data/lib/pact/consumer/mock_service/mock_service_administration_endpoint.rb +31 -0
- data/lib/pact/consumer/mock_service/pact_post.rb +33 -0
- data/lib/pact/consumer/mock_service/rack_request_helper.rb +51 -0
- data/lib/pact/consumer/mock_service/verification_get.rb +68 -0
- data/lib/pact/consumer/mock_service.rb +1 -339
- data/lib/pact/consumer/mock_service_client.rb +65 -0
- data/lib/pact/consumer/mock_service_interaction_expectation.rb +37 -0
- data/lib/pact/consumer/request.rb +27 -0
- data/lib/pact/consumer/rspec.rb +9 -19
- data/lib/pact/consumer/server.rb +90 -0
- data/lib/pact/consumer/spec_hooks.rb +38 -0
- data/lib/pact/consumer/world.rb +37 -0
- data/lib/pact/consumer.rb +10 -7
- data/lib/pact/consumer_contract/consumer_contract.rb +115 -0
- data/lib/pact/consumer_contract/consumer_contract_writer.rb +84 -0
- data/lib/pact/consumer_contract/file_name.rb +19 -0
- data/lib/pact/consumer_contract/headers.rb +51 -0
- data/lib/pact/consumer_contract/interaction.rb +67 -0
- data/lib/pact/consumer_contract/pact_file.rb +24 -0
- data/lib/pact/consumer_contract/request.rb +73 -0
- data/lib/pact/consumer_contract/service_consumer.rb +28 -0
- data/lib/pact/consumer_contract/service_provider.rb +28 -0
- data/lib/pact/consumer_contract.rb +1 -110
- data/lib/pact/doc/doc_file.rb +40 -0
- data/lib/pact/doc/generate.rb +11 -0
- data/lib/pact/doc/generator.rb +82 -0
- data/lib/pact/doc/interaction_view_model.rb +114 -0
- data/lib/pact/doc/markdown/consumer_contract_renderer.rb +56 -0
- data/lib/pact/doc/markdown/generator.rb +26 -0
- data/lib/pact/doc/markdown/index_renderer.rb +41 -0
- data/lib/pact/doc/markdown/interaction.erb +14 -0
- data/lib/pact/doc/markdown/interaction_renderer.rb +38 -0
- data/lib/pact/doc/sort_interactions.rb +17 -0
- data/lib/pact/matchers/actual_type.rb +16 -0
- data/lib/pact/matchers/base_difference.rb +37 -0
- data/lib/pact/matchers/differ.rb +153 -0
- data/lib/pact/matchers/difference.rb +13 -0
- data/lib/pact/matchers/difference_indicator.rb +26 -0
- data/lib/pact/matchers/embedded_diff_formatter.rb +62 -0
- data/lib/pact/matchers/expected_type.rb +35 -0
- data/lib/pact/matchers/index_not_found.rb +15 -0
- data/lib/pact/matchers/list_diff_formatter.rb +101 -0
- data/lib/pact/matchers/matchers.rb +91 -37
- data/lib/pact/matchers/no_diff_indicator.rb +18 -0
- data/lib/pact/matchers/regexp_difference.rb +13 -0
- data/lib/pact/matchers/type_difference.rb +16 -0
- data/lib/pact/matchers/unexpected_index.rb +11 -0
- data/lib/pact/matchers/unexpected_key.rb +11 -0
- data/lib/pact/matchers/unix_diff_formatter.rb +114 -0
- data/lib/pact/project_root.rb +7 -0
- data/lib/pact/provider/configuration/configuration_extension.rb +58 -0
- data/lib/pact/provider/configuration/dsl.rb +13 -0
- data/lib/pact/provider/configuration/pact_verification.rb +46 -0
- data/lib/pact/provider/configuration/service_provider_config.rb +16 -0
- data/lib/pact/provider/configuration/service_provider_dsl.rb +59 -0
- data/lib/pact/provider/configuration.rb +7 -0
- data/lib/pact/provider/context.rb +0 -0
- data/lib/pact/provider/matchers/messages.rb +45 -0
- data/lib/pact/provider/pact_helper_locator.rb +22 -0
- data/lib/pact/provider/pact_spec_runner.rb +123 -0
- data/lib/pact/provider/pact_verification.rb +17 -0
- data/lib/pact/provider/print_missing_provider_states.rb +30 -0
- data/lib/pact/provider/request.rb +70 -0
- data/lib/pact/provider/rspec/backtrace_formatter.rb +43 -0
- data/lib/pact/provider/rspec/custom_options_file +0 -0
- data/lib/pact/provider/rspec/formatter_rspec_2.rb +65 -0
- data/lib/pact/provider/rspec/formatter_rspec_3.rb +96 -0
- data/lib/pact/provider/rspec/matchers.rb +97 -0
- data/lib/pact/provider/rspec.rb +181 -0
- data/lib/pact/provider/state/provider_state.rb +181 -0
- data/lib/pact/provider/state/provider_state_configured_modules.rb +13 -0
- data/lib/pact/provider/state/provider_state_manager.rb +42 -0
- data/lib/pact/provider/state/provider_state_proxy.rb +39 -0
- data/lib/pact/provider/test_methods.rb +47 -0
- data/lib/pact/provider/verification_report.rb +36 -0
- data/lib/pact/provider/world.rb +23 -0
- data/lib/pact/provider.rb +3 -0
- data/lib/pact/reification.rb +6 -4
- data/lib/pact/rspec.rb +53 -0
- data/lib/pact/shared/active_support_support.rb +51 -0
- data/lib/pact/shared/dsl.rb +76 -0
- data/lib/pact/shared/jruby_support.rb +18 -0
- data/lib/pact/shared/json_differ.rb +15 -0
- data/lib/pact/shared/key_not_found.rb +15 -0
- data/lib/pact/shared/null_expectation.rb +31 -0
- data/lib/pact/shared/request.rb +80 -0
- data/lib/pact/shared/text_differ.rb +14 -0
- data/lib/pact/something_like.rb +49 -0
- data/lib/pact/symbolize_keys.rb +12 -0
- data/lib/pact/tasks/task_helper.rb +36 -0
- data/lib/pact/tasks/verification_task.rb +87 -0
- data/lib/pact/tasks.rb +2 -0
- data/lib/pact/templates/provider_state.erb +14 -0
- data/lib/pact/term.rb +47 -2
- data/lib/pact/version.rb +1 -1
- data/lib/pact.rb +1 -1
- data/lib/tasks/pact.rake +25 -2
- data/pact.gemspec +13 -11
- data/{scratchpad.txt → scratchpad.rb} +18 -2
- data/spec/features/consumption_spec.rb +24 -56
- data/spec/features/production_spec.rb +19 -24
- data/spec/features/{producer_states → provider_states}/zebras.rb +3 -3
- data/spec/integration/consumer_spec.rb +212 -0
- data/spec/integration/pact/consumer_configuration_spec.rb +66 -0
- data/spec/integration/pact/provider_configuration_spec.rb +25 -0
- data/spec/lib/pact/cli_spec.rb +47 -0
- data/spec/lib/pact/configuration_spec.rb +269 -7
- data/spec/lib/pact/consumer/app_manager_spec.rb +3 -3
- data/spec/lib/pact/consumer/configuration_spec.rb +57 -0
- data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +52 -70
- data/spec/lib/pact/consumer/interaction_builder_spec.rb +91 -0
- data/spec/lib/pact/consumer/interactions_spec.rb +64 -0
- data/spec/lib/pact/consumer/mock_service/app_spec.rb +52 -0
- data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +78 -0
- data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +70 -0
- data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +12 -0
- data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +88 -0
- data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +142 -0
- data/spec/lib/pact/consumer/mock_service_client_spec.rb +88 -0
- data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +54 -0
- data/spec/lib/pact/consumer/request_spec.rb +24 -0
- data/spec/lib/pact/consumer/service_consumer_spec.rb +1 -1
- data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +58 -0
- data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +180 -0
- data/spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb +111 -0
- data/spec/lib/pact/consumer_contract/headers_spec.rb +107 -0
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +107 -0
- data/spec/lib/pact/{request_spec.rb → consumer_contract/request_spec.rb} +80 -67
- data/spec/lib/pact/doc/generator_spec.rb +84 -0
- data/spec/lib/pact/doc/interaction_view_model_spec.rb +132 -0
- data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +29 -0
- data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +29 -0
- data/spec/lib/pact/matchers/differ_spec.rb +214 -0
- data/spec/lib/pact/matchers/difference_spec.rb +22 -0
- data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +90 -0
- data/spec/lib/pact/matchers/index_not_found_spec.rb +21 -0
- data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +114 -0
- data/spec/lib/pact/matchers/matchers_spec.rb +400 -254
- data/spec/lib/pact/matchers/regexp_difference_spec.rb +20 -0
- data/spec/lib/pact/matchers/type_difference_spec.rb +34 -0
- data/spec/lib/pact/matchers/unexpected_index_spec.rb +20 -0
- data/spec/lib/pact/matchers/unexpected_key_spec.rb +20 -0
- data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +216 -0
- data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +30 -0
- data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +43 -0
- data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +21 -0
- data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +108 -0
- data/spec/lib/pact/provider/configuration_spec.rb +50 -0
- data/spec/lib/pact/provider/matchers/messages_spec.rb +116 -0
- data/spec/lib/pact/provider/pact_helper_locator_spec.rb +54 -0
- data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +19 -0
- data/spec/lib/pact/provider/request_spec.rb +78 -0
- data/spec/lib/pact/provider/rspec/formatter_rspec_2_spec.rb +68 -0
- data/spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb +72 -0
- data/spec/lib/pact/provider/rspec_spec.rb +55 -0
- data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +89 -0
- data/spec/lib/pact/provider/state/provider_state_proxy_spec.rb +80 -0
- data/spec/lib/pact/provider/state/provider_state_spec.rb +213 -0
- data/spec/lib/pact/provider/world_spec.rb +41 -0
- data/spec/lib/pact/reification_spec.rb +24 -0
- data/spec/lib/pact/shared/dsl_spec.rb +86 -0
- data/spec/lib/pact/shared/json_differ_spec.rb +36 -0
- data/spec/lib/pact/shared/key_not_found_spec.rb +20 -0
- data/spec/lib/pact/shared/request_spec.rb +111 -0
- data/spec/lib/pact/shared/text_differ_spec.rb +54 -0
- data/spec/lib/pact/something_like_spec.rb +21 -0
- data/spec/lib/pact/tasks/task_helper_spec.rb +74 -0
- data/spec/lib/pact/tasks/verification_task_spec.rb +75 -0
- data/spec/lib/pact/term_spec.rb +57 -4
- data/spec/pact_specification/compliance-1.0.0.rb +47 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/standalone/consumer_fail_test.rb +55 -0
- data/spec/standalone/consumer_pass_test.rb +51 -0
- data/spec/support/a_consumer-a_producer.json +2 -4
- data/spec/support/a_consumer-a_provider.json +32 -0
- data/spec/support/active_support_if_configured.rb +6 -0
- data/spec/support/app_for_config_ru.rb +4 -0
- data/spec/support/consumer_contract_template.json +24 -0
- data/spec/support/dsl_spec_support.rb +7 -0
- data/spec/support/factories.rb +82 -0
- data/spec/support/generated_index.md +4 -0
- data/spec/support/generated_markdown.md +55 -0
- data/spec/support/interaction_view_model.json +63 -0
- data/spec/support/interaction_view_model_with_terms.json +50 -0
- data/spec/support/markdown_pact.json +48 -0
- data/spec/support/missing_provider_states_output.txt +25 -0
- data/spec/support/options.json +21 -0
- data/spec/support/options_app.rb +15 -0
- data/spec/support/pact_helper.rb +57 -0
- data/spec/support/shared_examples_for_request.rb +94 -0
- data/spec/support/spec_support.rb +20 -0
- data/spec/support/stubbing.json +22 -0
- data/spec/support/stubbing_using_allow.rb +29 -0
- data/spec/support/term.json +48 -0
- data/spec/support/test_app_fail.json +41 -2
- data/spec/support/test_app_pass.json +19 -2
- data/spec/support/test_app_with_right_content_type_differ.json +23 -0
- data/tasks/pact-test.rake +98 -8
- data/tasks/spec.rake +8 -0
- metadata +393 -95
- data/lib/pact/app.rb +0 -32
- data/lib/pact/consumer/configuration_dsl.rb +0 -71
- data/lib/pact/consumer/dsl.rb +0 -98
- data/lib/pact/consumer/interaction.rb +0 -70
- data/lib/pact/consumer/run_condor.rb +0 -4
- data/lib/pact/consumer/run_mock_contract_service.rb +0 -13
- data/lib/pact/consumer/service_consumer.rb +0 -22
- data/lib/pact/consumer/service_producer.rb +0 -23
- data/lib/pact/json_warning.rb +0 -23
- data/lib/pact/producer/configuration_dsl.rb +0 -62
- data/lib/pact/producer/matchers.rb +0 -22
- data/lib/pact/producer/pact_spec_runner.rb +0 -57
- data/lib/pact/producer/producer_state.rb +0 -81
- data/lib/pact/producer/rspec.rb +0 -127
- data/lib/pact/producer/test_methods.rb +0 -89
- data/lib/pact/producer.rb +0 -1
- data/lib/pact/rake_task.rb +0 -64
- data/lib/pact/request.rb +0 -109
- data/lib/pact/verification_task.rb +0 -57
- data/spec/integration/pact/configuration_spec.rb +0 -65
- data/spec/lib/pact/consumer/dsl_spec.rb +0 -52
- data/spec/lib/pact/consumer/interaction_spec.rb +0 -108
- data/spec/lib/pact/consumer/mock_service_spec.rb +0 -147
- data/spec/lib/pact/consumer_contract_spec.rb +0 -125
- data/spec/lib/pact/producer/configuration_dsl_spec.rb +0 -101
- data/spec/lib/pact/producer/producer_state_spec.rb +0 -103
- data/spec/lib/pact/producer/rspec_spec.rb +0 -48
- data/spec/lib/pact/verification_task_spec.rb +0 -64
- data/spec/support/pact_rake_support.rb +0 -41
data/lib/pact/app.rb
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require 'find_a_port'
|
|
2
|
-
require 'thor'
|
|
3
|
-
require 'thin'
|
|
4
|
-
require 'thwait'
|
|
5
|
-
require 'pact/consumer'
|
|
6
|
-
|
|
7
|
-
module Pact
|
|
8
|
-
class App < Thor
|
|
9
|
-
|
|
10
|
-
desc 'service', "starts a mock service"
|
|
11
|
-
method_option :port, aliases: "-p", desc: "Port on which to run the service"
|
|
12
|
-
method_option :log, aliases: "-l", desc: "File to which to log output"
|
|
13
|
-
method_option :quiet, aliases: "-q", desc: "If true, no admin messages will be shown"
|
|
14
|
-
|
|
15
|
-
def service
|
|
16
|
-
service_options = {}
|
|
17
|
-
if options[:log]
|
|
18
|
-
log = File.open(options[:log], 'w')
|
|
19
|
-
log.sync = true
|
|
20
|
-
service_options[:log_file] = log
|
|
21
|
-
end
|
|
22
|
-
port = options[:port] || FindAPort.available_port
|
|
23
|
-
mock_service = Consumer::MockService.new(service_options)
|
|
24
|
-
Thin::Server.start("0.0.0.0", port, mock_service)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
def log message
|
|
29
|
-
puts message unless options[:quiet]
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
require_relative 'service_consumer'
|
|
2
|
-
require_relative 'consumer_contract_builders'
|
|
3
|
-
require_relative '../configuration'
|
|
4
|
-
|
|
5
|
-
module Pact
|
|
6
|
-
module Consumer
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
module Configuration
|
|
10
|
-
def add_producer_verification &block
|
|
11
|
-
producer_verifications << block
|
|
12
|
-
end
|
|
13
|
-
def producer_verifications
|
|
14
|
-
@producer_verifications ||= []
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
module ConfigurationDSL
|
|
19
|
-
|
|
20
|
-
def consumer &block
|
|
21
|
-
if block_given?
|
|
22
|
-
@consumer = ConsumerDSL.new(&block).create_service_consumer
|
|
23
|
-
elsif @consumer
|
|
24
|
-
@consumer
|
|
25
|
-
else
|
|
26
|
-
raise "Please configure a consumer before configuring producers"
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class ConsumerDSL
|
|
31
|
-
|
|
32
|
-
def initialize &block
|
|
33
|
-
@app = nil
|
|
34
|
-
@port = nil
|
|
35
|
-
@name = nil
|
|
36
|
-
instance_eval(&block)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def validate
|
|
40
|
-
raise "Please provide a consumer name" unless @name
|
|
41
|
-
raise "Please provide a port for the consumer app" if @app && !@port
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def name name
|
|
45
|
-
@name = name
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def app app
|
|
49
|
-
@app = app
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def port port
|
|
53
|
-
@port = port
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def create_service_consumer
|
|
57
|
-
validate
|
|
58
|
-
register_consumer_app if @app
|
|
59
|
-
Pact::Consumer::ServiceConsumer.new name: @name
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def register_consumer_app
|
|
63
|
-
Pact::Consumer::AppManager.instance.register @app, @port
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
Pact::Configuration.send(:include, Pact::Consumer::ConfigurationDSL)
|
|
71
|
-
Pact::Configuration.send(:include, Pact::Consumer::Configuration)
|
data/lib/pact/consumer/dsl.rb
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
require_relative 'consumer_contract_builders'
|
|
2
|
-
|
|
3
|
-
module Pact::Consumer
|
|
4
|
-
module DSL
|
|
5
|
-
def with_producer name, &block
|
|
6
|
-
Producer.new(name, &block).create_consumer_contract_builder
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class Producer
|
|
10
|
-
def initialize name, &block
|
|
11
|
-
@name = name
|
|
12
|
-
@service = nil
|
|
13
|
-
instance_eval(&block)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def service name, &block
|
|
17
|
-
@service = Service.new(name, &block)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
alias_method :mock_service, :service
|
|
21
|
-
|
|
22
|
-
def create_consumer_contract_builder
|
|
23
|
-
validate
|
|
24
|
-
consumer_contract_builder_from_attributes
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def validate
|
|
28
|
-
raise "Please configure a service for #{@name}" unless @service
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def consumer_contract_builder_from_attributes
|
|
32
|
-
consumer_contract_builder_fields = {
|
|
33
|
-
:consumer_name => Pact.configuration.consumer.name,
|
|
34
|
-
:producer_name => @name,
|
|
35
|
-
:pactfile_write_mode => Pact.configuration.pactfile_write_mode
|
|
36
|
-
}
|
|
37
|
-
@service.configure_consumer_contract_builder consumer_contract_builder_fields
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
class Service
|
|
42
|
-
def initialize name, &block
|
|
43
|
-
@name = name
|
|
44
|
-
@port = nil
|
|
45
|
-
@standalone = false
|
|
46
|
-
@verify = false
|
|
47
|
-
instance_eval(&block)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def port port
|
|
51
|
-
@port = port
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def standalone standalone
|
|
55
|
-
@standalone = standalone
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def verify verify
|
|
59
|
-
@verify = verify
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def configure_consumer_contract_builder consumer_contract_builder_fields
|
|
63
|
-
validate
|
|
64
|
-
unless @standalone
|
|
65
|
-
AppManager.instance.register_mock_service_for consumer_contract_builder_fields[:producer_name], "http://localhost:#{@port}"
|
|
66
|
-
end
|
|
67
|
-
consumer_contract_builder = Pact::Consumer::ConsumerContractBuilder.new consumer_contract_builder_fields.merge({port: @port})
|
|
68
|
-
create_mock_services_module_method consumer_contract_builder
|
|
69
|
-
setup_verification(consumer_contract_builder) if @verify
|
|
70
|
-
consumer_contract_builder
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def setup_verification consumer_contract_builder
|
|
75
|
-
Pact.configuration.add_producer_verification do | example_description |
|
|
76
|
-
consumer_contract_builder.verify example_description
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
private
|
|
81
|
-
|
|
82
|
-
# This makes the consumer_contract_builder available via a module method with the given identifier
|
|
83
|
-
# as the method name.
|
|
84
|
-
# I feel this should be defined somewhere else, but I'm not sure where
|
|
85
|
-
def create_mock_services_module_method consumer_contract_builder
|
|
86
|
-
Pact::Consumer::ConsumerContractBuilders.send(:define_method, @name.to_sym) do
|
|
87
|
-
consumer_contract_builder
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def validate
|
|
92
|
-
raise "Please provide a port for service #{@name}" unless @port
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
Pact.send(:extend, Pact::Consumer::DSL)
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
require 'net/http'
|
|
2
|
-
require 'pact/reification'
|
|
3
|
-
require 'pact/request'
|
|
4
|
-
#require 'json/add/core'
|
|
5
|
-
|
|
6
|
-
module Pact
|
|
7
|
-
module Consumer
|
|
8
|
-
|
|
9
|
-
class Interaction
|
|
10
|
-
|
|
11
|
-
attr_accessor :description, :request, :response, :producer_state
|
|
12
|
-
|
|
13
|
-
def initialize options
|
|
14
|
-
@description = options[:description]
|
|
15
|
-
@request = options[:request]
|
|
16
|
-
@response = options[:response]
|
|
17
|
-
@producer_state = options[:producer_state]
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def self.from_hash options
|
|
21
|
-
new(:description => options['description'],
|
|
22
|
-
:producer_state => options['producer_state'],
|
|
23
|
-
:request => Pact::Request::Expected.from_hash(options['request']),
|
|
24
|
-
:response => options['response']
|
|
25
|
-
)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def as_json
|
|
29
|
-
{
|
|
30
|
-
:description => @description,
|
|
31
|
-
:request => @request.as_json,
|
|
32
|
-
:response => @response,
|
|
33
|
-
}.tap{ | hash | hash[:producer_state] = @producer_state if @producer_state }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def to_json(options = {})
|
|
37
|
-
as_json.to_json(options)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def to_json_with_generated_response
|
|
42
|
-
as_json.tap { | hash | hash[:response] = Reification.from_term(response) }.to_json
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
class InteractionBuilder
|
|
47
|
-
|
|
48
|
-
attr_reader :interaction
|
|
49
|
-
|
|
50
|
-
def initialize(description, producer_state)
|
|
51
|
-
producer_state = producer_state.nil? ? nil : producer_state.to_s
|
|
52
|
-
@interaction = Interaction.new(:description => description, :producer_state => producer_state)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def with(request_details)
|
|
56
|
-
interaction.request = Request::Expected.from_hash(request_details)
|
|
57
|
-
self
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def will_respond_with(response)
|
|
61
|
-
interaction.response = response
|
|
62
|
-
@callback.call interaction
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def on_interaction_fully_defined &block
|
|
66
|
-
@callback = block
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require 'net/http'
|
|
2
|
-
require_relative 'spawn_app'
|
|
3
|
-
require_relative 'mock_service'
|
|
4
|
-
|
|
5
|
-
spawn_app MockService.new, 1234
|
|
6
|
-
|
|
7
|
-
RSpec.configure do |c|
|
|
8
|
-
c.before(:each, :type => :feature) do
|
|
9
|
-
http = Net::HTTP.new('localhost', 1234)
|
|
10
|
-
request = Net::HTTP::Delete.new('/interactions')
|
|
11
|
-
response = http.request(request)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module Pact
|
|
2
|
-
module Consumer
|
|
3
|
-
class ServiceConsumer
|
|
4
|
-
attr_accessor :name
|
|
5
|
-
def initialize options
|
|
6
|
-
@name = options[:name]
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def to_s
|
|
10
|
-
name
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def as_json options = {}
|
|
14
|
-
{name: name}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def self.from_hash obj
|
|
18
|
-
ServiceConsumer.new(:name => obj['name'])
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module Pact
|
|
2
|
-
module Consumer
|
|
3
|
-
# This is a crap name, it's really just a object for serializing to JSON
|
|
4
|
-
class ServiceProducer
|
|
5
|
-
attr_accessor :name
|
|
6
|
-
def initialize options
|
|
7
|
-
@name = options[:name] || '[producer name unknown - please update the pact gem in the consumer project to the latest version and regenerate the pacts]'
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def to_s
|
|
11
|
-
name
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def as_json options = {}
|
|
15
|
-
{name: name}
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def self.from_hash obj
|
|
19
|
-
ServiceProducer.new(:name => obj['name'])
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
data/lib/pact/json_warning.rb
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
require 'logger'
|
|
2
|
-
require 'json/add/regexp'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
module JsonWarning
|
|
6
|
-
def check_for_active_support_json
|
|
7
|
-
# Active support clobbers the as_json methods defined in the json/add directory of the json gem.
|
|
8
|
-
# These methods are required to serialize and deserialize the Regexp and Symbol classes properly.
|
|
9
|
-
# You can potentially fix this by making sure the json gem is required AFTER the active_support/json gem
|
|
10
|
-
# OR if you don't use the json part of activesupport you could only require the parts of active support you really need
|
|
11
|
-
# OR you can only use strings in your pacts.
|
|
12
|
-
# Good luck.
|
|
13
|
-
|
|
14
|
-
# If someone knows how to make sure the pact gem uses the json gem as_json methods when activesupport/json is used in the calling code,
|
|
15
|
-
# without breaking the calling code, which may depend on activesupport/json... then please fix this.
|
|
16
|
-
# Note: we can probably do this in Ruby 2.0 with refinements, but for now, we're all stuck on 1.9 :(
|
|
17
|
-
|
|
18
|
-
unless Regexp.new('').as_json.is_a?(Hash)
|
|
19
|
-
Logger.new($stderr).warn("It appears you are using ActiveSupport json in your project. You are now in rubygems hell. Please see Pact::JsonWarning for more info.")
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
require 'ostruct'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
module Producer
|
|
6
|
-
module ConfigurationDSL
|
|
7
|
-
|
|
8
|
-
def producer &block
|
|
9
|
-
@producer ||= nil
|
|
10
|
-
if block_given?
|
|
11
|
-
@producer = ProducerDSL.new(&block).create_producer_config
|
|
12
|
-
elsif @producer
|
|
13
|
-
@producer
|
|
14
|
-
else
|
|
15
|
-
raise "Please configure your producer. See the Producer section in the README for examples."
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
class ProducerConfig
|
|
20
|
-
attr_accessor :name
|
|
21
|
-
|
|
22
|
-
def initialize name, &app_block
|
|
23
|
-
@name = name
|
|
24
|
-
@app_block = app_block
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def app
|
|
28
|
-
@app_block.call
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
class ProducerDSL
|
|
33
|
-
|
|
34
|
-
def initialize &block
|
|
35
|
-
@app = nil
|
|
36
|
-
@name = nil
|
|
37
|
-
instance_eval(&block)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def validate
|
|
41
|
-
raise "Please provide a name for the Producer" unless @name
|
|
42
|
-
raise "Please configure an app for the Producer" unless @app_block
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def name name
|
|
46
|
-
@name = name
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def app &block
|
|
50
|
-
@app_block = block
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def create_producer_config
|
|
54
|
-
validate
|
|
55
|
-
ProducerConfig.new(@name, &@app_block)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
Pact::Configuration.send(:include, Pact::Producer::ConfigurationDSL)
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require 'pact/term'
|
|
2
|
-
require 'awesome_print'
|
|
3
|
-
require 'pact/matchers'
|
|
4
|
-
require 'awesome_print'
|
|
5
|
-
|
|
6
|
-
RSpec::Matchers.define :match_term do |expected|
|
|
7
|
-
include Pact::Matchers
|
|
8
|
-
|
|
9
|
-
match do |actual|
|
|
10
|
-
if (difference = diff(expected, actual)).any?
|
|
11
|
-
@message = difference
|
|
12
|
-
false
|
|
13
|
-
else
|
|
14
|
-
true
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
failure_message_for_should do | actual |
|
|
19
|
-
@message.ai
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
end
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
require 'open-uri'
|
|
2
|
-
require 'rspec'
|
|
3
|
-
require 'rspec/core'
|
|
4
|
-
require 'rspec/core/formatters/documentation_formatter'
|
|
5
|
-
require_relative 'rspec'
|
|
6
|
-
|
|
7
|
-
module Pact
|
|
8
|
-
module Producer
|
|
9
|
-
class PactSpecRunner
|
|
10
|
-
|
|
11
|
-
extend Pact::Producer::RSpec::ClassMethods
|
|
12
|
-
|
|
13
|
-
def self.run(spec_definitions, options = {})
|
|
14
|
-
initialize_specs spec_definitions
|
|
15
|
-
configure_rspec options
|
|
16
|
-
run_specs
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def self.initialize_specs spec_definitions
|
|
22
|
-
spec_definitions.each do | spec_definition |
|
|
23
|
-
require spec_definition[:support_file] if spec_definition[:support_file]
|
|
24
|
-
options = {consumer: spec_definition[:consumer], save_pactfile_to_tmp: true}
|
|
25
|
-
honour_pactfile spec_definition[:uri], options
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def self.configure_rspec options
|
|
30
|
-
config = ::RSpec.configuration
|
|
31
|
-
config.color = true
|
|
32
|
-
|
|
33
|
-
unless options[:silent]
|
|
34
|
-
config.error_stream = $stderr
|
|
35
|
-
config.output_stream = $stdout
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
formatter = ::RSpec::Core::Formatters::DocumentationFormatter.new(config.output)
|
|
39
|
-
reporter = ::RSpec::Core::Reporter.new(formatter)
|
|
40
|
-
config.instance_variable_set(:@reporter, reporter)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def self.run_specs
|
|
44
|
-
config = ::RSpec.configuration
|
|
45
|
-
world = ::RSpec::world
|
|
46
|
-
config.reporter.report(world.example_count, nil) do |reporter|
|
|
47
|
-
begin
|
|
48
|
-
config.run_hook(:before, :suite)
|
|
49
|
-
world.example_groups.ordered.map {|g| g.run(reporter)}.all? ? 0 : config.failure_exit_code
|
|
50
|
-
ensure
|
|
51
|
-
config.run_hook(:after, :suite)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
module Pact
|
|
2
|
-
module Producer
|
|
3
|
-
|
|
4
|
-
module DSL
|
|
5
|
-
def producer_state name, &block
|
|
6
|
-
ProducerState.producer_state(name, &block).register
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def with_consumer name, &block
|
|
10
|
-
ProducerState.current_namespaces << name
|
|
11
|
-
instance_eval(&block)
|
|
12
|
-
ProducerState.current_namespaces.pop
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
class ProducerState
|
|
17
|
-
|
|
18
|
-
attr_accessor :name
|
|
19
|
-
attr_accessor :namespace
|
|
20
|
-
|
|
21
|
-
def self.producer_state name, &block
|
|
22
|
-
ProducerState.new(name, current_namespaces.join('.'), &block)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def self.register name, producer_state
|
|
26
|
-
producer_states[name] = producer_state
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def self.producer_states
|
|
30
|
-
@@producer_states ||= {}
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def self.current_namespaces
|
|
34
|
-
@@current_namespaces ||= []
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def self.get name, options = {}
|
|
38
|
-
fullname = options[:for] ? "#{options[:for]}.#{name}" : name
|
|
39
|
-
(producer_states[fullname] || producer_states[fullname.to_sym]) || producer_states[name]
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def register
|
|
43
|
-
self.class.register(namespaced(name), self)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def initialize name, namespace, &block
|
|
47
|
-
@name = name
|
|
48
|
-
@namespace = namespace
|
|
49
|
-
instance_eval(&block)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def set_up &block
|
|
53
|
-
if block_given?
|
|
54
|
-
@set_up_block = block
|
|
55
|
-
elsif @set_up_block
|
|
56
|
-
instance_eval &@set_up_block
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def tear_down &block
|
|
61
|
-
if block_given?
|
|
62
|
-
@tear_down_block = block
|
|
63
|
-
elsif @tear_down_block
|
|
64
|
-
instance_eval &@tear_down_block
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
private
|
|
69
|
-
|
|
70
|
-
def namespaced(name)
|
|
71
|
-
if namespace.empty?
|
|
72
|
-
name
|
|
73
|
-
else
|
|
74
|
-
"#{namespace}.#{name}"
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
Pact.send(:extend, Pact::Producer::DSL)
|