pact 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact (1.0.1)
4
+ pact (1.0.2)
5
5
  awesome_print (~> 1.1.0)
6
6
  find_a_port (~> 1.0.1)
7
7
  hashie (~> 2.0)
@@ -36,10 +36,15 @@ module Pact
36
36
  c.tmp_dir = File.expand_path('./tmp/pacts')
37
37
  c.log_dir = default_log_dir
38
38
  c.logger = default_logger c.log_path
39
- c.pactfile_write_mode = :overwrite
39
+ c.pactfile_write_mode = is_rake_running? ? :overwrite : :update
40
40
  c
41
41
  end
42
42
 
43
+ #Would love a better way of determining this! It sure won't work on windows.
44
+ def self.is_rake_running?
45
+ `ps -ef | grep rake | grep #{Process.ppid} | grep -v 'grep'`.size > 0
46
+ end
47
+
43
48
  def self.default_log_dir
44
49
  File.expand_path("./log")
45
50
  end
@@ -78,19 +78,29 @@ module Pact
78
78
  end
79
79
  end
80
80
 
81
- def log_and_puts msg
81
+ def warn_and_stderr msg
82
82
  $stderr.puts msg
83
83
  logger.warn msg
84
84
  end
85
85
 
86
+ def info_and_puts msg
87
+ $stdout.puts msg
88
+ logger.info msg
89
+ end
90
+
86
91
  def existing_interactions
87
92
  interactions = []
88
93
  if pactfile_exists?
89
94
  begin
90
95
  interactions = existing_consumer_contract.interactions
96
+ info_and_puts "*****************************************************************************"
97
+ info_and_puts "Updating existing file .#{consumer_contract.pactfile_path.gsub(Dir.pwd, '')} as config.pactfile_write_mode is :update"
98
+ info_and_puts "Only interactions defined in this test run will be updated."
99
+ info_and_puts "As interactions are identified by description and provider state, pleased note that if either of these have changed, the old interactions won't be removed from the pact file until rake is next run."
100
+ info_and_puts "*****************************************************************************"
91
101
  rescue StandardError => e
92
- log_and_puts "Could not load existing consumer contract from #{consumer_contract.pactfile_path} due to #{e}"
93
- log_and_puts "Creating a new file."
102
+ warn_and_stderr "Could not load existing consumer contract from #{consumer_contract.pactfile_path} due to #{e}"
103
+ warn_and_stderr "Creating a new file."
94
104
  end
95
105
  end
96
106
  interactions
@@ -0,0 +1,7 @@
1
+ module PactTaskHelper
2
+ def failure_message
3
+ "\n* * * * * * * * * * * * * * * * * * *\n" +
4
+ "Provider did not honour pact file.\nSee\n * #{Pact.configuration.log_path}\n * #{Pact.configuration.tmp_dir}\nfor logs and pact files." +
5
+ "\n* * * * * * * * * * * * * * * * * * *\n\n"
6
+ end
7
+ end
@@ -1,5 +1,6 @@
1
1
  require 'rake/tasklib'
2
2
  require 'pact/provider/pact_spec_runner'
3
+ require_relative 'pact_task_helper'
3
4
 
4
5
  =begin
5
6
  To create a rake pact:verify:<something> task
@@ -23,32 +24,29 @@ require 'pact/provider/pact_spec_runner'
23
24
 
24
25
  =end
25
26
 
27
+
26
28
  module Pact
27
29
  class VerificationTask < ::Rake::TaskLib
28
30
  attr_reader :pact_spec_config
29
31
 
32
+ include PactTaskHelper
30
33
  def initialize(name)
31
34
  @pact_spec_config = []
32
35
 
33
36
  yield self
34
37
 
35
38
  namespace :pact do
39
+
36
40
  desc "Verify provider against the consumer pacts for #{name}"
37
41
  task "verify:#{name}" do
38
42
  exit_status = Provider::PactSpecRunner.run(pact_spec_config)
39
43
  fail failure_message if exit_status != 0
40
44
  end
41
-
42
- def failure_message
43
- "\n* * * * * * * * * * * * * * * * * * *\n" +
44
- "Provider did not honour pact file.\nSee\n * #{Pact.configuration.log_path}\n * #{Pact.configuration.tmp_dir}\nfor logs and pact files." +
45
- "\n* * * * * * * * * * * * * * * * * * *\n\n"
46
- end
47
45
  end
48
46
  end
49
47
 
50
48
  def uri(uri, options)
51
- @pact_spec_config << {uri: uri, support_file: options[:support_file], consumer: options[:consumer]}
49
+ @pact_spec_config << {uri: uri, support_file: options[:support_file]}
52
50
  end
53
51
  end
54
52
  end
@@ -1,3 +1,3 @@
1
1
  module Pact
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,6 +1,17 @@
1
+ require 'pact'
2
+ require 'pact/pact_task_helper'
3
+
4
+ include PactTaskHelper
1
5
  namespace :pact do
