From 9da0f66414ed136df30ea7b541775bd78474bf54 Mon Sep 17 00:00:00 2001 From: Stefan Leszkiewicz Date: Fri, 17 Oct 2014 17:52:05 +1100 Subject: [PATCH] Bringing example up to date with latest pact version --- Gemfile | 1 - Gemfile.lock | 113 ++++----- README.md | 227 ++++++++---------- Rakefile | 28 +-- config.ru | 6 +- lib/client.rb | 11 +- lib/{producer.rb => provider.rb} | 9 +- ..._service_consumer-my_service_provider.json | 21 +- pacts/pact_helper.rb | 13 + spec/client_spec.rb | 57 +++-- spec/pacts/pact_helper.rb | 15 -- spec/spec_helper.rb | 18 -- 12 files changed, 230 insertions(+), 289 deletions(-) rename lib/{producer.rb => provider.rb} (60%) rename spec/pacts/my_consumer-my_producer.json => pacts/my_service_consumer-my_service_provider.json (51%) create mode 100644 pacts/pact_helper.rb delete mode 100644 spec/pacts/pact_helper.rb delete mode 100644 spec/spec_helper.rb diff --git a/Gemfile b/Gemfile index 82811cb..a38afd8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,4 @@ source 'https://rubygems.org' -source 'http://rea-rubygems' gem 'rake' gem 'activesupport' diff --git a/Gemfile.lock b/Gemfile.lock index d74b43f..a1fefd4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,93 +1,78 @@ GEM remote: https://rubygems.org/ - remote: http://rea-rubygems/ specs: - activesupport (4.0.0) - i18n (~> 0.6, >= 0.6.4) - minitest (~> 4.2) - multi_json (~> 1.3) + activesupport (4.1.6) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - atomic (1.1.13) - awesome_print (1.1.0) - capybara (2.1.0) - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - xpath (~> 2.0) - coderay (1.0.9) - columnize (0.3.6) - daemons (1.1.9) - debugger (1.6.1) + tzinfo (~> 1.1) + awesome_print (1.2.0) + coderay (1.1.0) + columnize (0.8.9) + debugger (1.6.8) columnize (>= 0.3.1) debugger-linecache (~> 1.2.0) - debugger-ruby_core_source (~> 1.2.3) + debugger-ruby_core_source (~> 1.3.5) debugger-linecache (1.2.0) - debugger-ruby_core_source (1.2.3) - diff-lcs (1.2.4) - eventmachine (1.0.3) + debugger-ruby_core_source (1.3.5) + diff-lcs (1.2.5) find_a_port (1.0.1) - hashie (2.0.5) - httparty (0.11.0) - multi_json (~> 1.0) + httparty (0.13.1) + json (~> 1.8) multi_xml (>= 0.5.2) - i18n (0.6.5) - json (1.8.0) + i18n (0.6.11) + json (1.8.1) method_source (0.8.2) - mime-types (1.24) - mini_portile (0.5.1) - minitest (4.7.5) - multi_json (1.7.9) + minitest (5.4.2) multi_xml (0.5.5) - nokogiri (1.6.0) - mini_portile (~> 0.5.0) - pact (0.1.23) - awesome_print (~> 1.1.0) - capybara (~> 2.1.0) + pact (1.3.3) + awesome_print (~> 1.1) find_a_port (~> 1.0.1) - hashie (~> 2.0.5) json rack-test (~> 0.6.2) randexp (~> 0.1.7) - rspec (~> 2.12) - thin + rspec (>= 2.14) + term-ansicolor (~> 1.0) thor - pry (0.9.12.2) - coderay (~> 1.0.5) - method_source (~> 0.8) + webrick + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) slop (~> 3.4) rack (1.5.2) - rack-protection (1.5.0) + rack-protection (1.5.3) rack rack-test (0.6.2) rack (>= 1.0) - rake (10.1.0) + rake (10.3.2) randexp (0.1.7) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.5) - rspec-expectations (2.14.2) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.3) - sinatra (1.4.3) + rspec (3.1.0) + rspec-core (~> 3.1.0) + rspec-expectations (~> 3.1.0) + rspec-mocks (~> 3.1.0) + rspec-core (3.1.7) + rspec-support (~> 3.1.0) + rspec-expectations (3.1.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.1.0) + rspec-mocks (3.1.3) + rspec-support (~> 3.1.0) + rspec-support (3.1.2) + sinatra (1.4.5) rack (~> 1.4) rack-protection (~> 1.4) tilt (~> 1.3, >= 1.3.4) - slop (3.4.6) - thin (1.5.1) - daemons (>= 1.0.9) - eventmachine (>= 0.12.6) - rack (>= 1.0.0) - thor (0.18.1) - thread_safe (0.1.2) - atomic + slop (3.6.0) + term-ansicolor (1.3.0) + tins (~> 1.0) + thor (0.19.1) + thread_safe (0.3.4) tilt (1.4.1) - tzinfo (0.3.37) - xpath (2.0.0) - nokogiri (~> 1.3) + tins (1.3.3) + tzinfo (1.2.2) + thread_safe (~> 0.1) + webrick (1.3.1) PLATFORMS ruby diff --git a/README.md b/README.md index b5476f9..eb6af57 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,82 @@ Example use of the Pact gem =========================== -When writing a lot of small services, testing the interactions between these becomes a major headache. That's the problem Pact is trying to solve. +When writing a lot of small services, testing the interactions between these becomes a major headache. +That's the problem Pact is trying to solve. -Integration tests tyically are slow and brittle, requiring each component to have it's own environment to run the tests in. With a micro-service architecture, this becomes even more of a problem. They also have to be 'all-knowing' and this makes them difficult to keep from being fragile. +Integration tests tyically are slow and brittle, requiring each component to have it's own environment to run the +tests in. With a micro-service architecture, this becomes even more of a problem. They also have to be 'all-knowing' +and this makes them difficult to keep from being fragile. -After J. B. Rainsberger's talk "Integrated Tests Are A Scam" people have been thinking how to get the confidence we need to deploy our software to production without having a tiresome integration test suite that does not give us all the coverage we think it does. +After J. B. Rainsberger's talk "Integrated Tests Are A Scam" people have been thinking how to get the confidence we +need to deploy our software to production without having a tiresome integration test suite that does not give us all +the coverage we think it does. -Pact is a ruby gem that allows you to define a pact between service consumers and providers. It provides a DSL for service consumers to define the request they will make to a service producer and the response they expect back. This expectation is used in the consumers specs to provide a mock producer, and is also played back in the producer specs to ensure the producer actually does provide the response the consumer expects. +Pact is a ruby gem that allows you to define a pact between service consumers and providers. It provides a DSL for +service consumers to define the request they will make to a service provider and the response they expect back. This +expectation is used in the consumers specs to provide a mock provider, and is also played back in the provider +pact:verify tasks to ensure the provider actually does provide the response the consumer expects. This allows you to test both sides of an integration point using fast unit tests. #Example Pact use# -Given we have a client that needs to make a HTTP GET request to a sinatra webapp, and requires a response in JSON format. The client would look something like: +Given we have a client that needs to make a HTTP GET request to a sinatra webapp, and requires a response in JSON +format. The client would look something like: client.rb: require 'httparty' require 'uri' require 'json' - + require 'ap' + class Client - - - def load_producer_json - response = HTTParty.get(URI::encode('http://localhost:8081/producer.json?valid_date=' + Time.now.httpdate)) + include HTTParty + base_uri 'http://service-somewhere' + + def load_provider_json + response = self.class.get("/provider.json?valid_date=#{URI::encode(Time.now.httpdate)}") if response.success? JSON.parse(response.body) end end - - + end -and the producer: -producer.rb - - require 'sinatra/base' - require 'json' - - - class Producer < Sinatra::Base +and the provider: +provider.rb - - get '/producer.json', :provides => 'json' do + class Provider < Sinatra::Base + + before do + content_type 'application/json;charset=utf-8' + end + + get '/provider.json', :provides => 'json' do valid_time = Time.parse(params[:valid_date]) JSON.pretty_generate({ :test => 'NO', - :valid_date => DateTime.now, + :date => "2013-08-16T15:31:20+10:00", :count => 1000 }) end - end -This producer expects a valid_date parameter in HTTP date format, and then returns some simple json back. +This provider expects a valid_date parameter in HTTP date format, and then returns some simple json back. -Running the client with the following rake task against the producer works nicely: +Running the client with the following rake task against the provider works nicely: desc 'Run the client' task :run_client => :init do require 'client' require 'ap' - ap Client.new.load_producer_json + ap Client.new.load_provider_json end - $ rake run_client - http://localhost:8081/producer.json?valid_date=Thu,%2015%20Aug%202013%2003:15:15%20GMT + http://localhost:8081/provider.json?valid_date=Thu,%2015%20Aug%202013%2003:15:15%20GMT { "test" => "NO", "valid_date" => "2013-08-15T13:31:39+10:00", @@ -77,12 +84,13 @@ Running the client with the following rake task against the producer works nicel } -Now lets get the client to use the data it gets back from the producer. Here is the updated client method that uses the returned data: +Now lets get the client to use the data it gets back from the provider. Here is the updated client method that uses the +returned data: client.rb def process_data - data = load_producer_json + data = load_provider_json ap data value = data['count'] / 100 date = Time.parse(data['date']) @@ -112,12 +120,10 @@ client_spec.rb: let(:response) { double('Response', :success? => true, :body => json_data.to_json) } - it 'can process the json payload from the producer' do - HTTParty.stub(:get).and_return(response) - expect(subject.process_data).to eql([1, Time.parse(json_data['date'])]) + it 'can process the json payload from the provider' do + expect(subject.process_data).to eql([10, Time.parse(json_data['date'])]) end - end Let's run this spec and see it all pass: @@ -127,7 +133,7 @@ Let's run this spec and see it all pass: Client - http://localhost:8081/producer.json?valid_date=Fri,%2016%20Aug%202013%2005:44:41%20GMT + http://localhost:8081/provider.json?valid_date=Fri,%2016%20Aug%202013%2005:44:41%20GMT { "test" => "NO", "date" => "2013-08-16T15:31:20+10:00", @@ -135,84 +141,68 @@ Let's run this spec and see it all pass: } 1 2013-08-16 15:31:20 +1000 - can process the json payload from the producer + can process the json payload from the provider Finished in 0.00409 seconds 1 example, 0 failures -However, there is a problem with this integration point. The producer returns a 'valid_date' while the consumer is trying to use 'date', which will blow up when run for real even with the tests all passing. Here is where Pact comes in. +However, there is a problem with this integration point. The provider returns a 'valid_date' while the consumer is +trying to use 'date', which will blow up when run for real even with the tests all passing. Here is where Pact comes in. #Pact to the rescue# Lets setup Pact in the consumer. Pact lets the consumers define the expectations for the integration point. -spec_helper.rb: - - require 'ap' - - require 'pact' - require 'pact/consumer/rspec' - - - $:.unshift 'lib' - - - Pact.configure do | config | - config.consumer do - name 'My Consumer' - end - end - - - Pact.with_producer "My Producer" do - mock_service :my_producer do - port 8081 + Pact.service_consumer "My Service Consumer" do + has_pact_with "My Service Provider" do + mock_service :my_service_provider do + port 8081 + end end end - -This defines a consumer and a producer that runs on port 8081. +This defines a consumer and a provider that runs on port 8081. The spec for the client now has a pact section. client_spec.rb: - describe 'pact with producer', :pact => true do + describe 'pact with provider', :pact => true do let(:date) { Time.now.httpdate } before do - my_producer. - given("producer is in a sane state"). - upon_receiving("a request for producer json"). - with({ - method: :get, - path: '/producer.json', - query: URI::encode('valid_date=' + date) - }). - will_respond_with({ - status: 200, - headers: { 'Content-Type' => 'application/json' }, - body: json_data - }) + my_service_provider.given("provider is in a sane state"). + upon_receiving("a request for provider json"). + with( + method: :get, + path: '/provider.json', + query: URI::encode('valid_date=' + date) + ). + will_respond_with( + status: 200, + headers: { 'Content-Type' => 'application/json;charset=utf-8' }, + body: json_data + ) end - it 'can process the json payload from the producer' do + it 'can process the json payload from the provider' do expect(subject.process_data).to eql([1, Time.parse(json_data['date'])]) end end -Running this spec still passes, but it creates a pact file which we can use to validate our assumptions on the producer side. +Running this spec still passes, but it creates a pact file which we can use to validate our assumptions +on the provider side. $ rake spec /Users/ronald/.rvm/rubies/ruby-1.9.3-p448/bin/ruby -S rspec ./spec/client_spec.rb Client - http://localhost:8081/producer.json?valid_date=Fri,%2016%20Aug%202013%2006:09:44%20GMT + http://localhost:8081/provider.json?valid_date=Fri,%2016%20Aug%202013%2006:09:44%20GMT { "test" => "NO", "date" => "2013-08-16T15:31:20+10:00", @@ -220,9 +210,9 @@ Running this spec still passes, but it creates a pact file which we can use to v } 1 2013-08-16 15:31:20 +1000 - can process the json payload from the producer - pact with producer - http://localhost:8081/producer.json?valid_date=Fri,%2016%20Aug%202013%2006:09:44%20GMT + can process the json payload from the provider + pact with provider + http://localhost:8081/provider.json?valid_date=Fri,%2016%20Aug%202013%2006:09:44%20GMT { "test" => "NO", "date" => "2013-08-16T15:31:20+10:00", @@ -230,80 +220,65 @@ Running this spec still passes, but it creates a pact file which we can use to v } 1 2013-08-16 15:31:20 +1000 - can process the json payload from the producer + can process the json payload from the provider - -Generated pact file (spec/pacts/my_consumer-my_producer.json): +Generated pact file (pacts/my_consumer-my_service_provider.json): { - "producer": { - "name": "My Producer" + "provider": { + "name": "My Service Provider" }, "consumer": { - "name": "My Consumer" + "name": "My Service Consumer" }, "interactions": [ { - "description": "a request for producer json", + "description": "a request for provider json", + "provider_state": "provider is in a sane state", "request": { "method": "get", - "path": "/producer.json", - "query": "valid_date=Fri,%2016%20Aug%202013%2006:09:44%20GMT" + "path": "/provider.json", + "query": "valid_date=Fri,%2017%20Oct%202014%2005:39:25%20GMT" }, "response": { "status": 200, "headers": { - "Content-Type": "application/json" + "Content-Type": "application/json;charset=utf-8" }, "body": { "test": "NO", "date": "2013-08-16T15:31:20+10:00", - "count": 100 + "count": 1000 } - }, - "producer_state": "producer is in a sane state" + } } ], "metadata": { - "date": "2013-08-16T16:09:44+10:00", - "pact_gem": { - "version": "0.1.23" - } + "pactSpecificationVersion": "1.0.0" } } -#Producer Setup# +#Provider Setup# -Pact has a rake task to verify the producer against the generated pact file. It can get the pact file from any URL (like the last sucessful CI build), but we just going to use the local one. Here is the addition to the Rakefile. +Pact has a rake task to verify the provider against the generated pact file. It can get the pact file from any URL +(like the last sucessful CI build), but we just going to use the local one. Here is the addition to the Rakefile. Rakefile: + require 'pact/tasks' - require 'pact' - require 'pact/verification_task' - - - Pact::VerificationTask.new(:local) do | pact | - pact.uri 'spec/pacts/my_consumer-my_producer.json', support_file: './spec/pacts/pact_helper' - end - -The pact_helper needs to tell Pact which Rack app it needs to test against. +This will automatically find and load the pact_helper.rb, and give us our verification tasks. spec/pacts/pact_helper.rb - Pact.with_consumer 'My Consumer' do - producer_state "producer is in a sane state" do - set_up do - # Create a thing here using your factory of choice - end + Pact.service_provider "My Service Provider" do + honours_pact_with 'My Service Consumer' do + pact_uri './pacts/my_service_consumer-my_service_provider.json' end end - - - require 'producer' - Pact.configure do | config | - config.producer do - name "My Producer" - app { Producer.new } + + Pact.provider_states_for "My Service Consumer" do + provider_state "provider is in a sane state" do + no_op end end @@ -312,9 +287,9 @@ Now if we run our pact verification task, it should fail. $ rake pact:verify:local - Pact in spec/pacts/my_consumer-my_producer.json - Given producer is in a sane state - a request for producer json to /producer.json + Pact in spec/pacts/my_consumer-my_service_provider.json + Given provider is in a sane state + a request for provider json to /provider.json returns a response which has status code 200 has a matching body (FAILED - 1) @@ -325,7 +300,7 @@ Now if we run our pact verification task, it should fail. Failures: - 1) Pact in spec/pacts/my_consumer-my_producer.json Given producer is in a sane state a request for producer json to /producer.json returns a response which has a matching body + 1) Pact in spec/pacts/my_service_consumer-my_service_provider.json Given provider is in a sane state a request for provider json to /provider.json returns a response which has a matching body Failure/Error: expect(parse_entity_from_response(last_response)).to match_term response['body'] { "date" => { @@ -338,4 +313,4 @@ Now if we run our pact verification task, it should fail. } } -Looks like we need to update the producer to return 'date' instead of 'valid_date', we also need to update the client expectation to return 1000 for the count and the correct content type (we expected application/json but got application/json;charset=utf-8). Doing this, and we now have fast unit tests on each side of the integration point instead of tedious integration tests. +Looks like we need to update the provider to return 'date' instead of 'valid_date', we also need to update the client expectation to return 1000 for the count. Doing this, and we now have fast unit tests on each side of the integration point instead of tedious integration tests. diff --git a/Rakefile b/Rakefile index 20089b5..bae2f2f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,34 +1,18 @@ # encoding: utf-8 require 'rubygems' -require 'bundler' - -begin - Bundler.setup(:default, :development) -rescue Bundler::BundlerError => e - $stderr.puts e.message - $stderr.puts "Run `bundle install` to install missing gems" - exit e.status_code -end - -require 'rake' +require 'bundler/setup' require 'rspec/core/rake_task' -RSpec::Core::RakeTask.new(:spec) +require 'pact/tasks' -task :default => [:spec, 'pact:tests'] +$LOAD_PATH << './lib' -$:.unshift 'lib' +RSpec::Core::RakeTask.new(:spec) +task :default => [:spec, 'pact:verify'] desc 'Run the client' task :run_client do require 'client' - require 'ap' + Client.base_uri 'localhost:8081' Client.new.process_data end - -require 'pact' -require 'pact/verification_task' - -Pact::VerificationTask.new(:local) do | pact | - pact.uri 'spec/pacts/my_consumer-my_producer.json', support_file: './spec/pacts/pact_helper' -end diff --git a/config.ru b/config.ru index 1bad2dc..013c025 100644 --- a/config.ru +++ b/config.ru @@ -1,2 +1,4 @@ -require './lib/producer' -run Producer +#/ -p 8081 + +require './lib/provider' +run Provider diff --git a/lib/client.rb b/lib/client.rb index 8529dcf..6bc9f31 100644 --- a/lib/client.rb +++ b/lib/client.rb @@ -1,20 +1,21 @@ require 'httparty' require 'uri' require 'json' +require 'ap' class Client + include HTTParty + base_uri 'http://service-somewhere' - def load_producer_json - url = URI::encode('http://localhost:8081/producer.json?valid_date=' + Time.now.httpdate) - puts url - response = HTTParty.get(url) + def load_provider_json + response = self.class.get("/provider.json?valid_date=#{URI::encode(Time.now.httpdate)}") if response.success? JSON.parse(response.body) end end def process_data - data = load_producer_json + data = load_provider_json ap data value = data['count'] / 100 date = Time.parse(data['date']) diff --git a/lib/producer.rb b/lib/provider.rb similarity index 60% rename from lib/producer.rb rename to lib/provider.rb index 7f10787..6d8c96e 100644 --- a/lib/producer.rb +++ b/lib/provider.rb @@ -1,9 +1,13 @@ require 'sinatra/base' require 'json' -class Producer < Sinatra::Base +class Provider < Sinatra::Base - get '/producer.json', :provides => 'json' do + before do + content_type 'application/json;charset=utf-8' + end + + get '/provider.json', :provides => 'json' do valid_time = Time.parse(params[:valid_date]) JSON.pretty_generate({ :test => 'NO', @@ -11,5 +15,4 @@ class Producer < Sinatra::Base :count => 1000 }) end - end diff --git a/spec/pacts/my_consumer-my_producer.json b/pacts/my_service_consumer-my_service_provider.json similarity index 51% rename from spec/pacts/my_consumer-my_producer.json rename to pacts/my_service_consumer-my_service_provider.json index 49c60f0..d86a292 100644 --- a/spec/pacts/my_consumer-my_producer.json +++ b/pacts/my_service_consumer-my_service_provider.json @@ -1,17 +1,18 @@ { - "producer": { - "name": "My Producer" + "provider": { + "name": "My Service Provider" }, "consumer": { - "name": "My Consumer" + "name": "My Service Consumer" }, "interactions": [ { - "description": "a request for producer json", + "description": "a request for provider json", + "provider_state": "provider is in a sane state", "request": { "method": "get", - "path": "/producer.json", - "query": "valid_date=Fri,%2016%20Aug%202013%2007:12:19%20GMT" + "path": "/provider.json", + "query": "valid_date=Fri,%2017%20Oct%202014%2006:44:24%20GMT" }, "response": { "status": 200, @@ -23,14 +24,10 @@ "date": "2013-08-16T15:31:20+10:00", "count": 1000 } - }, - "producer_state": "producer is in a sane state" + } } ], "metadata": { - "date": "2013-08-16T17:12:19+10:00", - "pact_gem": { - "version": "0.1.23" - } + "pactSpecificationVersion": "1.0.0" } } \ No newline at end of file diff --git a/pacts/pact_helper.rb b/pacts/pact_helper.rb new file mode 100644 index 0000000..24f6d6c --- /dev/null +++ b/pacts/pact_helper.rb @@ -0,0 +1,13 @@ +require 'pact/provider/rspec' + +Pact.service_provider "My Service Provider" do + honours_pact_with 'My Service Consumer' do + pact_uri './pacts/my_service_consumer-my_service_provider.json' + end +end + +Pact.provider_states_for "My Service Consumer" do + provider_state "provider is in a sane state" do + no_op + end +end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index b09da7c..f3d43cc 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -1,43 +1,58 @@ -require 'spec_helper' require 'client' +require 'pact/consumer/rspec' -describe Client do +Pact.configure do | config | + config.pact_dir = './pacts' +end + +Pact.service_consumer "My Service Consumer" do + has_pact_with "My Service Provider" do + mock_service :my_service_provider do + port 8081 + end + end +end + +describe Client, :pact => true do + + before do + Client.base_uri 'localhost:8081' + end let(:json_data) do { - "test" => "NO", - "date" => "2013-08-16T15:31:20+10:00", + "test" => "NO", + "date" => "2013-08-16T15:31:20+10:00", "count" => 1000 } end let(:response) { double('Response', :success? => true, :body => json_data.to_json) } - it 'can process the json payload from the producer' do - HTTParty.stub(:get).and_return(response) + it 'can process the json payload from the provider' do + allow(Client).to receive(:get) {response} expect(subject.process_data).to eql([10, Time.parse(json_data['date'])]) end - describe 'pact with producer', :pact => true do + describe 'pact with provider', :pact => true do let(:date) { Time.now.httpdate } before do - my_producer. - given("producer is in a sane state"). - upon_receiving("a request for producer json"). - with({ - method: :get, - path: '/producer.json', - query: URI::encode('valid_date=' + date) - }). - will_respond_with({ - status: 200, - headers: { 'Content-Type' => 'application/json;charset=utf-8' }, - body: json_data - }) + my_service_provider.given("provider is in a sane state"). + upon_receiving("a request for provider json"). + with( + method: :get, + path: '/provider.json', + query: URI::encode('valid_date=' + date) + ). + will_respond_with( + status: 200, + headers: { 'Content-Type' => 'application/json;charset=utf-8' }, + body: json_data + ) end - it 'can process the json payload from the producer' do + it 'can process the json payload from the provider' do expect(subject.process_data).to eql([10, Time.parse(json_data['date'])]) end diff --git a/spec/pacts/pact_helper.rb b/spec/pacts/pact_helper.rb deleted file mode 100644 index a5eced8..0000000 --- a/spec/pacts/pact_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -Pact.with_consumer 'My Consumer' do - producer_state "producer is in a sane state" do - set_up do - # Create a thing here using your factory of choice - end - end -end - -require 'producer' -Pact.configure do | config | - config.producer do - name "My Producer" - app { Producer.new } - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index 7617a7d..0000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'ap' - -require 'pact' -require 'pact/consumer/rspec' - -$:.unshift 'lib' - -Pact.configure do | config | - config.consumer do - name 'My Consumer' - end -end - -Pact.with_producer "My Producer" do - mock_service :my_producer do - port 8081 - end -end