pacto 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO.md +1 -0
- data/lib/pacto/response.rb +5 -5
- data/lib/pacto/version.rb +1 -1
- data/spec/pacto/response_spec.rb +4 -14
- metadata +2 -2
data/TODO.md
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
- 'default' value to be used when it is present with an array of types
|
14
14
|
- Support 'null' attribute type
|
15
15
|
- Validate contract structure in a rake task. Then assume all contracts are valid.
|
16
|
+
- When a request is not OK (200), the body may not be a json. Add support to ignore the body.
|
16
17
|
|
17
18
|
## Assumptions
|
18
19
|
|
data/lib/pacto/response.rb
CHANGED
@@ -13,15 +13,15 @@ module Pacto
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def validate(response)
|
16
|
-
@errors = []
|
17
16
|
if @definition['status'] != response.status
|
18
|
-
|
17
|
+
return [ "Invalid status: expected #{@definition['status']} but got #{response.status}" ]
|
19
18
|
end
|
19
|
+
|
20
20
|
unless @definition['headers'].normalize_keys.subset_of?(response.headers.normalize_keys)
|
21
|
-
|
21
|
+
return [ "Invalid headers: expected #{@definition['headers'].inspect} to be a subset of #{response.headers.inspect}" ]
|
22
22
|
end
|
23
|
-
|
24
|
-
@
|
23
|
+
|
24
|
+
JSON::Validator.fully_validate(@definition['body'], response.body)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/pacto/version.rb
CHANGED
data/spec/pacto/response_spec.rb
CHANGED
@@ -44,23 +44,13 @@ module Pacto
|
|
44
44
|
response.validate(fake_response).should == []
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
48
|
-
it 'should not return any errors' do
|
49
|
-
JSON::Validator.should_receive(:fully_validate).
|
50
|
-
with(definition['body'], fake_response.body).
|
51
|
-
and_return([])
|
52
|
-
|
53
|
-
response = described_class.new(definition)
|
54
|
-
response.validate(fake_response).should == []
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
47
|
+
|
58
48
|
context 'when status does not match' do
|
59
49
|
let(:status) { 500 }
|
60
50
|
|
61
51
|
it 'should return a status error' do
|
62
|
-
JSON::Validator.
|
63
|
-
|
52
|
+
JSON::Validator.should_not_receive(:fully_validate)
|
53
|
+
|
64
54
|
response = described_class.new(definition)
|
65
55
|
response.validate(fake_response).should == ["Invalid status: expected #{definition['status']} but got #{status}"]
|
66
56
|
end
|
@@ -70,7 +60,7 @@ module Pacto
|
|
70
60
|
let(:headers) { {'Content-Type' => 'text/html'} }
|
71
61
|
|
72
62
|
it 'should return a header error' do
|
73
|
-
JSON::Validator.
|
63
|
+
JSON::Validator.should_not_receive(:fully_validate)
|
74
64
|
|
75
65
|
response = described_class.new(definition)
|
76
66
|
response.validate(fake_response).should == ["Invalid headers: expected #{definition['headers'].inspect} to be a subset of #{headers.inspect}"]
|
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.1.
|
4
|
+
version: 0.1.1
|
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-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: webmock
|