Sha256: 0bdce092bdfa85c71ddcc37aafcb361b03d5687a7a649f274f1982be7b4fbd8d

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'rake/tasklib'
require 'pact/provider/pact_spec_runner'
require_relative 'pact_task_helper'

=begin
	To create a rake pact:verify:<something> task

	Pact::VerificationTask.new(:head) do | pact |
	  pact.uri 'http://master.cd.vpc.realestate.com.au/browse/BIQ-MAS/latestSuccessful/artifact/JOB2/Pacts/mas-contract_transaction_service.json'
    pact.uri 'http://master.cd.vpc.realestate.com.au/browse/BIQ-IMAGINARY-CONSUMER/latestSuccessful/artifact/JOB2/Pacts/imaginary_consumer-contract_transaction_service.json'
	end

	The pact.uri may be a local file system path or a remote URL.

	To run a pact:verify:xxx task you need to define a pact_helper.rb, ideally in spec/service_consumers.
	It should contain your service_provider definition, and load any provider state definition files.
	It should also load all your app's dependencies (eg by calling out to spec_helper)

	Eg.

	require 'spec_helper'
	require 'provider_states_for_my_consumer'

	Pact.service_provider "My Provider" do
		app { TestApp.new }
	end

=end


module Pact
	class VerificationTask < ::Rake::TaskLib
	  attr_reader :pact_spec_config

	  include PactTaskHelper
	  def initialize(name)
	    @pact_spec_config = []
	    @name = name
	    yield self
	    define_rake_task
	  end

	  def uri(uri, options = {})
	    @pact_spec_config << {uri: uri, support_file: options[:support_file]}
	  end

	  private

	  attr_reader :name

	  def define_rake_task
	  	namespace :pact do
	  	  desc "Verify provider against the consumer pacts for #{name}"
	  	  task "verify:#{name}" do
	  	    exit_status = Provider::PactSpecRunner.run(pact_spec_config)
	  	    fail failure_message if exit_status != 0
	  	  end
	  	end
	  end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact-1.0.4 lib/pact/verification_task.rb