api_pi 0.2.3 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +14 -0
- data/Gemfile.lock +20 -11
- data/README.md +6 -6
- data/api_pi.gemspec +6 -5
- data/example/example.json +12 -0
- data/example/{apiary.rb → example.rb} +3 -4
- data/lib/api_pi.rb +1 -1
- data/lib/api_pi/assertion.rb +15 -15
- data/lib/api_pi/request.rb +4 -2
- data/lib/api_pi/version.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/test_assertions.rb +4 -4
- data/test/unit/test_dsl.rb +1 -1
- metadata +36 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 590ba41eee563126e54dbd3e6381ef5de82cf19ca7f64c7c8c7bcaf569fe6692
|
4
|
+
data.tar.gz: 8a40403e38f2e3691508a0eb8e5cb0b8380f8676fdb13bc16872faa1fd1d6175
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 913b42c2cf80243ebe5a36af4208f5bcf2f25f0fb1525dc3eb84070203efec1283b227bf0479bea2489440b5d64158670e89f746f2b32305ee1f6c53e6437b97
|
7
|
+
data.tar.gz: 5c642f942401b018e98ac68f54a9de30be6bcc4a5b7f4973ec6b582e1be1d6a83c50d77042c8247903538c2ad571bd6089d682254906e012a04ad06a2aaa5b1e
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.5
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,26 +1,35 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
api_pi (0.2.
|
5
|
-
map (~> 6.
|
4
|
+
api_pi (0.2.6)
|
5
|
+
map (~> 6.6)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
addressable (2.
|
11
|
-
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
crack (0.4.3)
|
12
13
|
safe_yaml (~> 1.0.0)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
hashdiff (1.0.0)
|
15
|
+
map (6.6.0)
|
16
|
+
minitest (5.8.5)
|
17
|
+
public_suffix (4.0.1)
|
18
|
+
rake (13.0.0)
|
19
|
+
safe_yaml (1.0.5)
|
20
|
+
webmock (3.7.6)
|
21
|
+
addressable (>= 2.3.6)
|
18
22
|
crack (>= 0.3.2)
|
23
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
19
24
|
|
20
25
|
PLATFORMS
|
21
26
|
ruby
|
22
27
|
|
23
28
|
DEPENDENCIES
|
24
29
|
api_pi!
|
25
|
-
|
26
|
-
|
30
|
+
minitest (~> 5.8.4)
|
31
|
+
rake (~> 13.0.0)
|
32
|
+
webmock (~> 3.7.6)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.17.2
|
data/README.md
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# API P.I.
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/benwoody/api_pi.svg)](https://travis-ci.org/benwoody/api_pi)
|
4
|
+
|
5
|
+
A ruby DSL to test JSON contracts.
|
4
6
|
|
5
7
|
An example test can be found in the example/ directory.
|
6
8
|
|
7
9
|
## Install
|
8
10
|
|
9
|
-
Api P.I. requires ruby 2.0.0+
|
10
|
-
|
11
11
|
Install the gem:
|
12
12
|
|
13
13
|
$ gem install api_pi
|
14
|
-
|
14
|
+
|
15
15
|
## Usage
|
16
16
|
|
17
17
|
### GETting Data
|
@@ -59,7 +59,7 @@ Header fields can be queried using the following format:
|
|
59
59
|
`response.header` is required in order to use dot notation on header fields.
|
60
60
|
|
61
61
|
Example:
|
62
|
-
|
62
|
+
|
63
63
|
response.header.connection.is 'keep-alive'
|
64
64
|
response.header.contenttype.is 'application/json'
|
65
65
|
|
@@ -132,7 +132,7 @@ This goes through the array and tests every item in it!
|
|
132
132
|
"this".is "that" => false
|
133
133
|
|
134
134
|
### is_a, is_an
|
135
|
-
|
135
|
+
|
136
136
|
The `is_a` and `is_an` assertions are used to assert Type on a field:
|
137
137
|
|
138
138
|
"Hello, World!".is_a String => true
|
data/api_pi.gemspec
CHANGED
@@ -16,9 +16,10 @@ Gem::Specification.new do |g|
|
|
16
16
|
g.test_files = `git ls-files -- test/*`.split("\n")
|
17
17
|
|
18
18
|
g.extra_rdoc_files = ["README.md"]
|
19
|
-
g.required_ruby_version = '>= 2.0.0'
|
20
|
-
|
21
|
-
g.add_dependency 'map', '~> 6.
|
22
|
-
g.add_development_dependency '
|
23
|
-
g.add_development_dependency '
|
19
|
+
g.required_ruby_version = '>= 2.0.0'
|
20
|
+
|
21
|
+
g.add_dependency 'map', '~> 6.6'
|
22
|
+
g.add_development_dependency 'minitest', '~>5.8.4'
|
23
|
+
g.add_development_dependency 'webmock', '~> 3.7.6'
|
24
|
+
g.add_development_dependency 'rake', '~> 13.0.0'
|
24
25
|
end
|
@@ -2,14 +2,13 @@ require 'api_pi'
|
|
2
2
|
|
3
3
|
set_header "api-pi-demo-header", "api-pi-example"
|
4
4
|
|
5
|
-
get "
|
5
|
+
get "https://raw.githubusercontent.com/benwoody/api_pi/master/example/example.json" do
|
6
6
|
|
7
7
|
test "headers" do
|
8
|
-
response.header.contenttype.is "application/json"
|
9
8
|
response.code.is 200
|
10
9
|
end
|
11
10
|
|
12
|
-
test "
|
11
|
+
test "results.string" do
|
13
12
|
response.body.results.string.is_a String
|
14
13
|
response.body.results.string.matches /\w*/
|
15
14
|
end
|
@@ -25,6 +24,6 @@ get "http://apipi.apiary.io/tests" do
|
|
25
24
|
end
|
26
25
|
|
27
26
|
test "results.array" do
|
28
|
-
response.body.results.array.includes
|
27
|
+
response.body.results.array.includes 3
|
29
28
|
end
|
30
29
|
end
|
data/lib/api_pi.rb
CHANGED
data/lib/api_pi/assertion.rb
CHANGED
@@ -15,13 +15,13 @@ class Object
|
|
15
15
|
end
|
16
16
|
true
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
# `is` assertions are used to compare exact values.
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# "this".is "this" => true
|
22
22
|
# 200.is "200" => true
|
23
23
|
# "this".is "that" => false
|
24
|
-
|
24
|
+
|
25
25
|
def is this
|
26
26
|
msg = "#{self} is not #{this}"
|
27
27
|
if this.is_a? Integer
|
@@ -32,29 +32,29 @@ class Object
|
|
32
32
|
end
|
33
33
|
|
34
34
|
# The `is_a` and `is_an` assertions are used to assert Type on a field:
|
35
|
-
#
|
35
|
+
#
|
36
36
|
# "Hello, World!".is_a String => true
|
37
37
|
# 3.14159265359.is_a Float => true
|
38
38
|
# "Not an array!".is_an Array => false
|
39
|
-
|
39
|
+
|
40
40
|
def is_a klass
|
41
41
|
msg = "#{self} is not a #{klass}"
|
42
|
-
check_if self.is_a?(klass), msg
|
42
|
+
check_if self.is_a?(klass), msg
|
43
43
|
end
|
44
44
|
alias :is_an :is_a
|
45
45
|
|
46
46
|
# The `has_key` assertion can be used to query if a certain
|
47
47
|
# field is present in a JSON block:
|
48
|
-
#
|
48
|
+
#
|
49
49
|
# { "here": "present!" }.has_key "here" => true
|
50
50
|
# { "here": "present!" }.has_key "nope!" => false
|
51
|
-
|
51
|
+
|
52
52
|
def has_key kkey
|
53
53
|
msg = "#{kkey} was not found in #{self.keys.join(', ')}}"
|
54
54
|
check_if self.respond_to?(kkey), msg
|
55
55
|
end
|
56
56
|
|
57
|
-
# The `has_keys` assertion works the same as `has_key`, except it takes
|
57
|
+
# The `has_keys` assertion works the same as `has_key`, except it takes
|
58
58
|
# multiple keys and tests them all at once:
|
59
59
|
#
|
60
60
|
# { "here": "present!", "hello": "world!" }.has_keys "here","hello" => true
|
@@ -71,7 +71,7 @@ class Object
|
|
71
71
|
true
|
72
72
|
else
|
73
73
|
nf = not_found.join(", ")
|
74
|
-
msg = "#{nf} were not found in #{self.keys.join(', ')}"
|
74
|
+
msg = "#{nf} were not found in #{self.keys.join(', ')}"
|
75
75
|
raise ApiPi::AssertionError, msg
|
76
76
|
end
|
77
77
|
end
|
@@ -88,7 +88,7 @@ class Object
|
|
88
88
|
end
|
89
89
|
|
90
90
|
# `matches` expectes a Regex formed value.
|
91
|
-
#
|
91
|
+
#
|
92
92
|
# "hello".matches /ll/ => true
|
93
93
|
|
94
94
|
def matches regex
|
@@ -97,7 +97,7 @@ class Object
|
|
97
97
|
end
|
98
98
|
|
99
99
|
# `includes` can be used for array to query if specific values are present:
|
100
|
-
#
|
100
|
+
#
|
101
101
|
# [1,2,3,4].includes 2 => true
|
102
102
|
|
103
103
|
def includes item
|
@@ -106,7 +106,7 @@ class Object
|
|
106
106
|
end
|
107
107
|
|
108
108
|
# `not_nil?` checks to see if the value is nil:
|
109
|
-
#
|
109
|
+
#
|
110
110
|
# nil.not_nil? => false
|
111
111
|
# "something".not_nil? => true
|
112
112
|
|
@@ -116,10 +116,10 @@ class Object
|
|
116
116
|
end
|
117
117
|
|
118
118
|
# `stripped?` will test is there is whitespace before or after a string:
|
119
|
-
#
|
119
|
+
#
|
120
120
|
# "works".stripped? => true
|
121
121
|
# " spaces ".stripped? => false
|
122
|
-
|
122
|
+
|
123
123
|
def stripped?
|
124
124
|
msg = "#{self} contains whitespace"
|
125
125
|
check_if(self.strip == self, msg)
|
data/lib/api_pi/request.rb
CHANGED
@@ -9,7 +9,9 @@ module Kernel
|
|
9
9
|
uri = URI.parse url
|
10
10
|
get = Net::HTTP::Get.new(uri)
|
11
11
|
req = Net::HTTPHeader.build_headers get
|
12
|
-
|
12
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
13
|
+
http.use_ssl = (uri.scheme == 'https')
|
14
|
+
resp = http.request req
|
13
15
|
json = net_parse resp
|
14
16
|
ApiPi::Dsl.new(json).parse(url, block)
|
15
17
|
end
|
@@ -21,7 +23,7 @@ module Kernel
|
|
21
23
|
end
|
22
24
|
|
23
25
|
private
|
24
|
-
|
26
|
+
|
25
27
|
# Groups all of the response parsing
|
26
28
|
|
27
29
|
def net_parse response
|
data/lib/api_pi/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -2,10 +2,10 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ApiPi
|
4
4
|
class TestAssertions < TestCase
|
5
|
-
|
5
|
+
|
6
6
|
def test_patch_methods
|
7
7
|
assert Object.respond_to?(:check_if), Object.check_if(true, "Yep")
|
8
|
-
assert Object.respond_to?(:is), Object.is(Object)
|
8
|
+
assert Object.respond_to?(:is), Object.is(Object)
|
9
9
|
assert Object.respond_to?(:is_a), @map.k.is_a(String)
|
10
10
|
assert Object.respond_to?(:is_an), Object.is_an(Object)
|
11
11
|
assert Object.respond_to?(:has_key), @map.has_key(:k)
|
@@ -38,7 +38,7 @@ module ApiPi
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_is_a__with_true
|
41
|
-
assert "string".is_a(String)
|
41
|
+
assert "string".is_a(String)
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_is_a__with_false
|
@@ -58,7 +58,7 @@ module ApiPi
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_has_keys__with_false
|
61
|
-
assert_raises(ApiPi::AssertionError) { @map.has_keys(:n,:r) }
|
61
|
+
assert_raises(ApiPi::AssertionError) { @map.has_keys(:n,:r) }
|
62
62
|
end
|
63
63
|
|
64
64
|
def test_lacks_key__with_true
|
data/test/unit/test_dsl.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_pi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.9'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Woodall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: map
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '6.
|
19
|
+
version: '6.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '6.
|
26
|
+
version: '6.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.8.4
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.8.4
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: webmock
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - ~>
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 3.7.6
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - ~>
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 3.7.6
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - ~>
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 13.0.0
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - ~>
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 13.0.0
|
55
69
|
description: A ruby DSL to validate API requests.
|
56
70
|
email: mail@benwoodall.com
|
57
71
|
executables: []
|
@@ -59,14 +73,16 @@ extensions: []
|
|
59
73
|
extra_rdoc_files:
|
60
74
|
- README.md
|
61
75
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .ruby-version
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- ".travis.yml"
|
64
79
|
- Gemfile
|
65
80
|
- Gemfile.lock
|
66
81
|
- README.md
|
67
82
|
- Rakefile
|
68
83
|
- api_pi.gemspec
|
69
|
-
- example/
|
84
|
+
- example/example.json
|
85
|
+
- example/example.rb
|
70
86
|
- lib/api_pi.rb
|
71
87
|
- lib/api_pi/assertion.rb
|
72
88
|
- lib/api_pi/case.rb
|
@@ -86,17 +102,16 @@ require_paths:
|
|
86
102
|
- lib
|
87
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
104
|
requirements:
|
89
|
-
- -
|
105
|
+
- - ">="
|
90
106
|
- !ruby/object:Gem::Version
|
91
107
|
version: 2.0.0
|
92
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
109
|
requirements:
|
94
|
-
- -
|
110
|
+
- - ">="
|
95
111
|
- !ruby/object:Gem::Version
|
96
112
|
version: '0'
|
97
113
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.0.0
|
114
|
+
rubygems_version: 3.0.3
|
100
115
|
signing_key:
|
101
116
|
specification_version: 4
|
102
117
|
summary: API validation DSL
|