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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9bb93d26d0c2c0268df45e1d0c7b65bfac8fa71c
4
- data.tar.gz: 625d48a0cd5faa4c4c25d4ef2c0eb95954214edb
2
+ SHA256:
3
+ metadata.gz: 590ba41eee563126e54dbd3e6381ef5de82cf19ca7f64c7c8c7bcaf569fe6692
4
+ data.tar.gz: 8a40403e38f2e3691508a0eb8e5cb0b8380f8676fdb13bc16872faa1fd1d6175
5
5
  SHA512:
6
- metadata.gz: d608c3bf845f9945b2904a12c22ac8c66b3213b794e090fd4b2b9d4c7728e0d36652a9d2c8594d25ef423f64bb952e0702a665ae9129bd059883133f150b2f30
7
- data.tar.gz: 05181cb0c380d83d1fb509ec88ae90900abeb64edaff4c187e7ad250a1b5a06de4b7db4fb206d042a47ed66e6d95350d1aa6df6d5f0ac444bd723fedc7a87608
6
+ metadata.gz: 913b42c2cf80243ebe5a36af4208f5bcf2f25f0fb1525dc3eb84070203efec1283b227bf0479bea2489440b5d64158670e89f746f2b32305ee1f6c53e6437b97
7
+ data.tar.gz: 5c642f942401b018e98ac68f54a9de30be6bcc4a5b7f4973ec6b582e1be1d6a83c50d77042c8247903538c2ad571bd6089d682254906e012a04ad06a2aaa5b1e
@@ -1 +1 @@
1
- 2.0.0-p0
1
+ 2.6.5
@@ -0,0 +1,14 @@
1
+ ---
2
+ language: ruby
3
+
4
+ rvm:
5
+ - 2.3.0
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
9
+
10
+ bundler_args: --jobs=2
11
+ script:
12
+ - bundle exec rake
13
+
14
+ cache: bundler
@@ -1,26 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api_pi (0.2.2)
5
- map (~> 6.5)
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.3.5)
11
- crack (0.4.2)
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
- map (6.5.1)
14
- rake (10.1.0)
15
- safe_yaml (1.0.1)
16
- webmock (1.17.3)
17
- addressable (>= 2.2.7)
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
- rake (~> 10.1)
26
- webmock (~> 1.17)
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
- A ruby DSL to test expected values in a service API!
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
@@ -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.5'
22
- g.add_development_dependency 'webmock', '~> 1.17'
23
- g.add_development_dependency 'rake', '~> 10.1'
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
@@ -0,0 +1,12 @@
1
+ {
2
+ "metadata": {
3
+ "totalCount": 120,
4
+ "totalPageCount": 13
5
+ },
6
+ "results": {
7
+ "string": "I'm a String!",
8
+ "int": 12,
9
+ "here": "I'm present!",
10
+ "array": [0, 1, 2, 3]
11
+ }
12
+ }
@@ -2,14 +2,13 @@ require 'api_pi'
2
2
 
3
3
  set_header "api-pi-demo-header", "api-pi-example"
4
4
 
5
- get "http://apipi.apiary.io/tests" do
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 "body results.string" do
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 4
27
+ response.body.results.array.includes 3
29
28
  end
30
29
  end
@@ -5,7 +5,7 @@ require 'api_pi/assertion'
5
5
  require 'api_pi/version'
6
6
 
7
7
  module ApiPi
8
-
8
+
9
9
  # Build Headers, setting default User-Agent.
10
10
 
11
11
  HEADER = { "user-agent" => "ApiPi-v#{ApiPi::VERSION}"}
@@ -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)
@@ -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
- resp = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
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
@@ -1,3 +1,3 @@
1
1
  module ApiPi
2
- VERSION = '0.2.3'
2
+ VERSION = '0.9'
3
3
  end
@@ -3,7 +3,7 @@ require 'webmock/minitest'
3
3
  require 'api_pi'
4
4
 
5
5
  module ApiPi
6
- class TestCase < MiniTest::Unit::TestCase
6
+ class TestCase < Minitest::Test
7
7
 
8
8
  def setup
9
9
  map = { k: "v", a: [1,2,3], m: 1 }
@@ -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
@@ -5,7 +5,7 @@ module ApiPi
5
5
 
6
6
  def test_response_gathering
7
7
  r = ApiPi::Dsl.new(t:'t')
8
- r.test "metadata" do
8
+ r.test "metadata" do
9
9
  "test".is_a(String)
10
10
  end
11
11
  assert r.tests.has_key?('metadata'), r.tests['metadata']
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.2.3
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: 2014-05-08 00:00:00.000000000 Z
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.5'
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.5'
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: '1.17'
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: '1.17'
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: '10.1'
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: '10.1'
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/apiary.rb
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
- rubyforge_project:
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