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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5d30a283161211c873590342a3e4606bca8ca0a
4
- data.tar.gz: 5c9d75f8e4294d1150c8333fe16e1a75497971d6
3
+ metadata.gz: 8ee6a0304cf9ce5c134154b06cb0dc9ee4c22d94
4
+ data.tar.gz: 1c9101fd8201f89accffea9c5a1c5bef4e11dca1
5
5
  SHA512:
6
- metadata.gz: d9edbdcd668d9753f6d4d635ed313fe6c47b20a76011a681709bdefc9f654f66ef8dfe8f099339541bbc963d90b5c35e0c24b2c010be9db8580830416f7fb395
7
- data.tar.gz: 42331a05df1bdeaf9a8fe057417780a335daf83171f55d742f02af1243f8bfc94d0227fe8b194186444cfe259f3852f7ac3b64916621c667bba2c1ae691ede90
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
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  When(/^I GET "(.*?)"$/) do |path|
18
18
  parameters = ApiSpec::Parameters.new(:get, path)
19
- @response = RestClient.get parameters.url, test_headers
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.code.to_s.should == code
32
+ @response.status.to_s.should == code
33
33
  end
34
34
 
35
35
  Then(/^the Content\-Type is (.*)$/) do |content_type|
@@ -1,7 +1,12 @@
1
1
  require "rest-client"
2
2
 
3
- module ApiSpec
4
- class ErrorResponse < Struct.new(:code, :body)
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 = RestClient.get parameters.url,
26
+ @response = http_client.get parameters.url,
22
27
  headers.merge(params: parameters.query)
23
28
  when :post
24
- @response = RestClient.post parameters.url, parameters.body,
29
+ @response = http_client.post parameters.url, parameters.body,
25
30
  headers.merge(content_type: :json)
26
31
  when :put
27
- @response = RestClient.put parameters.url, parameters.body,
32
+ @response = http_client.put parameters.url, parameters.body,
28
33
  headers.merge(content_type: :json)
29
34
  when :delete
30
- @response = RestClient.delete parameters.url,
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 RestClient::Exception => e
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
@@ -1,4 +1,4 @@
1
- module ApiSpec
1
+ class ApiSpec
2
2
  class Parameters
3
3
  attr_reader :query
4
4
 
@@ -1,4 +1,4 @@
1
- module ApiSpec
1
+ class ApiSpec
2
2
  class State
3
3
  class << self
4
4
  def set(key, value)
@@ -1,3 +1,3 @@
1
- module ApiSpec
2
- VERSION = "0.1.1"
1
+ class ApiSpec
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/api_spec.rb CHANGED
@@ -1,6 +1,7 @@
1
- module ApiSpec
1
+ class ApiSpec
2
2
  end
3
3
 
4
+ require_relative "api_spec/configuration"
4
5
  require_relative "api_spec/helpers"
5
6
  require_relative "api_spec/parameters"
6
7
  require_relative "api_spec/state"
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.1.1
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