Class: Net::HTTP
- Inherits:
-
Object
- Object
- Net::HTTP
- Defined in:
- lib/net/httpstub.rb
Constant Summary collapse
- @@responses =
[]
Class Method Summary collapse
-
.push(res) ⇒ Object
push the res to the response list, and set stub mode on.
-
.push_file(filename, base_path = ".") ⇒ Object
push the content of filename to the response list, and set stub mode on.
-
.stub ⇒ Object
(also: stub?)
return stub mode.
-
.stub=(value) ⇒ Object
set stub mode.
Class Method Details
.push(res) ⇒ Object
push the res to the response list, and set stub mode on.
11 12 13 14 |
# File 'lib/net/httpstub.rb', line 11 def push(res) @@responses.push add_header(res) self.stub = true end |
.push_file(filename, base_path = ".") ⇒ Object
push the content of filename to the response list, and set stub mode on.
18 19 20 21 22 23 24 25 26 |
# File 'lib/net/httpstub.rb', line 18 def push_file(filename, base_path = ".") unless filename == File.(filename) base_path = File.(base_path) base_path = File.dirname(base_path) unless File.directory?(base_path) filename = File.join(base_path, filename) end res = open(filename){|f| f.read} push(res) end |
.stub ⇒ Object Also known as: stub?
return stub mode.
29 30 31 |
# File 'lib/net/httpstub.rb', line 29 def stub @stub || false end |
.stub=(value) ⇒ Object
set stub mode.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/net/httpstub.rb', line 36 def stub=(value) @stub = value if @stub module_eval do alias :request :request_stub alias :connect :connect_stub public :request end else module_eval do alias :request :request_orig alias :connect :connect_orig public :request end end end |