http_spec 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -4,8 +4,9 @@ require "rack/mock"
|
|
4
4
|
module HTTPSpec
|
5
5
|
module Clients
|
6
6
|
class Rack
|
7
|
-
def initialize(app)
|
7
|
+
def initialize(app, env = {})
|
8
8
|
@session = ::Rack::MockRequest.new(app)
|
9
|
+
@env = env
|
9
10
|
end
|
10
11
|
|
11
12
|
def dispatch(request)
|
@@ -21,7 +22,7 @@ module HTTPSpec
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def headers_to_env(headers)
|
24
|
-
headers.inject(
|
25
|
+
headers.inject(@env) do |env, (k, v)|
|
25
26
|
k = k.tr("-", "_").upcase
|
26
27
|
k = "HTTP_#{k}" unless %w{CONTENT_TYPE CONTENT_LENGTH}.include?(k)
|
27
28
|
env.merge(k => v)
|
@@ -8,12 +8,16 @@ module HTTPSpec
|
|
8
8
|
methods.each do |method|
|
9
9
|
define_method(method) do |path, body="", headers={}|
|
10
10
|
request = Request.new(method, path, body, headers)
|
11
|
-
HTTPSpec.dispatch(request)
|
11
|
+
@last_response = HTTPSpec.dispatch(request)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
define_actions :get, :post, :put, :patch, :delete, :options, :head
|
17
|
+
|
18
|
+
def last_response
|
19
|
+
@last_response or raise "No request yet."
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -56,11 +56,12 @@ module HTTPSpec
|
|
56
56
|
|
57
57
|
def build_request(options)
|
58
58
|
request = example.metadata[:request]
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
Request.new(
|
60
|
+
request.method,
|
61
|
+
build_path(request, options),
|
62
|
+
options.fetch(:body, ""),
|
63
|
+
example.metadata[:default_headers].merge(options.fetch(:headers, {}))
|
64
|
+
)
|
64
65
|
end
|
65
66
|
|
66
67
|
def build_path(request, options)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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: 2012-
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-core
|