http_vanilli 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/http_vanilli/basic_mapper.rb +2 -2
- data/lib/http_vanilli/net_http/override.rb +11 -1
- data/lib/http_vanilli/net_http/request.rb +3 -2
- data/lib/http_vanilli/responders/rack.rb +10 -2
- data/lib/http_vanilli/version.rb +1 -1
- metadata +14 -8
- data/lib/http_vanilli/basic_mapping.rb +0 -22
- data/lib/http_vanilli/other_mapper.rb +0 -54
- data/lib/http_vanilli/test_adapters/rspec.rb +0 -9
@@ -32,8 +32,8 @@ module HttpVanilli
|
|
32
32
|
## Mapping API
|
33
33
|
|
34
34
|
# Take the info from the innards of Net::HTTP and build a request.
|
35
|
-
def build_request(kind,http,request
|
36
|
-
HttpVanilli::Request.build(kind,http,request
|
35
|
+
def build_request(kind, http, request, index, &block)
|
36
|
+
HttpVanilli::Request.build(kind, http, request, index, &block)
|
37
37
|
end
|
38
38
|
|
39
39
|
# Should we map the request?
|
@@ -39,12 +39,22 @@ module Net #:nodoc: all
|
|
39
39
|
end
|
40
40
|
|
41
41
|
class HTTP
|
42
|
+
# add some class methods
|
42
43
|
class << self
|
43
44
|
def socket_type_with_http_vanilli
|
44
45
|
HttpVanilli::NetHttp::StubSocket
|
45
46
|
end
|
46
47
|
alias_method :socket_type_without_http_vanilli, :socket_type
|
47
48
|
alias_method :socket_type, :socket_type_with_http_vanilli
|
49
|
+
|
50
|
+
def last_request_index
|
51
|
+
@last_request_index ||= -1
|
52
|
+
end
|
53
|
+
|
54
|
+
def next_request_index
|
55
|
+
@last_request_index ||= -1
|
56
|
+
@last_request_index += 1
|
57
|
+
end
|
48
58
|
end
|
49
59
|
|
50
60
|
def request_with_http_vanilli(request, body = nil, &block)
|
@@ -53,7 +63,7 @@ module Net #:nodoc: all
|
|
53
63
|
request.set_body_internal body
|
54
64
|
|
55
65
|
# Wrap Net::HTTPRequest & associated info in a HttpVanilli::Request
|
56
|
-
vanilli_request = mapper.build_request(:net_http, self, request, &block)
|
66
|
+
vanilli_request = mapper.build_request(:net_http, self, request, self.class.next_request_index, &block)
|
57
67
|
|
58
68
|
# The mapper can map the request. Do it.
|
59
69
|
if mapper.map_request?(vanilli_request)
|
@@ -3,11 +3,12 @@ require 'http_vanilli/request'
|
|
3
3
|
module HttpVanilli
|
4
4
|
module NetHttp
|
5
5
|
class Request < HttpVanilli::Request
|
6
|
-
attr_reader :block, :uri, :method, :original_request
|
6
|
+
attr_reader :block, :uri, :method, :original_request, :index
|
7
7
|
|
8
|
-
def initialize(http,request,&block)
|
8
|
+
def initialize(http,request,index,&block)
|
9
9
|
@http = http
|
10
10
|
@original_request = request
|
11
|
+
@index = index
|
11
12
|
@block = block
|
12
13
|
|
13
14
|
protocol = http.use_ssl? ? "https" : "http"
|
@@ -45,7 +45,8 @@ module HttpVanilli
|
|
45
45
|
"rack.multiprocess" => false,
|
46
46
|
"rack.run_once" => false,
|
47
47
|
|
48
|
-
"rack.url_scheme" => request.uri.scheme
|
48
|
+
"rack.url_scheme" => request.uri.scheme,
|
49
|
+
"http_vanilli.request_index" => request.index
|
49
50
|
})
|
50
51
|
|
51
52
|
app.call(env)
|
@@ -53,7 +54,14 @@ module HttpVanilli
|
|
53
54
|
|
54
55
|
def app
|
55
56
|
inner_app = lambda {|l| [BadStatus,{'Content-Type' => 'text/plain'},['']]}
|
56
|
-
|
57
|
+
|
58
|
+
if Proc === @app_class
|
59
|
+
lambda {|env|
|
60
|
+
@app_class.call(env) || inner_app.call(env)
|
61
|
+
}
|
62
|
+
else
|
63
|
+
@app_class.new(inner_app,*@args,&@block)
|
64
|
+
end
|
57
65
|
end
|
58
66
|
end
|
59
67
|
end
|
data/lib/http_vanilli/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_vanilli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Lachie Cox
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-04-19 00:00:00 +10:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: exemplor
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
version: "0"
|
@@ -33,9 +36,11 @@ dependencies:
|
|
33
36
|
name: addressable
|
34
37
|
prerelease: false
|
35
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
36
40
|
requirements:
|
37
41
|
- - ">="
|
38
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 7
|
39
44
|
segments:
|
40
45
|
- 2
|
41
46
|
- 2
|
@@ -56,19 +61,16 @@ files:
|
|
56
61
|
- lib/angry_web/matcher.rb
|
57
62
|
- lib/http_vanilli/abstract_responder.rb
|
58
63
|
- lib/http_vanilli/basic_mapper.rb
|
59
|
-
- lib/http_vanilli/basic_mapping.rb
|
60
64
|
- lib/http_vanilli/net_http/override.rb
|
61
65
|
- lib/http_vanilli/net_http/request.rb
|
62
66
|
- lib/http_vanilli/net_http/response.rb
|
63
67
|
- lib/http_vanilli/net_http/stubs.rb
|
64
68
|
- lib/http_vanilli/net_http/util.rb
|
65
|
-
- lib/http_vanilli/other_mapper.rb
|
66
69
|
- lib/http_vanilli/request.rb
|
67
70
|
- lib/http_vanilli/responders/block.rb
|
68
71
|
- lib/http_vanilli/responders/rack.rb
|
69
72
|
- lib/http_vanilli/responders.rb
|
70
73
|
- lib/http_vanilli/response.rb
|
71
|
-
- lib/http_vanilli/test_adapters/rspec.rb
|
72
74
|
- lib/http_vanilli/util.rb
|
73
75
|
- lib/http_vanilli/version.rb
|
74
76
|
- lib/http_vanilli.rb
|
@@ -82,16 +84,20 @@ rdoc_options: []
|
|
82
84
|
require_paths:
|
83
85
|
- lib
|
84
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
85
88
|
requirements:
|
86
89
|
- - ">="
|
87
90
|
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
88
92
|
segments:
|
89
93
|
- 0
|
90
94
|
version: "0"
|
91
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
92
97
|
requirements:
|
93
98
|
- - ">="
|
94
99
|
- !ruby/object:Gem::Version
|
100
|
+
hash: 23
|
95
101
|
segments:
|
96
102
|
- 1
|
97
103
|
- 3
|
@@ -100,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
106
|
requirements: []
|
101
107
|
|
102
108
|
rubyforge_project: http_vanilli
|
103
|
-
rubygems_version: 1.
|
109
|
+
rubygems_version: 1.6.2
|
104
110
|
signing_key:
|
105
111
|
specification_version: 3
|
106
112
|
summary: Flexible web connection mocking lib.
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'addressable/uri'
|
2
|
-
|
3
|
-
module Unused
|
4
|
-
class BasicMapping
|
5
|
-
include HttpVanilli::NetHttp::YieldResponse
|
6
|
-
|
7
|
-
def initialize(method,url,&block)
|
8
|
-
@method = method
|
9
|
-
@url = Addressable::URI.heuristic_parse(url)
|
10
|
-
@block = block
|
11
|
-
end
|
12
|
-
|
13
|
-
def match?(request)
|
14
|
-
(request.host == @url.host)
|
15
|
-
end
|
16
|
-
|
17
|
-
def rack_response
|
18
|
-
@block[request]
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
require 'pp'
|
3
|
-
|
4
|
-
module HttpVanilli
|
5
|
-
class OtherMapper
|
6
|
-
def customise_request(&block)
|
7
|
-
@customise_request = block
|
8
|
-
end
|
9
|
-
|
10
|
-
# Take the info from the innards of Net::HTTP and build a request.
|
11
|
-
def build_request(kind,http,request,body,&block)
|
12
|
-
req = OpenStruct.new
|
13
|
-
req.block = block
|
14
|
-
|
15
|
-
pp http
|
16
|
-
pp request.to_hash
|
17
|
-
|
18
|
-
protocol = http.use_ssl? ? "https" : "http"
|
19
|
-
|
20
|
-
path = request.path
|
21
|
-
path = Addressable::URI.parse(request.path).request_uri if request.path =~ /^http/
|
22
|
-
|
23
|
-
req.uri = Addressable::URI.parse( "#{protocol}://#{http.address}:#{http.port}#{path}" )
|
24
|
-
req.method = request.method.downcase.to_sym
|
25
|
-
|
26
|
-
if @customise_request
|
27
|
-
@customise_request[req]
|
28
|
-
end
|
29
|
-
|
30
|
-
req
|
31
|
-
end
|
32
|
-
|
33
|
-
# Should we map the request?
|
34
|
-
def map_request?(request)
|
35
|
-
true
|
36
|
-
end
|
37
|
-
|
38
|
-
# Map the request
|
39
|
-
def map_request(request)
|
40
|
-
response = HttpVanilli::NetHttp::Response.new(200,'cool')
|
41
|
-
response.body = "boddy"
|
42
|
-
|
43
|
-
nhrsp = response.to_net_http
|
44
|
-
request.block[nhrsp] if request.block
|
45
|
-
|
46
|
-
nhrsp
|
47
|
-
end
|
48
|
-
|
49
|
-
# The request wasn't matched and normal net connection was disallowed.
|
50
|
-
def unmapped_request(request)
|
51
|
-
raise "unmatched_request :("
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|