pact 1.0.37 → 1.0.38
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +3 -1
- data/README.md +6 -2
- data/lib/pact/configuration.rb +4 -0
- data/lib/pact/consumer/consumer_contract_builder.rb +1 -1
- data/lib/pact/provider/pact_spec_runner.rb +27 -28
- data/lib/pact/provider/print_missing_provider_states.rb +2 -2
- data/lib/pact/provider/rspec.rb +16 -7
- data/lib/pact/provider/rspec/formatter.rb +63 -0
- data/lib/pact/provider/rspec/silent_json_formatter.rb +18 -0
- data/lib/pact/provider/world.rb +6 -0
- data/lib/pact/tasks/task_helper.rb +15 -18
- data/lib/pact/templates/provider_state.erb +0 -1
- data/lib/pact/version.rb +1 -1
- data/pact.gemspec +1 -0
- data/spec/lib/pact/tasks/task_helper_spec.rb +80 -0
- data/spec/lib/pact/verification_task_spec.rb +0 -10
- data/spec/support/pact_helper.rb +5 -2
- data/spec/support/stubbing.json +1 -1
- data/spec/support/test_app_fail.json +29 -2
- data/spec/support/test_app_pass.json +4 -4
- data/tasks/pact-test.rake +8 -0
- metadata +24 -4
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@ Do this to generate your change history
|
|
2
2
|
|
3
3
|
git log --date=relative --pretty=format:' * %h - %s (%an, %ad)'
|
4
4
|
|
5
|
+
### 1.0.38 (24 March 2014)
|
6
|
+
|
7
|
+
* 7fb2bc3 - Improved readability of pact:verify specs by removing pactfile name and request details from output (bethesque, 23 hours ago)
|
8
|
+
* ff1de3c - Improving readability of error messages when pact:verify fails (bethesque, 23 hours ago)
|
9
|
+
* 8a08abf - Removed the last RSpec private API usage. I think. (bethesque, 33 hours ago)
|
10
|
+
* 6a0be58 - Reducing even more use of RSpec private APIs (bethesque, 33 hours ago)
|
11
|
+
* e1fd51c - Reducing use of RSpec private APIs (bethesque, 34 hours ago)
|
12
|
+
* 587cb90 - Replaced rspec 'commands to rerun failed examples' with Pact specific commands to rerun failed interactions (bethesque, 2 days ago)
|
13
|
+
|
5
14
|
### 1.0.37 (19 March 2014)
|
6
15
|
|
7
16
|
* 0e8b80e - Cleaned up pact:verify rspec matcher lines so the output makes more sense to the reader (bethesque, 3 minutes ago)
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pact (1.0.
|
4
|
+
pact (1.0.38)
|
5
5
|
awesome_print (~> 1.1)
|
6
|
+
colored
|
6
7
|
find_a_port (~> 1.0.1)
|
7
8
|
json
|
8
9
|
rack-test (~> 0.6.2)
|
@@ -24,6 +25,7 @@ GEM
|
|
24
25
|
atomic (1.1.14)
|
25
26
|
awesome_print (1.2.0)
|
26
27
|
coderay (1.0.9)
|
28
|
+
colored (1.2)
|
27
29
|
crack (0.4.1)
|
28
30
|
safe_yaml (~> 0.9.0)
|
29
31
|
diff-lcs (1.2.4)
|
data/README.md
CHANGED
@@ -377,9 +377,13 @@ Configure the pact_uri in the Pact.service_provider block with the pact artifact
|
|
377
377
|
|
378
378
|
It should run with all your other tests. If an integration is broken, you want to know about it *before* you check in.
|
379
379
|
|
380
|
-
####
|
380
|
+
#### Stub calls to downstream systems
|
381
381
|
|
382
|
-
|
382
|
+
Consider making a separate pact with the downstream system and using shared fixtures.
|
383
|
+
|
384
|
+
#### Consider carefully whether to use the real database or stub calls
|
385
|
+
|
386
|
+
You may choose not stub your database calls for pact:verify. This can be a good time for you to test your database integration if you have a simple application, however, for a complex one, you might want to carefully choose a point at which to stub calls.
|
383
387
|
|
384
388
|
## Gotchas
|
385
389
|
|
data/lib/pact/configuration.rb
CHANGED
@@ -10,6 +10,8 @@ module Pact
|
|
10
10
|
attr_accessor :tmp_dir
|
11
11
|
attr_accessor :reports_dir
|
12
12
|
attr_writer :pactfile_write_mode
|
13
|
+
attr_accessor :error_stream
|
14
|
+
attr_accessor :output_stream
|
13
15
|
|
14
16
|
def log_path
|
15
17
|
log_dir + "/pact.log"
|
@@ -54,6 +56,8 @@ module Pact
|
|
54
56
|
c.logger = default_logger c.log_path
|
55
57
|
c.pactfile_write_mode = :overwrite
|
56
58
|
c.reports_dir = File.expand_path('./reports/pacts')
|
59
|
+
c.output_stream = $stdout
|
60
|
+
c.error_stream = $stderr
|
57
61
|
c
|
58
62
|
end
|
59
63
|
|
@@ -4,7 +4,8 @@ require 'rspec/core'
|
|
4
4
|
require 'rspec/core/formatters/documentation_formatter'
|
5
5
|
require 'rspec/core/formatters/json_formatter'
|
6
6
|
require 'pact/provider/pact_helper_locator'
|
7
|
-
require 'pact/provider/
|
7
|
+
require 'pact/provider/rspec/formatter'
|
8
|
+
require 'pact/provider/rspec/silent_json_formatter'
|
8
9
|
require_relative 'rspec'
|
9
10
|
|
10
11
|
|
@@ -36,6 +37,7 @@ module Pact
|
|
36
37
|
run_specs
|
37
38
|
ensure
|
38
39
|
::RSpec.reset
|
40
|
+
Pact.clear_world
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -43,11 +45,11 @@ module Pact
|
|
43
45
|
|
44
46
|
def require_pact_helper spec_definition
|
45
47
|
if spec_definition[:pact_helper]
|
46
|
-
puts "Using #{spec_definition[:pact_helper]}"
|
48
|
+
Pact.configuration.output_stream.puts "Using #{spec_definition[:pact_helper]}"
|
47
49
|
require spec_definition[:pact_helper]
|
48
50
|
elsif spec_definition[:support_file]
|
49
|
-
puts "Using #{spec_definition[:support_file]}"
|
50
|
-
|
51
|
+
Pact.configuration.output_stream.puts "Using #{spec_definition[:support_file]}"
|
52
|
+
Pact.configuration.error_stream.puts SUPPORT_FILE_DEPRECATION_MESSAGE
|
51
53
|
require spec_definition[:support_file]
|
52
54
|
else
|
53
55
|
require 'pact/provider/client_project_pact_helper'
|
@@ -70,42 +72,39 @@ module Pact
|
|
70
72
|
config = ::RSpec.configuration
|
71
73
|
|
72
74
|
config.color = true
|
75
|
+
config.pattern = "pattern which doesn't match any files"
|
76
|
+
config.backtrace_inclusion_patterns = [/pact\/provider\/rspec/]
|
77
|
+
|
73
78
|
config.extend Pact::Provider::RSpec::ClassMethods
|
74
79
|
config.include Pact::Provider::RSpec::InstanceMethods
|
75
80
|
config.include Pact::Provider::TestMethods
|
76
|
-
config.backtrace_inclusion_patterns = [/pact\/provider\/rspec/]
|
77
81
|
|
78
|
-
|
79
|
-
|
80
|
-
|
82
|
+
if options[:silent]
|
83
|
+
config.output_stream = StringIO.new
|
84
|
+
config.error_stream = StringIO.new
|
85
|
+
else
|
86
|
+
config.error_stream = Pact.configuration.error_stream
|
87
|
+
config.output_stream = Pact.configuration.output_stream
|
81
88
|
end
|
82
89
|
|
83
|
-
|
84
|
-
|
85
|
-
config.output_stream = $stdout
|
86
|
-
end
|
90
|
+
config.add_formatter Pact::Provider::RSpec::Formatter
|
91
|
+
config.add_formatter Pact::Provider::RSpec::SilentJsonFormatter
|
87
92
|
|
88
|
-
formatter = ::RSpec::Core::Formatters::DocumentationFormatter.new(config.output)
|
89
|
-
@json_formatter = ::RSpec::Core::Formatters::JsonFormatter.new(StringIO.new)
|
90
|
-
reporter = ::RSpec::Core::Reporter.new(formatter, @json_formatter)
|
91
|
-
config.instance_variable_set(:@reporter, reporter)
|
92
93
|
end
|
93
94
|
|
94
95
|
def run_specs
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
begin
|
99
|
-
config.run_hook(:before, :suite)
|
100
|
-
world.example_groups.ordered.map {|g| g.run(reporter)}.all? ? 0 : config.failure_exit_code
|
101
|
-
ensure
|
102
|
-
config.run_hook(:after, :suite)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
PrintMissingProviderStates.call Pact.world.provider_states.missing_provider_states
|
106
|
-
@output = @json_formatter.output_hash
|
96
|
+
exit_code = ::RSpec::Core::CommandLine.new(NoConfigurationOptions.new)
|
97
|
+
.run(::RSpec.configuration.output_stream, ::RSpec.configuration.error_stream)
|
98
|
+
@output = JSON.parse(Pact.world.json_formatter_stream.string, symbolize_keys: true)
|
107
99
|
exit_code
|
108
100
|
end
|
101
|
+
|
102
|
+
class NoConfigurationOptions
|
103
|
+
def method_missing(method, *args, &block)
|
104
|
+
# Do nothing!
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
109
108
|
end
|
110
109
|
end
|
111
110
|
end
|
@@ -3,9 +3,9 @@ module Pact
|
|
3
3
|
class PrintMissingProviderStates
|
4
4
|
|
5
5
|
# Hash of consumer names to array of names of missing provider states
|
6
|
-
def self.call missing_provider_states
|
6
|
+
def self.call missing_provider_states, output
|
7
7
|
if missing_provider_states.any?
|
8
|
-
puts orangeify(text(missing_provider_states))
|
8
|
+
output.puts orangeify(text(missing_provider_states))
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
data/lib/pact/provider/rspec.rb
CHANGED
@@ -19,12 +19,10 @@ module Pact
|
|
19
19
|
include ::RSpec::Core::DSL
|
20
20
|
|
21
21
|
def honour_pactfile pactfile_uri, options = {}
|
22
|
-
puts "Filtering specs by: #{options[:criteria]}" if options[:criteria]
|
22
|
+
puts "Filtering specs by: #{options[:criteria]}" if options[:criteria] && options[:criteria].any?
|
23
23
|
consumer_contract = Pact::ConsumerContract.from_json(read_pact_from(pactfile_uri, options))
|
24
|
-
describe "
|
25
|
-
|
26
|
-
honour_consumer_contract consumer_contract, options
|
27
|
-
end
|
24
|
+
describe "Verifying a pact between #{consumer_contract.consumer.name} and #{consumer_contract.provider.name}", :pactfile_uri => pactfile_uri do
|
25
|
+
honour_consumer_contract consumer_contract, options
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
@@ -60,12 +58,19 @@ module Pact
|
|
60
58
|
|
61
59
|
def describe_interaction interaction, options
|
62
60
|
|
63
|
-
|
61
|
+
metadata = {
|
62
|
+
:pact => :verify,
|
63
|
+
:pact_interaction => interaction,
|
64
|
+
:pact_interaction_example_description => interaction_description_for_rerun_command(interaction)
|
65
|
+
}
|
66
|
+
|
67
|
+
describe description_for(interaction), metadata do
|
64
68
|
|
65
69
|
interaction_context = InteractionContext.new
|
66
70
|
|
67
71
|
before do
|
68
72
|
interaction_context.run_once :before do
|
73
|
+
Pact.configuration.logger.info "Running example '#{self.example.full_description}'"
|
69
74
|
set_up_provider_state interaction.provider_state, options[:consumer]
|
70
75
|
replay_interaction interaction
|
71
76
|
interaction_context.last_response = last_response
|
@@ -119,7 +124,11 @@ module Pact
|
|
119
124
|
end
|
120
125
|
|
121
126
|
def description_for interaction
|
122
|
-
|
127
|
+
interaction.provider_state ? interaction.description : interaction.description.capitalize
|
128
|
+
end
|
129
|
+
|
130
|
+
def interaction_description_for_rerun_command interaction
|
131
|
+
description_for(interaction).capitalize + ( interaction.provider_state ? " given #{interaction.provider_state}" : "")
|
123
132
|
end
|
124
133
|
|
125
134
|
def read_pact_from uri, options = {}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'pact/provider/print_missing_provider_states'
|
2
|
+
require 'rspec/core/formatters'
|
3
|
+
require 'colored'
|
4
|
+
|
5
|
+
module Pact
|
6
|
+
module Provider
|
7
|
+
module RSpec
|
8
|
+
class Formatter < ::RSpec::Core::Formatters::DocumentationFormatter
|
9
|
+
|
10
|
+
|
11
|
+
def dump_commands_to_rerun_failed_examples
|
12
|
+
return if failed_examples.empty?
|
13
|
+
|
14
|
+
print_rerun_commands
|
15
|
+
print_failure_message
|
16
|
+
print_missing_provider_states
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def print_rerun_commands
|
21
|
+
output.puts("\n")
|
22
|
+
interaction_failure_messages.each do | message |
|
23
|
+
output.puts(message)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def print_missing_provider_states
|
28
|
+
PrintMissingProviderStates.call Pact.world.provider_states.missing_provider_states, output
|
29
|
+
end
|
30
|
+
|
31
|
+
def interaction_failure_messages
|
32
|
+
failed_examples.collect do |example|
|
33
|
+
interaction_failure_message_for example
|
34
|
+
end.uniq
|
35
|
+
end
|
36
|
+
|
37
|
+
def interaction_failure_message_for example
|
38
|
+
provider_state = example.metadata[:pact_interaction].provider_state
|
39
|
+
description = example.metadata[:pact_interaction].description
|
40
|
+
pactfile_uri = example.metadata[:pactfile_uri]
|
41
|
+
example_description = example.metadata[:pact_interaction_example_description]
|
42
|
+
failure_color("rake pact:verify:at[#{pactfile_uri}] PACT_DESCRIPTION=\"#{description}\" PACT_PROVIDER_STATE=\"#{provider_state}\"") + " " + detail_color("# #{example_description}")
|
43
|
+
end
|
44
|
+
|
45
|
+
def print_failure_message
|
46
|
+
output.puts failure_message
|
47
|
+
end
|
48
|
+
|
49
|
+
def failure_message
|
50
|
+
|
51
|
+
"\n" + "For assistance debugging failures, please note:".underline.yellow + "\n\n" +
|
52
|
+
"The pact files have been stored locally in the following temp directory:\n #{Pact.configuration.tmp_dir}\n\n" +
|
53
|
+
"The requests and responses are logged in the following log file:\n #{Pact.configuration.log_path}\n\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rspec/core/formatters'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
module Provider
|
5
|
+
module RSpec
|
6
|
+
class SilentJsonFormatter < ::RSpec::Core::Formatters::JsonFormatter
|
7
|
+
|
8
|
+
def initialize stream
|
9
|
+
# Don't want to display this to the screen,
|
10
|
+
# not sure how else to set a custom stream for a particular formatter
|
11
|
+
# Store a reference to this so it can be inspected afterwards.
|
12
|
+
super(Pact.world.json_formatter_stream)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/pact/provider/world.rb
CHANGED
@@ -14,6 +14,12 @@ module Pact
|
|
14
14
|
module Provider
|
15
15
|
class World
|
16
16
|
|
17
|
+
attr_reader :json_formatter_stream
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@json_formatter_stream = StringIO.new
|
21
|
+
end
|
22
|
+
|
17
23
|
def provider_states
|
18
24
|
@provider_states_proxy ||= Pact::Provider::State::ProviderStateProxy.new
|
19
25
|
end
|
@@ -1,32 +1,29 @@
|
|
1
1
|
module Pact
|
2
2
|
module TaskHelper
|
3
|
-
def failure_message
|
4
|
-
redify(
|
5
|
-
"\n* * * * * * * * * * * * * * * * * * *\n" +
|
6
|
-
"Provider did not honour pact file.\nSee\n * #{Pact.configuration.log_path}\n * #{Pact.configuration.tmp_dir}\nfor logs and pact files." +
|
7
|
-
"\n* * * * * * * * * * * * * * * * * * *\n\n"
|
8
|
-
)
|
9
|
-
end
|
10
3
|
|
11
|
-
|
12
|
-
"\e[31m#{string}\e[m"
|
13
|
-
end
|
4
|
+
extend self
|
14
5
|
|
15
6
|
def handle_verification_failure
|
16
7
|
exit_status = yield
|
17
|
-
if exit_status != 0
|
18
|
-
$stderr.puts failure_message
|
19
|
-
fail
|
20
|
-
end
|
8
|
+
abort if exit_status != 0
|
21
9
|
end
|
22
10
|
|
23
11
|
def spec_criteria defaults = {description: nil, provider_state: nil}
|
24
12
|
criteria = {}
|
25
|
-
|
26
|
-
|
27
|
-
|
13
|
+
|
14
|
+
description = ENV.fetch("PACT_DESCRIPTION", defaults[:description])
|
15
|
+
criteria[:description] = Regexp.new(description) if description
|
16
|
+
|
17
|
+
provider_state = ENV.fetch("PACT_PROVIDER_STATE", defaults[:provider_state])
|
18
|
+
if provider_state
|
19
|
+
if provider_state.length == 0
|
20
|
+
criteria[:provider_state] = nil #Allow PACT_PROVIDER_STATE="" to mean no provider state
|
21
|
+
else
|
22
|
+
criteria[:provider_state] = Regexp.new(provider_state)
|
23
|
+
end
|
28
24
|
end
|
29
|
-
|
25
|
+
|
26
|
+
criteria
|
30
27
|
end
|
31
28
|
end
|
32
29
|
end
|
data/lib/pact/version.rb
CHANGED
data/pact.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
|
|
26
26
|
gem.add_runtime_dependency 'thor'
|
27
27
|
gem.add_runtime_dependency 'json' #Not locking down a version because buncher gem requires 1.6, while other projects use 1.7.
|
28
28
|
gem.add_runtime_dependency 'webrick'
|
29
|
+
gem.add_runtime_dependency 'colored'
|
29
30
|
|
30
31
|
gem.add_development_dependency 'rake', '~> 10.0.3'
|
31
32
|
gem.add_development_dependency 'webmock', '~> 1.9.3'
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pact/tasks/task_helper'
|
3
|
+
|
4
|
+
module Pact
|
5
|
+
describe TaskHelper do
|
6
|
+
include TaskHelper
|
7
|
+
|
8
|
+
let(:env_description) { "pact description set in ENV"}
|
9
|
+
let(:env_provider_state) { "provider state set in ENV"}
|
10
|
+
let(:env_criteria){ {:description=>/#{env_description}/, :provider_state=>/#{env_provider_state}/} }
|
11
|
+
let(:default_description) { "default description"}
|
12
|
+
let(:default_provider_state) { "default provider state"}
|
13
|
+
|
14
|
+
shared_context "PACT_DESCRIPTION is defined" do
|
15
|
+
before do
|
16
|
+
ENV.stub(:[])
|
17
|
+
ENV.stub(:[]).with("PACT_DESCRIPTION").and_return(env_description)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
shared_context 'PACT_PROVIDER_STATE is defined' do
|
22
|
+
before do
|
23
|
+
ENV.stub(:[])
|
24
|
+
ENV.stub(:[]).with("PACT_PROVIDER_STATE").and_return(env_provider_state)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
shared_context 'default description is defined' do
|
29
|
+
let(:default_description) { "default description"}
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:defaults) { {:description => default_description, :provider_state => default_provider_state} }
|
33
|
+
|
34
|
+
describe "spec_criteria" do
|
35
|
+
|
36
|
+
context "when ENV variables are defined" do
|
37
|
+
before do
|
38
|
+
ENV.stub(:fetch).with("PACT_DESCRIPTION", anything).and_return(env_description)
|
39
|
+
ENV.stub(:fetch).with("PACT_PROVIDER_STATE", anything).and_return(env_provider_state)
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when defaults are not passed in" do
|
43
|
+
it "returns the env vars as regexes" do
|
44
|
+
expect(spec_criteria).to eq(env_criteria)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when defaults are passed in" do
|
49
|
+
it "returns the env vars as regexes" do
|
50
|
+
expect(spec_criteria(defaults)).to eq(env_criteria)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when ENV variables are not defined" do
|
56
|
+
context "when defaults are passed in" do
|
57
|
+
it "returns the defaults as regexes" do
|
58
|
+
expect(spec_criteria(defaults)).to eq({:description=>/#{default_description}/, :provider_state=>/#{default_provider_state}/})
|
59
|
+
end
|
60
|
+
end
|
61
|
+
context "when defaults are not passed in" do
|
62
|
+
it "returns an empty hash" do
|
63
|
+
expect(spec_criteria).to eq({})
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when provider state is an empty string" do
|
69
|
+
before do
|
70
|
+
ENV.stub(:fetch).with(anything, anything).and_return(nil)
|
71
|
+
ENV.stub(:fetch).with("PACT_PROVIDER_STATE", anything).and_return('')
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns a nil provider state so that it matches a nil provider state on the interaction" do
|
75
|
+
expect(spec_criteria[:provider_state]).to be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -88,16 +88,6 @@ module Pact
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
context 'when one or more specs fail' do
|
92
|
-
|
93
|
-
let(:exit_code) {1}
|
94
|
-
|
95
|
-
it 'raises an exception' do
|
96
|
-
$stderr.should_receive(:puts) #Confusing if this shows on the screen!
|
97
|
-
expect { Rake::Task[@task_name].execute }.to raise_error RuntimeError
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
91
|
end
|
102
92
|
end
|
103
93
|
end
|
data/spec/support/pact_helper.rb
CHANGED
@@ -28,12 +28,16 @@ module Pact
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
Pact.set_up do
|
32
|
+
WEATHER ||= {}
|
33
|
+
end
|
31
34
|
|
32
35
|
#one with a top level consumer
|
33
36
|
Pact.provider_states_for 'some-test-consumer' do
|
37
|
+
|
34
38
|
provider_state "the weather is sunny" do
|
35
39
|
set_up do
|
36
|
-
|
40
|
+
|
37
41
|
WEATHER[:current_state] = 'sunny'
|
38
42
|
end
|
39
43
|
end
|
@@ -42,7 +46,6 @@ module Pact
|
|
42
46
|
#one without a top level consumer
|
43
47
|
Pact.provider_state "the weather is cloudy" do
|
44
48
|
set_up do
|
45
|
-
WEATHER ||= {}
|
46
49
|
WEATHER[:current_state] = 'cloudy'
|
47
50
|
end
|
48
51
|
end
|
data/spec/support/stubbing.json
CHANGED
@@ -4,10 +4,10 @@
|
|
4
4
|
},
|
5
5
|
"provider": {
|
6
6
|
"name": "an unknown provider"
|
7
|
-
},
|
7
|
+
},
|
8
8
|
"interactions": [
|
9
9
|
{
|
10
|
-
"description": "
|
10
|
+
"description": "a test request",
|
11
11
|
"request": {
|
12
12
|
"method": "get",
|
13
13
|
"path": "/weather",
|
@@ -20,6 +20,33 @@
|
|
20
20
|
|
21
21
|
},
|
22
22
|
"provider_state": "the weather is cloudy"
|
23
|
+
},{
|
24
|
+
"description": "another test request",
|
25
|
+
"request": {
|
26
|
+
"method": "get",
|
27
|
+
"path": "/weather",
|
28
|
+
"query": ""
|
29
|
+
},
|
30
|
+
"response": {
|
31
|
+
"status": 200,
|
32
|
+
"headers" : {"Content-type": "application/json"},
|
33
|
+
"body": {"message" : "this is not the weather you are looking for"}
|
34
|
+
|
35
|
+
}
|
36
|
+
},{
|
37
|
+
"description": "another test request",
|
38
|
+
"provider_state": "a missing provider state",
|
39
|
+
"request": {
|
40
|
+
"method": "get",
|
41
|
+
"path": "/weather",
|
42
|
+
"query": ""
|
43
|
+
},
|
44
|
+
"response": {
|
45
|
+
"status": 200,
|
46
|
+
"headers" : {"Content-type": "application/json"},
|
47
|
+
"body": {"message" : "this is not the weather you are looking for"}
|
48
|
+
|
49
|
+
}
|
23
50
|
}
|
24
51
|
]
|
25
52
|
}
|
@@ -4,10 +4,10 @@
|
|
4
4
|
},
|
5
5
|
"provider": {
|
6
6
|
"name": "an unknown provider"
|
7
|
-
},
|
7
|
+
},
|
8
8
|
"interactions": [
|
9
9
|
{
|
10
|
-
"description": "
|
10
|
+
"description": "a test request",
|
11
11
|
"request": {
|
12
12
|
"method": "get",
|
13
13
|
"path": "/weather",
|
@@ -21,7 +21,7 @@
|
|
21
21
|
"provider_state": "the weather is sunny"
|
22
22
|
},
|
23
23
|
{
|
24
|
-
"description": "
|
24
|
+
"description": "a test request for text",
|
25
25
|
"request": {
|
26
26
|
"method": "get",
|
27
27
|
"path": "/sometext",
|
@@ -33,6 +33,6 @@
|
|
33
33
|
"headers" : {"Content-type": "text/plain"},
|
34
34
|
"body": "some text"
|
35
35
|
}
|
36
|
-
}
|
36
|
+
}
|
37
37
|
]
|
38
38
|
}
|
data/tasks/pact-test.rake
CHANGED
@@ -8,6 +8,13 @@ Pact::VerificationTask.new(:stubbing_using_allow) do | pact |
|
|
8
8
|
pact.uri './spec/support/stubbing.json', :pact_helper => './spec/support/stubbing_using_allow.rb'
|
9
9
|
end
|
10
10
|
|
11
|
+
Pact::VerificationTask.new(:pass) do | pact |
|
12
|
+
pact.uri './spec/support/test_app_pass.json'
|
13
|
+
end
|
14
|
+
|
15
|
+
Pact::VerificationTask.new(:fail) do | pact |
|
16
|
+
pact.uri './spec/support/test_app_fail.json'
|
17
|
+
end
|
11
18
|
|
12
19
|
namespace :pact do
|
13
20
|
|
@@ -20,6 +27,7 @@ namespace :pact do
|
|
20
27
|
silent = true
|
21
28
|
puts "Running task pact:tests"
|
22
29
|
# Run these specs silently, otherwise expected failures will be written to stdout and look like unexpected failures.
|
30
|
+
Pact.configuration.output_stream = StringIO.new if silent
|
23
31
|
|
24
32
|
result = Pact::Provider::PactSpecRunner.new([{ uri: './spec/support/test_app_pass.json' }], silent: silent).run
|
25
33
|
fail 'Expected pact to pass' unless (result == 0)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.38
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2014-03-
|
16
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: randexp
|
@@ -143,6 +143,22 @@ dependencies:
|
|
143
143
|
- - ! '>='
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
|
+
- !ruby/object:Gem::Dependency
|
147
|
+
name: colored
|
148
|
+
requirement: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
type: :runtime
|
155
|
+
prerelease: false
|
156
|
+
version_requirements: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ! '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
146
162
|
- !ruby/object:Gem::Dependency
|
147
163
|
name: rake
|
148
164
|
requirement: !ruby/object:Gem::Requirement
|
@@ -359,6 +375,8 @@ files:
|
|
359
375
|
- lib/pact/provider/print_missing_provider_states.rb
|
360
376
|
- lib/pact/provider/request.rb
|
361
377
|
- lib/pact/provider/rspec.rb
|
378
|
+
- lib/pact/provider/rspec/formatter.rb
|
379
|
+
- lib/pact/provider/rspec/silent_json_formatter.rb
|
362
380
|
- lib/pact/provider/state/provider_state.rb
|
363
381
|
- lib/pact/provider/state/provider_state_configured_modules.rb
|
364
382
|
- lib/pact/provider/state/provider_state_manager.rb
|
@@ -421,6 +439,7 @@ files:
|
|
421
439
|
- spec/lib/pact/reification_spec.rb
|
422
440
|
- spec/lib/pact/shared/dsl_spec.rb
|
423
441
|
- spec/lib/pact/something_like_spec.rb
|
442
|
+
- spec/lib/pact/tasks/task_helper_spec.rb
|
424
443
|
- spec/lib/pact/term_spec.rb
|
425
444
|
- spec/lib/pact/verification_task_spec.rb
|
426
445
|
- spec/spec_helper.rb
|
@@ -455,7 +474,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
455
474
|
version: '0'
|
456
475
|
segments:
|
457
476
|
- 0
|
458
|
-
hash:
|
477
|
+
hash: 1671674810832384181
|
459
478
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
460
479
|
none: false
|
461
480
|
requirements:
|
@@ -464,7 +483,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
464
483
|
version: '0'
|
465
484
|
segments:
|
466
485
|
- 0
|
467
|
-
hash:
|
486
|
+
hash: 1671674810832384181
|
468
487
|
requirements: []
|
469
488
|
rubyforge_project:
|
470
489
|
rubygems_version: 1.8.23
|
@@ -513,6 +532,7 @@ test_files:
|
|
513
532
|
- spec/lib/pact/reification_spec.rb
|
514
533
|
- spec/lib/pact/shared/dsl_spec.rb
|
515
534
|
- spec/lib/pact/something_like_spec.rb
|
535
|
+
- spec/lib/pact/tasks/task_helper_spec.rb
|
516
536
|
- spec/lib/pact/term_spec.rb
|
517
537
|
- spec/lib/pact/verification_task_spec.rb
|
518
538
|
- spec/spec_helper.rb
|