pact 1.2.1.rc1 → 1.2.1.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@ Do this to generate your change history
2
2
 
3
3
  git log --pretty=format:' * %h - %s (%an, %ad)'
4
4
 
5
+ ### 1.2.1.rc2 (13 June 2014)
6
+
7
+ * d805f35 - Ensuring the pact RSpec formatter works for both rspec 2 and rspec 3 (Beth, Fri Jun 13 16:27:01 2014 +1000)
8
+ * 1669d46 - Fix require for sample app to work without munging LOAD_PATH (Daniel Heath, Fri Jun 13 15:50:03 2014 +1000)
9
+
5
10
  ### 1.2.1.rc1 (13 June 2014)
6
11
 
7
12
  * b8d1586 - Making RSpec::Mocks::ExampleMethods available in set_up and tear_down, so the allow method is available without configuration.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact (1.2.1.rc1)
4
+ pact (1.2.1.rc2)
5
5
  awesome_print (~> 1.1)
6
6
  find_a_port (~> 1.0.1)
7
7
  json
data/bin/pact CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'pact/app'
4
- Pact::App.start
3
+ require 'pact/cli'
4
+ Pact::CLI.start
@@ -14,9 +14,9 @@ The development process will be different for every organisation, but this is on
14
14
 
15
15
  ## New features
16
16
 
17
- 1. Add new feature, with pact specs, to consumer project on a branch.
17
+ 1. Add new feature, with pact specs, to consumer project on a new feature branch.
18
18
  1. In the provider project, use `rake pact:verify:at[/path/to/pact/on/branch]` to verify the new pact.
19
19
  1. Commit/release new provider feature.
20
- 1. Merge consumer branch into master.
20
+ 1. Merge consumer branch into main development branch.
21
21
 
22
- This may seem complex, but it is actually sufacing the underlying reality, that you cannot add new functionality to the consumer before it can be supported by the provider, but that the functionality that the provider supports should still be driven by the needs of the consumer.
22
+ This may seem complex, but it is actually sufacing the underlying reality, that you cannot add new functionality to the consumer before it can be supported by the provider, and that the functionality that the provider supports should still be driven by the needs of the consumer.
@@ -73,8 +73,8 @@ by your CI box) add the following to your Rakefile. The pact.uri may be a local
73
73
  # This creates a rake task that can be executed by running
74
74
  # $ rake pact:verify:dev
75
75
 
76
- Pact::VerificationTask.new(:dev) do | pact |
77
- pact.uri '../path-to-your-consumer-project/specs/pacts/my_consumer-my_provider.json'
76
+ Pact::VerificationTask.new(:dev) do | task |
77
+ task.uri '../path-to-your-consumer-project/specs/pacts/my_consumer-my_provider.json'
78
78
  end
