Class: EventMachine::MockHttpRequest
Defined Under Namespace
Classes: FakeHttpClient, RegisteredRequest
Constant Summary
collapse
- @@registry =
Hash.new
- @@registry_count =
Hash.new{|h,k| h[k] = 0}
- @@pass_through_requests =
true
HttpEncoding::FIELD_ENCODING, HttpEncoding::HTTP_REQUEST_HEADER
Instance Attribute Summary
Attributes inherited from HttpRequest
#method, #options
Class Method Summary
collapse
-
.activate! ⇒ Object
-
.count(url, method, headers = {}) ⇒ Object
-
.deactivate! ⇒ Object
-
.increment_access(url, method, headers = {}) ⇒ Object
-
.parse_register_args(args, &proc) ⇒ Object
-
.pass_through_requests ⇒ Object
-
.pass_through_requests=(pass_through_requests) ⇒ Object
-
.register(*args, &proc) ⇒ Object
-
.register_file(*args) ⇒ Object
-
.registered?(url, method, headers = {}) ⇒ Boolean
-
.registered_content(url, method, headers = {}) ⇒ Object
-
.reset_counts! ⇒ Object
-
.reset_registry! ⇒ Object
-
.use ⇒ Object
Instance Method Summary
collapse
#bytesize, #encode_auth, #encode_cookie, #encode_field, #encode_headers, #encode_host, #encode_param, #encode_query, #encode_request, #escape, #munge_header_keys, #unescape
Methods inherited from HttpRequest
#delete, #get, #head, #initialize, #post, #put
Class Method Details
.count(url, method, headers = {}) ⇒ Object
102
103
104
|
# File 'lib/em-http/mock.rb', line 102
def self.count(url, method, = {})
@@registry_count[RegisteredRequest.build(url, method, )]
end
|
.increment_access(url, method, headers = {}) ⇒ Object
114
115
116
|
# File 'lib/em-http/mock.rb', line 114
def self.increment_access(url, method, = {})
@@registry_count[RegisteredRequest.build(url, method, )] += 1
end
|
.parse_register_args(args, &proc) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/em-http/mock.rb', line 74
def self.parse_register_args(args, &proc)
args << proc{|client| proc.call(client); ''} if proc
, data = case args.size
when 3
args[2].is_a?(Hash) ?
[args[2][:headers], args[2][:data]] :
[{}, args[2]]
when 4
[args[2], args[3]]
else
raise
end
url = args[0]
method = args[1]
[, url, method, data]
end
|
.pass_through_requests ⇒ Object
70
71
72
|
# File 'lib/em-http/mock.rb', line 70
def self.pass_through_requests
@@pass_through_requests
end
|
.pass_through_requests=(pass_through_requests) ⇒ Object
66
67
68
|
# File 'lib/em-http/mock.rb', line 66
def self.pass_through_requests=(pass_through_requests)
@@pass_through_requests = pass_through_requests
end
|
.register(*args, &proc) ⇒ Object
92
93
94
95
|
# File 'lib/em-http/mock.rb', line 92
def self.register(*args, &proc)
, url, method, data = parse_register_args(args, &proc)
@@registry[RegisteredRequest.build(url, method, )] = data
end
|
.register_file(*args) ⇒ Object
97
98
99
100
|
# File 'lib/em-http/mock.rb', line 97
def self.register_file(*args)
, url, method, data = parse_register_args(args)
@@registry[RegisteredRequest.build(url, method, )] = File.read(data)
end
|
.registered?(url, method, headers = {}) ⇒ Boolean
106
107
108
|
# File 'lib/em-http/mock.rb', line 106
def self.registered?(url, method, = {})
@@registry.key?(RegisteredRequest.build(url, method, ))
end
|
.registered_content(url, method, headers = {}) ⇒ Object
110
111
112
|
# File 'lib/em-http/mock.rb', line 110
def self.registered_content(url, method, = {})
@@registry[RegisteredRequest.build(url, method, )]
end
|
.reset_counts! ⇒ Object
56
57
58
|
# File 'lib/em-http/mock.rb', line 56
def self.reset_counts!
@@registry_count.clear
end
|
.reset_registry! ⇒ Object
60
61
62
|
# File 'lib/em-http/mock.rb', line 60
def self.reset_registry!
@@registry.clear
end
|
.use ⇒ Object
39
40
41
42
43
44
|
# File 'lib/em-http/mock.rb', line 39
def self.use
activate!
yield
ensure
deactivate!
end
|
Instance Method Details
#real_send_request ⇒ Object
118
|
# File 'lib/em-http/mock.rb', line 118
alias_method :real_send_request, :send_request
|