api-spec 0.1.1 → 0.2.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/lib/api_spec/configuration.rb +20 -0
- data/lib/api_spec/cucumber.rb +2 -2
- data/lib/api_spec/helpers.rb +16 -7
- data/lib/api_spec/parameters.rb +1 -1
- data/lib/api_spec/state.rb +1 -1
- data/lib/api_spec/version.rb +2 -2
- data/lib/api_spec.rb +2 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ee6a0304cf9ce5c134154b06cb0dc9ee4c22d94
|
4
|
+
data.tar.gz: 1c9101fd8201f89accffea9c5a1c5bef4e11dca1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9c7e6c52db2107ff590f518c482de786ab1d5d15642984103854385c9503653cbca6f78a11f154965109fb11f04d09ad8c9d2437498e1849acec0ea051a276e
|
7
|
+
data.tar.gz: bfd4fa132b73db8f9e81d39ca2e5f6fb1634beea89fad793598b1d3de25364367821256bb694ab7aa66b8df67b0eca9b498872b8d68ec5e86e1ef5561689530b
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class ApiSpec
|
2
|
+
class Configuration < Struct.new(:http_client)
|
3
|
+
end
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :configuration
|
7
|
+
|
8
|
+
def configure
|
9
|
+
self.configuration ||= Configuration.new
|
10
|
+
set_defaults
|
11
|
+
yield(configuration) if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def set_defaults
|
17
|
+
configuration.http_client = RestClient
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/api_spec/cucumber.rb
CHANGED
@@ -16,7 +16,7 @@ end
|
|
16
16
|
|
17
17
|
When(/^I GET "(.*?)"$/) do |path|
|
18
18
|
parameters = ApiSpec::Parameters.new(:get, path)
|
19
|
-
@response =
|
19
|
+
@response = http_client.get parameters.url, test_headers
|
20
20
|
puts "@response = #{@response}"
|
21
21
|
end
|
22
22
|
|
@@ -29,7 +29,7 @@ When(/^I DELETE "(.*?)" with:$/) do |path, table|
|
|
29
29
|
end
|
30
30
|
|
31
31
|
Then(/^the status code is (\d+)$/) do |code|
|
32
|
-
@response.
|
32
|
+
@response.status.to_s.should == code
|
33
33
|
end
|
34
34
|
|
35
35
|
Then(/^the Content\-Type is (.*)$/) do |content_type|
|
data/lib/api_spec/helpers.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
require "rest-client"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# Make RestClient compatible with rack test helpers
|
4
|
+
RestClient::Response.class_eval do
|
5
|
+
alias_method :status, :code
|
6
|
+
end
|
7
|
+
|
8
|
+
class ApiSpec
|
9
|
+
class ErrorResponse < Struct.new(:status, :body)
|
5
10
|
end
|
6
11
|
|
7
12
|
module Helpers
|
@@ -18,16 +23,16 @@ module ApiSpec
|
|
18
23
|
begin
|
19
24
|
case method
|
20
25
|
when :get
|
21
|
-
@response =
|
26
|
+
@response = http_client.get parameters.url,
|
22
27
|
headers.merge(params: parameters.query)
|
23
28
|
when :post
|
24
|
-
@response =
|
29
|
+
@response = http_client.post parameters.url, parameters.body,
|
25
30
|
headers.merge(content_type: :json)
|
26
31
|
when :put
|
27
|
-
@response =
|
32
|
+
@response = http_client.put parameters.url, parameters.body,
|
28
33
|
headers.merge(content_type: :json)
|
29
34
|
when :delete
|
30
|
-
@response =
|
35
|
+
@response = http_client.delete parameters.url,
|
31
36
|
headers
|
32
37
|
else
|
33
38
|
fail "Unsupported method: #{method}"
|
@@ -36,10 +41,14 @@ module ApiSpec
|
|
36
41
|
if ENV["API_SPEC_DEBUG"]
|
37
42
|
puts "@response = #{@response}"
|
38
43
|
end
|
39
|
-
rescue
|
44
|
+
rescue http_client::Exception => e
|
40
45
|
@response = ErrorResponse.new(e.http_code, e.http_body)
|
41
46
|
puts "Error response body: #{ @response.body }"
|
42
47
|
end
|
43
48
|
end
|
49
|
+
|
50
|
+
def http_client
|
51
|
+
ApiSpec.configuration.http_client
|
52
|
+
end
|
44
53
|
end
|
45
54
|
end
|
data/lib/api_spec/parameters.rb
CHANGED
data/lib/api_spec/state.rb
CHANGED
data/lib/api_spec/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class ApiSpec
|
2
|
+
VERSION = "0.2.0"
|
3
3
|
end
|
data/lib/api_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruz Marzolf
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- api-spec.gemspec
|
82
82
|
- lib/api-spec.rb
|
83
83
|
- lib/api_spec.rb
|
84
|
+
- lib/api_spec/configuration.rb
|
84
85
|
- lib/api_spec/cucumber.rb
|
85
86
|
- lib/api_spec/helpers.rb
|
86
87
|
- lib/api_spec/parameters.rb
|