pacto 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -9
- data/lib/pacto/response.rb +5 -1
- data/lib/pacto/version.rb +1 -1
- data/spec/pacto/response_spec.rb +19 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Pacto
|
2
2
|
|
3
3
|
Pacto is a Ruby implementation of the [Consumer-Driven Contracts](http://martinfowler.com/articles/consumerDrivenContracts.html)
|
4
|
-
pattern for evolving services.
|
4
|
+
pattern for evolving services. Its main features are:
|
5
5
|
|
6
|
-
- A simple language for specifying a contract
|
7
|
-
- An automated way to validate that a producer meets
|
6
|
+
- A simple language for specifying a contract;
|
7
|
+
- An automated way to validate that a producer meets its consumer's requirements;
|
8
8
|
- An auto-generated stub to be used in the consumer's acceptance tests.
|
9
9
|
|
10
10
|
It was developed in a micro-services environment, specifically a RESTful one, so expect it to be opinionated. Although
|
@@ -18,15 +18,15 @@ an HTTP interaction, which is composed of two main parts: a request and a respon
|
|
18
18
|
|
19
19
|
A request has the following attributes:
|
20
20
|
|
21
|
-
- Method: the method of the HTTP request (e.g. GET, POST, PUT, DELETE)
|
22
|
-
- Path: the relative path (without host) of the provider's endpoint
|
23
|
-
- Headers: headers sent in the HTTP request
|
21
|
+
- Method: the method of the HTTP request (e.g. GET, POST, PUT, DELETE);
|
22
|
+
- Path: the relative path (without host) of the provider's endpoint;
|
23
|
+
- Headers: headers sent in the HTTP request;
|
24
24
|
- Params: any data or parameters of the HTTP request (e.g. query string for GET, body for POST).
|
25
25
|
|
26
26
|
A response has the following attributes:
|
27
27
|
|
28
|
-
- Status: the HTTP response status code (e.g. 200, 404, 500)
|
29
|
-
- Headers: the HTTP response headers
|
28
|
+
- Status: the HTTP response status code (e.g. 200, 404, 500);
|
29
|
+
- Headers: the HTTP response headers;
|
30
30
|
- Body: a JSON Schema defining the expected structure of the HTTP response body.
|
31
31
|
|
32
32
|
Pacto relies on a simple, JSON based language for defining contracts. Below is an example contract for a GET request
|
@@ -74,7 +74,7 @@ Pacto includes a default Rake task. To use it, include it in your Rakefile:
|
|
74
74
|
|
75
75
|
Validating a contract against a provider is as simple as running:
|
76
76
|
|
77
|
-
$ rake pacto:validate[host,dir]
|
77
|
+
$ rake pacto:validate[host,dir] # Validates all contracts in a given directory against a given host
|
78
78
|
|
79
79
|
It is recommended that you also include [colorize](https://github.com/fazibear/colorize) to get prettier, colorful output.
|
80
80
|
|
data/lib/pacto/response.rb
CHANGED
@@ -21,7 +21,11 @@ module Pacto
|
|
21
21
|
return [ "Invalid headers: expected #{@definition['headers'].inspect} to be a subset of #{response.headers.inspect}" ]
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
if @definition['body']
|
25
|
+
JSON::Validator.fully_validate(@definition['body'], response.body)
|
26
|
+
else
|
27
|
+
[]
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
data/lib/pacto/version.rb
CHANGED
data/spec/pacto/response_spec.rb
CHANGED
@@ -99,6 +99,25 @@ module Pacto
|
|
99
99
|
response.validate(fake_response).should == errors
|
100
100
|
end
|
101
101
|
end
|
102
|
+
|
103
|
+
context 'when body not specified' do
|
104
|
+
let(:definition) do
|
105
|
+
{
|
106
|
+
'status' => status,
|
107
|
+
'headers' => headers
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should not validate body' do
|
112
|
+
JSON::Validator.should_not_receive(:fully_validate)
|
113
|
+
response = described_class.new(definition)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should give no errors' do
|
117
|
+
response = described_class.new(definition)
|
118
|
+
response.validate(fake_response).should == []
|
119
|
+
end
|
120
|
+
end
|
102
121
|
end
|
103
122
|
end
|
104
123
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pacto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: webmock
|