2
- desc "Runs all the tasks prefixed with pact:verify in this project"
3
- task :verify do
4
- Rake::Task.tasks.find_all{ | task| task.name.start_with? "pact:verify:"}.map(&:invoke)
6
+
7
+ desc "Runs the specified pact file against the service provider"
8
+ task :verify, :pact_uri, :support_file do | t, args |
9
+ puts 'BLSH'
10
+ require 'pact/provider/pact_spec_runner'
11
+ puts "Using pact at uri #{args[:pact_uri]}"
12
+ puts "Using support file #{args[:support_file]}"
13
+ pact_spec_config = {uri: args[:pact_uri], support_file: args[:support_file]}
14
+ exit_status = Pact::Provider::PactSpecRunner.run([pact_spec_config])
15
+ fail failure_message if exit_status != 0
5
16
  end
6
17
  end
@@ -22,7 +22,7 @@ module Pact
22
22
 
23
23
  let(:consumer_name) { 'a consumer' }
24
24
  let(:provider_name) { 'a provider' }
25
- let(:consumer_contract_builder) {
25
+ let(:consumer_contract_builder) {
26
26
  Pact::Consumer::ConsumerContractBuilder.new(
27
27
  :pactfile_write_mode => pactfile_write_mode,
28
28
  :consumer_name => consumer_name,
@@ -42,15 +42,36 @@ module Pact
42
42
  end
43
43
 
44
44
  context "when updating pact" do
45
+ before do
46
+
47
+ end
45
48
  let(:pactfile_write_mode) {:update}
46
49
  it "loads the interactions from the existing pact file" do
47
- expect(consumer_contract_builder.consumer_contract.interactions).to eq expected_interactions
50
+ ConsumerContractBuilder.any_instance.stub(:info_and_puts)
51
+ expect(consumer_contract_builder.consumer_contract.interactions).to eq expected_interactions
48
52
  end
49
53
 
50
54
  it "uses an UpdatableInteractionsFilter to handle new interactions" do
55
+ ConsumerContractBuilder.any_instance.stub(:info_and_puts)
51
56
  Pact::Consumer::UpdatableInteractionsFilter.should_receive(:new).with(expected_interactions)
52
57
  consumer_contract_builder
53
58
  end
59
+
60
+ let(:line0) { /\*/ }
61
+ let(:line1) { /Updating existing file/ }
62
+ let(:line2) { /Only interactions defined in this test run will be updated/ }
63
+ let(:line3) { /As interactions are identified by description and provider state/ }
64
+ it "logs a description message" do
65
+ $stdout.should_receive(:puts).with(line0).twice
66
+ $stdout.should_receive(:puts).with(line1)
67
+ $stdout.should_receive(:puts).with(line2)
68
+ $stdout.should_receive(:puts).with(line3)
69
+ Pact.configuration.logger.should_receive(:info).with(line0).twice
70
+ Pact.configuration.logger.should_receive(:info).with(line1)
71
+ Pact.configuration.logger.should_receive(:info).with(line2)
72
+ Pact.configuration.logger.should_receive(:info).with(line3)
73
+ consumer_contract_builder
74
+ end
54
75
  end
55
76
 
56
77
  context "when an error occurs deserializing the existing pactfile" do
@@ -24,7 +24,7 @@ module Pact
24
24
 
25
25
  describe 'execute' do
26
26
 
27
- let(:consumer_contract) { [ uri: @pact_uri, support_file: @support_file, consumer: @consumer] }
27
+ let(:consumer_contract) { [ uri: @pact_uri, support_file: @support_file] }
28
28
 
29
29
  it 'verifies the pacts using PactSpecRunner' do
30
30
  Provider::PactSpecRunner.should_receive(:run).with(consumer_contract).and_return(0)
@@ -4,13 +4,14 @@ namespace :pact do
4
4
 
5
5
  desc 'Runs pact tests against a sample application, testing failure and success.'
6
6
  task :tests do
7
+ silent = true
7
8
  puts "Running task pact:tests"
8
9
  # Run these specs silently, otherwise expected failures will be written to stdout and look like unexpected failures.
9
10
 
10
- result = Pact::Provider::PactSpecRunner.run([{ uri: './spec/support/test_app_pass.json', support_file: './spec/support/pact_rake_support.rb', consumer: 'some-test-consumer' }], silent: true)
11
+ result = Pact::Provider::PactSpecRunner.run([{ uri: './spec/support/test_app_pass.json', support_file: './spec/support/pact_rake_support.rb', consumer: 'some-test-consumer' }], silent: silent)
11
12
  fail 'Expected pact to pass' unless (result == 0)
12
13
 
13
- result = Pact::Provider::PactSpecRunner.run([{ uri: './spec/support/test_app_fail.json', support_file: './spec/support/pact_rake_support.rb' }], silent: true)
14
+ result = Pact::Provider::PactSpecRunner.run([{ uri: './spec/support/test_app_fail.json', support_file: './spec/support/pact_rake_support.rb' }], silent: silent)
14
15
  fail 'Expected pact to fail' if (result == 0)
15
16
 
16
17
  puts "Task pact:tests completed succesfully."
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.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -274,6 +274,7 @@ files:
274
274
  - lib/pact/logging.rb
275
275
  - lib/pact/matchers.rb
276
276
  - lib/pact/matchers/matchers.rb
277
+ - lib/pact/pact_task_helper.rb
277
278
  - lib/pact/provider.rb
278
279
  - lib/pact/provider/dsl.rb
279
280
  - lib/pact/provider/matchers.rb