pact-support 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/pact/consumer_contract/consumer_contract.rb +5 -44
- data/lib/pact/consumer_contract/interaction.rb +8 -13
- data/lib/pact/consumer_contract/response.rb +5 -1
- data/lib/pact/shared/active_support_support.rb +3 -3
- data/lib/pact/shared/request.rb +5 -13
- data/lib/pact/support/version.rb +1 -1
- data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -22
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -50
- data/spec/lib/pact/consumer_contract/request_spec.rb +0 -9
- data/spec/lib/pact/shared/request_spec.rb +0 -6
- data/tasks/spec.rake +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96c37218ffea4538adf60f7a93d1c494723d14c1
|
4
|
+
data.tar.gz: a54ca9babda872a3aec4412e2d3f2456dc915d72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f92a57c9ab90f83c059d23a17434dc4e9cb96424a9ef50953a750ec38bd994adc716b05b7495c76dc1ce1cb9e044ecae5e91517296d400d620b2bcb6eb2598a7
|
7
|
+
data.tar.gz: 0740b78cb0f67a31ef808efcd85e7c00274928247ae1dfa4d7becb401860eeb2c3d8757697de6213258b032770a3771b3f12a59fbfeba90007d50da88eb5ae4e
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@ Do this to generate your change history
|
|
2
2
|
|
3
3
|
git log --pretty=format:' * %h - %s (%an, %ad)'
|
4
4
|
|
5
|
+
### 0.1.0 (22 October 2014)
|
6
|
+
|
7
|
+
* fa7e03f - Removed JSON serialisation code from models. It has been moved to decorators in pact_mock-service. (bethesque, Wed Oct 22 12:53:21 2014 +1100)
|
8
|
+
|
5
9
|
### 0.0.4 (20 October 2014)
|
6
10
|
|
7
11
|
* ebe5e32 - Added differ for application/x-www-form-urlencoded bodies. (bethesque, Mon Oct 20 20:26:13 2014 +1100)
|
data/Gemfile.lock
CHANGED
@@ -9,11 +9,7 @@ require 'open-uri'
|
|
9
9
|
require_relative 'service_consumer'
|
10
10
|
require_relative 'service_provider'
|
11
11
|
require_relative 'interaction'
|
12
|
-
require_relative 'request'
|
13
12
|
require_relative 'pact_file'
|
14
|
-
require_relative 'file_name'
|
15
|
-
|
16
|
-
|
17
13
|
|
18
14
|
module Pact
|
19
15
|
|
@@ -21,8 +17,7 @@ module Pact
|
|
21
17
|
|
22
18
|
include SymbolizeKeys
|
23
19
|
include Logging
|
24
|
-
include
|
25
|
-
include ActiveSupportSupport
|
20
|
+
include PactFile
|
26
21
|
|
27
22
|
attr_accessor :interactions
|
28
23
|
attr_accessor :consumer
|
@@ -34,32 +29,13 @@ module Pact
|
|
34
29
|
@provider = attributes[:provider]
|
35
30
|
end
|
36
31
|
|
37
|
-
def to_hash
|
38
|
-
{
|
39
|
-
provider: @provider.as_json,
|
40
|
-
consumer: @consumer.as_json,
|
41
|
-
interactions: @interactions.collect(&:as_json),
|
42
|
-
metadata: {
|
43
|
-
pactSpecificationVersion: "1.0.0"
|
44
|
-
}
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
def as_json(options = {})
|
49
|
-
fix_all_the_things to_hash
|
50
|
-
end
|
51
|
-
|
52
|
-
def to_json(options = {})
|
53
|
-
as_json.to_json(options)
|
54
|
-
end
|
55
|
-
|
56
32
|
def self.from_hash(hash)
|
57
33
|
hash = symbolize_keys(hash)
|
58
|
-
new(
|
59
|
-
:interactions => hash[:interactions].collect { |hash| Interaction.from_hash(hash)},
|
34
|
+
new(
|
60
35
|
:consumer => ServiceConsumer.from_hash(hash[:consumer]),
|
61
|
-
:provider => ServiceProvider.from_hash(hash[:provider])
|
62
|
-
|
36
|
+
:provider => ServiceProvider.from_hash(hash[:provider]),
|
37
|
+
:interactions => hash[:interactions].collect { |hash| Interaction.from_hash(hash)}
|
38
|
+
)
|
63
39
|
end
|
64
40
|
|
65
41
|
def self.from_json string
|
@@ -95,20 +71,5 @@ module Pact
|
|
95
71
|
end
|
96
72
|
end
|
97
73
|
|
98
|
-
def pact_file_name
|
99
|
-
file_name consumer.name, provider.name
|
100
|
-
end
|
101
|
-
|
102
|
-
def pactfile_path
|
103
|
-
raise 'You must first specify a consumer and service name' unless (consumer && consumer.name && provider && provider.name)
|
104
|
-
@pactfile_path ||= file_path consumer.name, provider.name
|
105
|
-
end
|
106
|
-
|
107
|
-
def update_pactfile
|
108
|
-
logger.debug "Updating pact file for #{provider.name} at #{pactfile_path}"
|
109
|
-
File.open(pactfile_path, 'w') do |f|
|
110
|
-
f.write fix_json_formatting(JSON.pretty_generate(self))
|
111
|
-
end
|
112
|
-
end
|
113
74
|
end
|
114
75
|
end
|
@@ -24,17 +24,12 @@ module Pact
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def to_hash
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
fix_all_the_things to_hash
|
34
|
-
end
|
35
|
-
|
36
|
-
def to_json(options = {})
|
37
|
-
as_json.to_json(options)
|
27
|
+
{
|
28
|
+
description: description,
|
29
|
+
provider_state: provider_state,
|
30
|
+
request: request.to_hash,
|
31
|
+
response: response.to_hash
|
32
|
+
}
|
38
33
|
end
|
39
34
|
|
40
35
|
def matches_criteria? criteria
|
@@ -51,7 +46,7 @@ module Pact
|
|
51
46
|
end
|
52
47
|
|
53
48
|
def == other
|
54
|
-
other.is_a?(Interaction) &&
|
49
|
+
other.is_a?(Interaction) && to_hash == other.to_hash
|
55
50
|
end
|
56
51
|
|
57
52
|
def eq? other
|
@@ -67,7 +62,7 @@ module Pact
|
|
67
62
|
end
|
68
63
|
|
69
64
|
def to_s
|
70
|
-
|
65
|
+
to_hash.to_s
|
71
66
|
end
|
72
67
|
end
|
73
68
|
end
|
@@ -23,6 +23,10 @@ module Pact
|
|
23
23
|
self[:body]
|
24
24
|
end
|
25
25
|
|
26
|
+
def specified? key
|
27
|
+
self.key?(key.to_sym)
|
28
|
+
end
|
29
|
+
|
26
30
|
def body_allows_any_value?
|
27
31
|
body_not_specified? || body_is_empty_hash?
|
28
32
|
end
|
@@ -43,7 +47,7 @@ module Pact
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def body_not_specified?
|
46
|
-
!
|
50
|
+
!specified?(:body)
|
47
51
|
end
|
48
52
|
|
49
53
|
end
|
@@ -36,10 +36,10 @@ module Pact
|
|
36
36
|
# reparse the generated JSON into a hash and pretty_generate that... sigh...
|
37
37
|
# Oh ActiveSupport, why....
|
38
38
|
def fix_json_formatting json
|
39
|
-
if json
|
40
|
-
json
|
41
|
-
else
|
39
|
+
if json =~ /\{".*?":"/
|
42
40
|
JSON.pretty_generate(JSON.parse(json, create_additions: false))
|
41
|
+
else
|
42
|
+
json
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
data/lib/pact/shared/request.rb
CHANGED
@@ -22,14 +22,6 @@ module Pact
|
|
22
22
|
@query = is_unspecified?(query) ? query : Pact::Query.create(query)
|
23
23
|
end
|
24
24
|
|
25
|
-
def to_json(options = {})
|
26
|
-
as_json.to_json(options)
|
27
|
-
end
|
28
|
-
|
29
|
-
def as_json options = {}
|
30
|
-
to_hash
|
31
|
-
end
|
32
|
-
|
33
25
|
def to_hash
|
34
26
|
hash = {
|
35
27
|
method: method,
|
@@ -59,6 +51,10 @@ module Pact
|
|
59
51
|
http_method_modifies_resource? && body_specified?
|
60
52
|
end
|
61
53
|
|
54
|
+
def specified? key
|
55
|
+
!is_unspecified?(self.send(key))
|
56
|
+
end
|
57
|
+
|
62
58
|
protected
|
63
59
|
|
64
60
|
# Not including DELETE, as we don't care about the resources updated state.
|
@@ -74,17 +70,13 @@ module Pact
|
|
74
70
|
specified?(:body)
|
75
71
|
end
|
76
72
|
|
77
|
-
def specified? key
|
78
|
-
!is_unspecified?(self.send(key))
|
79
|
-
end
|
80
|
-
|
81
73
|
def is_unspecified? value
|
82
74
|
value.is_a? self.class.key_not_found.class
|
83
75
|
end
|
84
76
|
|
85
77
|
def to_hash_without_body_or_query
|
86
78
|
keep_keys = [:method, :path, :headers]
|
87
|
-
|
79
|
+
to_hash.reject{ |key, value| !keep_keys.include? key }.tap do | hash |
|
88
80
|
hash[:method] = method.upcase
|
89
81
|
end
|
90
82
|
end
|
data/lib/pact/support/version.rb
CHANGED
@@ -3,28 +3,6 @@ require 'pact/consumer_contract'
|
|
3
3
|
|
4
4
|
module Pact
|
5
5
|
describe ConsumerContract do
|
6
|
-
describe "as_json" do
|
7
|
-
|
8
|
-
class MockInteraction
|
9
|
-
def as_json(options ={})
|
10
|
-
{:mock => "interaction"}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
before do
|
15
|
-
allow(DateTime).to receive(:now).and_return(DateTime.strptime("2013-08-15T13:27:13+10:00"))
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:service_consumer) { double('ServiceConsumer', :as_json => {:a => 'consumer'}) }
|
19
|
-
let(:service_provider) { double('ServiceProvider', :as_json => {:a => 'provider'}) }
|
20
|
-
let(:pact) { ConsumerContract.new({:interactions => [MockInteraction.new], :consumer => service_consumer, :provider => service_provider }) }
|
21
|
-
let(:expected_as_json) { {:provider=>{:a=>"provider"}, :consumer=>{:a=>"consumer"}, :interactions=>[{:mock=>"interaction"}], :metadata=>{:pactSpecificationVersion=> "1.0.0" }} }
|
22
|
-
|
23
|
-
it "should return a hash representation of the Pact" do
|
24
|
-
expect(pact.as_json).to eq expected_as_json
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
6
|
|
29
7
|
describe ".from_json" do
|
30
8
|
let(:loaded_pact) { ConsumerContract.from_json(string) }
|
@@ -53,56 +53,6 @@ module Pact
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
describe "to JSON" do
|
57
|
-
let(:request) do
|
58
|
-
{
|
59
|
-
method: 'post',
|
60
|
-
path: '/foo',
|
61
|
-
body: Term.new(generate: 'waffle', matcher: /ffl/),
|
62
|
-
headers: { 'Content-Type' => 'application/json' },
|
63
|
-
query: '',
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
let(:response) do
|
68
|
-
{ baz: /qux/, wiffle: Term.new(generate: 'wiffle', matcher: /iff/) }
|
69
|
-
end
|
70
|
-
|
71
|
-
let(:parsed_result) do
|
72
|
-
JSON.load(subject.to_json)
|
73
|
-
end
|
74
|
-
|
75
|
-
subject { Interaction.from_hash('response' => response, 'request' => request) }
|
76
|
-
|
77
|
-
it "contains the request" do
|
78
|
-
expect(parsed_result['request']).to eq({
|
79
|
-
'method' => 'post',
|
80
|
-
'path' => '/foo',
|
81
|
-
'headers' => {
|
82
|
-
'Content-Type' => 'application/json'
|
83
|
-
},
|
84
|
-
'body' => Term.new(generate: 'waffle', matcher: /ffl/),
|
85
|
-
'query' => ''
|
86
|
-
})
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "response" do
|
90
|
-
|
91
|
-
it "serialises regexes" do
|
92
|
-
expect(parsed_result['response']['baz']).to eql /qux/
|
93
|
-
end
|
94
|
-
|
95
|
-
it "serialises terms" do
|
96
|
-
term = Term.new(generate:'wiffle', matcher: /iff/)
|
97
|
-
parsed_term = parsed_result['response']['wiffle']
|
98
|
-
expect(term.matcher).to eql parsed_term.matcher
|
99
|
-
expect(term.generate).to eql parsed_term.generate
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
56
|
describe "request_modifies_resource_without_checking_response_body?" do
|
107
57
|
|
108
58
|
let(:interaction) { Interaction.new(request: request, response: response)}
|
@@ -26,15 +26,6 @@ module Pact
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe "as_json" do
|
30
|
-
subject { Request::Expected.new(:get, '/path', {:header => 'value'}, {:body => 'yeah'}, "query", {some: 'options'}) }
|
31
|
-
context "with options" do
|
32
|
-
it "does not include the options because they are a temporary hack and should leave no trace of themselves in the pact file" do
|
33
|
-
expect(subject.as_json.key?(:options)).to be false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
29
|
describe "matching to actual requests" do
|
39
30
|
|
40
31
|
subject { Request::Expected.new(expected_method, expected_path, expected_headers, expected_body, expected_query, options) }
|
@@ -18,12 +18,6 @@ module Pact
|
|
18
18
|
|
19
19
|
subject { TestRequest.new("get", "/", {some: "things"}, {some: "things"} , "some=things") }
|
20
20
|
|
21
|
-
describe "#to_json" do
|
22
|
-
it "renders the keys in a sensible order" do
|
23
|
-
expect(subject.to_json).to match(/method.*path.*query.*headers.*body/)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
21
|
describe "#full_path" do
|
28
22
|
|
29
23
|
subject { TestRequest.new("get", "/something", {}, {some: "things"} , query).full_path }
|
data/tasks/spec.rake
CHANGED
@@ -2,5 +2,14 @@ require 'rspec/core/rake_task'
|
|
2
2
|
|
3
3
|
RSpec::Core::RakeTask.new(:spec)
|
4
4
|
|
5
|
-
task :
|
5
|
+
task :set_active_support_on do
|
6
|
+
ENV["LOAD_ACTIVE_SUPPORT"] = 'true'
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "This is to ensure that the gem still works even when active support JSON is loaded."
|
10
|
+
task :spec_with_active_support => [:set_active_support_on] do
|
11
|
+
Rake::Task['spec'].execute
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => [:spec, :spec_with_active_support]
|
6
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Fraser
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-10-
|
15
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: randexp
|