79
79
  ```
80
80
 
@@ -84,6 +84,15 @@ At some stage, you'll want to be able to run your specs one at a time while you
84
84
 
85
85
  $ rake pact:verify PACT_DESCRIPTION="a request for something" PACT_PROVIDER_STATE="something exists"
86
86
 
87
+ ## Configuring RSpec
88
+
89
+ Pact uses dynamically created RSpec specs to verify pacts. If you want to modify the behaviour of the underlying RSpec execution, you can:
90
+
91
+ 1. Set `task.rspec_opts` in your custom rake VerificationTask, the same way you would with a normal RSpec rake task declaration.
92
+ 1. Configure RSpec in the pact_helper using the normal `RSpec.configure` code.
93
+
94
+ For future proofing though, try to use the provider state set_up/tear_down blocks where you can, because we may swap out RSpec for custom verification code in the future.
95
+
87
96
  ## Pact Helper location
88
97
 
89
98
  The search paths for the pact_helper are:
@@ -1,3 +1,3 @@
1
1
  require File.dirname(__FILE__) + '/lib/animal_service/api'
2
2
 
3
- run AnimalService::Api
3
+ run AnimalService::Api
@@ -1,5 +1,5 @@
1
1
  require 'sinatra/base'
2
- require 'animal_service/animal_repository'
2
+ require_relative 'animal_repository'
3
3
 
4
4
  module AnimalService
5
5
 
@@ -25,4 +25,4 @@ module AnimalService
25
25
  end
26
26
 
27
27
  end
28
- end
28
+ end
@@ -5,7 +5,7 @@ require 'pact/consumer'
5
5
  require 'rack/handler/webrick'
6
6
 
7
7
  module Pact
8
- class App < Thor
8
+ class CLI < Thor
9
9
 
10
10
  desc 'verify', "Verify a pact"
11
11
  method_option :pact_helper, aliases: "-h", desc: "Pact helper file", :required => true
@@ -45,6 +45,7 @@ module Pact
45
45
 
46
46
 
47
47
  def call
48
+ initialize_rspec
48
49
  setup_load_path
49
50
  load_pact_helper
50
51
  run_specs
@@ -52,10 +53,19 @@ module Pact
52
53
 
53
54
  private
54
55
 
56
+ def initialize_rspec
57
+ # With RSpec3, if the pact_helper loads a library that adds its own formatter before we set one,
58
+ # we will get a ProgressFormatter too, and get little dots sprinkled throughout our output.
59
+ require 'pact/rspec'
60
+ ::RSpec.configuration.add_formatter Pact::RSpec.formatter_class
61
+ end
62
+
55
63
  def setup_load_path
56
64
  require 'pact/provider/pact_spec_runner'
57
- lib = Dir.pwd + "/lib" # Assume we are running from within the project root. RSpec is smarter about this.
65
+ lib = File.join(Dir.pwd, "lib") # Assume we are running from within the project root. RSpec is smarter about this.
66
+ spec = File.join(Dir.pwd, "spec")
58
67
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
68
+ $LOAD_PATH.unshift(spec) if Dir.exist?(spec) && !$LOAD_PATH.include?(spec)
59
69
  end
60
70
 
61
71
  def load_pact_helper
@@ -54,8 +54,7 @@ module Pact
54
54
 
55
55
  config.color = true
56
56
  config.pattern = "pattern which doesn't match any files"
57
- config.backtrace_inclusion_patterns = [Regexp.new(Dir.getwd), /pact.*pact\.rake.*2/]
58
- config.backtrace_exclusion_patterns << /pact/
57
+ config.backtrace_inclusion_patterns = [Regexp.new(Dir.getwd), /bin\/pact/]
59
58
 
60
59
  config.extend Pact::Provider::RSpec::ClassMethods
61
60
  config.include Pact::Provider::RSpec::InstanceMethods
@@ -69,7 +68,10 @@ module Pact
69
68
  config.output_stream = Pact.configuration.output_stream
70
69
  end
71
70
 
72
- config.add_formatter Pact::RSpec.formatter_class
71
+ # Sometimes the formatter set in the cli.rb get set with an output of StringIO.. don't know why
72
+ formatter_class = Pact::RSpec.formatter_class
73
+ pact_formatter = ::RSpec.configuration.formatters.find {|f| f.class == formatter_class && f.output == ::RSpec.configuration.output_stream}
74
+ ::RSpec.configuration.add_formatter formatter_class unless pact_formatter
73
75
 
74
76
  config.before(:suite) do
75
77
  # Preload app before suite so the classes loaded in memory are consistent for
@@ -79,6 +81,7 @@ module Pact
79
81
  # (eg. with database_cleaner transactions)
80
82
  Pact.configuration.provider.app
81
83
  end
84
+
82
85
  end
83
86
 
84
87
  def run_specs
@@ -1,5 +1,5 @@
1
1
  require 'pact/provider/print_missing_provider_states'
2
- require 'rspec/core/formatters'
2
+ require 'rspec/core/formatters/documentation_formatter'
3
3
  require 'term/ansicolor'
4
4
 
5
5
  module Pact
data/lib/pact/rspec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rspec'
1
2
  # This is horrible, must work out a better way of doing this
2
3
  module Pact
3
4
  module RSpec
@@ -1,13 +1,14 @@
1
1
  require 'pact/provider/pact_helper_locator'
2
2
  require 'rake/file_utils'
3
+ require 'shellwords'
3
4
 
4
5
  module Pact
5
6
  module TaskHelper
6
7
 
7
8
  extend self
8
9
 
9
- def execute_pact_verify pact_uri = nil, pact_helper = nil
10
- execute_cmd verify_command(pact_helper || Pact::Provider::PactHelperLocater.pact_helper_path, pact_uri)
10
+ def execute_pact_verify pact_uri = nil, pact_helper = nil, rspec_opts = nil
11
+ execute_cmd verify_command(pact_helper || Pact::Provider::PactHelperLocater.pact_helper_path, pact_uri, rspec_opts)
11
12
  end
12
13
 
13
14
  def handle_verification_failure
@@ -15,8 +16,11 @@ module Pact
15
16
  abort if exit_status != 0
16
17
  end
17
18
 
18
- def verify_command pact_helper, pact_uri = nil
19
+ def verify_command pact_helper, pact_uri, rspec_opts
19
20
  command_parts = []
21
+ # Clear SPEC_OPTS, otherwise we can get extra formatters, creating duplicate output eg. CI Reporting.
22
+ # Allow deliberate configuration using rspec_opts in VerificationTask.
23
+ command_parts << "SPEC_OPTS=#{Shellwords.escape(rspec_opts || '')}"
20
24
  command_parts << FileUtils::RUBY
21
25
  command_parts << "-S pact verify"
22
26
  command_parts << "-h" << (pact_helper.end_with?(".rb") ? pact_helper : pact_helper + ".rb")
@@ -29,8 +29,10 @@ module Pact
29
29
  class VerificationTask < ::Rake::TaskLib
30
30
 
31
31
  attr_reader :pact_spec_configs
32
+ attr_accessor :rspec_opts
32
33
 
33
34
  def initialize(name)
35
+ @rspec_opts = nil
34
36
  @pact_spec_configs = []
35
37
  @name = name
36
38
  yield self
@@ -72,7 +74,7 @@ module Pact
72
74
  require 'pact/tasks/task_helper'
73
75
 
74
76
  exit_statuses = pact_spec_configs.collect do | config |
75
- Pact::TaskHelper.execute_pact_verify config[:uri], config[:pact_helper]
77
+ Pact::TaskHelper.execute_pact_verify config[:uri], config[:pact_helper], rspec_opts
76
78
  end
77
79
 
78
80
  Pact::TaskHelper.handle_verification_failure do
data/lib/pact/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pact
2
- VERSION = "1.2.1.rc1"
2
+ VERSION = "1.2.1.rc2"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'pact/app'
2
+ require 'pact/cli'
3
3
 
4
4
  module Pact
5
5
  describe SpecCriteria do
@@ -17,7 +17,7 @@ module Pact
17
17
  end
18
18
 
19
19
  context "with no pact_helper or pact URI" do
20
- let(:command) { "#{ruby_path} -S pact verify -h #{default_pact_helper_path}" }
20
+ let(:command) { "SPEC_OPTS='' #{ruby_path} -S pact verify -h #{default_pact_helper_path}" }
21
21
  it "executes the command" do
22
22
  expect(TaskHelper).to receive(:execute_cmd).with(command)
23
23
  TaskHelper.execute_pact_verify
@@ -25,7 +25,7 @@ module Pact
25
25
  end
26
26
 
27
27
  context "with a pact URI" do
28
- let(:command) { "#{ruby_path} -S pact verify -h #{default_pact_helper_path} -p #{pact_uri}" }
28
+ let(:command) { "SPEC_OPTS='' #{ruby_path} -S pact verify -h #{default_pact_helper_path} -p #{pact_uri}" }
29
29
  it "executes the command" do
30
30
  expect(TaskHelper).to receive(:execute_cmd).with(command)
31
31
  TaskHelper.execute_pact_verify(pact_uri)
@@ -34,7 +34,7 @@ module Pact
34
34
 
35
35
  context "with a pact URI and a pact_helper" do
36
36
  let(:custom_pact_helper_path) { '/custom/pact_helper.rb' }
37
- let(:command) { "#{ruby_path} -S pact verify -h #{custom_pact_helper_path} -p #{pact_uri}" }
37
+ let(:command) { "SPEC_OPTS='' #{ruby_path} -S pact verify -h #{custom_pact_helper_path} -p #{pact_uri}" }
38
38
  it "executes the command" do
39
39
  expect(TaskHelper).to receive(:execute_cmd).with(command)
40
40
  TaskHelper.execute_pact_verify(pact_uri, custom_pact_helper_path)
@@ -43,7 +43,7 @@ module Pact
43
43
 
44
44
  context "with a pact_helper with no .rb on the end" do
45
45
  let(:custom_pact_helper_path) { '/custom/pact_helper' }
46
- let(:command) { "#{ruby_path} -S pact verify -h #{custom_pact_helper_path}.rb -p #{pact_uri}" }
46
+ let(:command) { "SPEC_OPTS='' #{ruby_path} -S pact verify -h #{custom_pact_helper_path}.rb -p #{pact_uri}" }
47
47
  it "executes the command" do
48
48
  expect(TaskHelper).to receive(:execute_cmd).with(command)
49
49
  TaskHelper.execute_pact_verify(pact_uri, custom_pact_helper_path)
@@ -51,13 +51,22 @@ module Pact
51
51
  end
52
52
 
53
53
  context "with a pact URI and a nil pact_helper" do
54
- let(:command) { "#{ruby_path} -S pact verify -h #{default_pact_helper_path} -p #{pact_uri}" }
54
+ let(:command) { "SPEC_OPTS='' #{ruby_path} -S pact verify -h #{default_pact_helper_path} -p #{pact_uri}" }
55
55
  it "executes the command" do
56
56
  expect(TaskHelper).to receive(:execute_cmd).with(command)
57
57
  TaskHelper.execute_pact_verify(pact_uri, nil)
58
58
  end
59
59
  end
60
60
 
61
+ context "with rspec_opts" do
62
+ it "includes the rspec_opts as SPEC_OPTS in the command" do
63
+ expect(TaskHelper).to receive(:execute_cmd) do | command |
64
+ expect(command).to start_with("SPEC_OPTS=--reporter\\ SomeReporter #{ruby_path}")
65
+ end
66
+ TaskHelper.execute_pact_verify(pact_uri, nil, "--reporter SomeReporter")
67
+ end
68
+ end
69
+
61
70
  end
62
71
 
63
72
 
@@ -44,7 +44,7 @@ module Pact
44
44
 
45
45
  context "with no explicit pact_helper" do
46
46
  it 'verifies the pacts using the TaskHelper' do
47
- expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, nil)
47
+ expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, nil, nil)
48
48
  Rake::Task[@task_name].execute
49
49
  end
50
50
  end
@@ -52,7 +52,7 @@ module Pact
52
52
  context "with an explict pact_helper" do
53
53
  let(:verification_config) { [ uri: @pact_uri, pact_helper: @pact_helper] }
54
54
  it 'verifies the pacts using the TaskHelper' do
55
- expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, @pact_helper)
55
+ expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, @pact_helper, nil)
56
56
  Rake::Task[@task_name_with_explict_pact_helper].execute
57
57
  end
58
58
  end
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.2.1.rc1
4
+ version: 1.2.1.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -333,7 +333,7 @@ files:
333
333
  - example/zoo-app/spec/service_providers/pact_helper.rb
334
334
  - example/zoo-app/spec/spec_helper.rb
335
335
  - lib/pact.rb
336
- - lib/pact/app.rb
336
+ - lib/pact/cli.rb
337
337
  - lib/pact/configuration.rb
338
338
  - lib/pact/consumer.rb
339
339
  - lib/pact/consumer/app_manager.rb
@@ -456,7 +456,7 @@ files:
456
456
  - spec/integration/consumer_spec.rb
457
457
  - spec/integration/pact/consumer_configuration_spec.rb
458
458
  - spec/integration/pact/provider_configuration_spec.rb
459
- - spec/lib/pact/app_spec.rb
459
+ - spec/lib/pact/cli_spec.rb
460
460
  - spec/lib/pact/configuration_spec.rb
461
461
  - spec/lib/pact/consumer/app_manager_spec.rb
462
462
  - spec/lib/pact/consumer/configuration_spec.rb
@@ -559,7 +559,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
559
559
  version: '0'
560
560
  segments:
561
561
  - 0
562
- hash: 984907966293091128
562
+ hash: -3125311526466390789
563
563
  required_rubygems_version: !ruby/object:Gem::Requirement
564
564
  none: false
565
565
  requirements:
@@ -581,7 +581,7 @@ test_files:
581
581
  - spec/integration/consumer_spec.rb
582
582
  - spec/integration/pact/consumer_configuration_spec.rb
583
583
  - spec/integration/pact/provider_configuration_spec.rb
584
- - spec/lib/pact/app_spec.rb
584
+ - spec/lib/pact/cli_spec.rb
585
585
  - spec/lib/pact/configuration_spec.rb
586
586
  - spec/lib/pact/consumer/app_manager_spec.rb
587
587
  - spec/lib/pact/consumer/configuration_spec.rb