Class: Mimic::FakeHost
- Inherits:
-
Object
show all
- Defined in:
- lib/mimic/fake_host.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ FakeHost
Returns a new instance of FakeHost.
12
13
14
15
16
17
18
19
|
# File 'lib/mimic/fake_host.rb', line 12
def initialize(options = {})
@hostname = options[:hostname]
@remote_configuration_path = options[:remote_configuration_path]
@log = options[:log]
@imports = []
setup_sinatra
build_url_map!
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
81
82
83
|
# File 'lib/mimic/fake_host.rb', line 81
def method_missing(method, *args, &block)
@app.send(method, *args, &block)
end
|
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
9
10
11
|
# File 'lib/mimic/fake_host.rb', line 9
def hostname
@hostname
end
|
#log ⇒ Object
Returns the value of attribute log.
10
11
12
|
# File 'lib/mimic/fake_host.rb', line 10
def log
@log
end
|
#url_map ⇒ Object
Returns the value of attribute url_map.
9
10
11
|
# File 'lib/mimic/fake_host.rb', line 9
def url_map
@url_map
end
|
Instance Method Details
#call(env) ⇒ Object
54
55
56
57
|
# File 'lib/mimic/fake_host.rb', line 54
def call(env)
@stubs.each(&:build)
@app.call(env) end
|
#clear ⇒ Object
72
73
74
|
# File 'lib/mimic/fake_host.rb', line 72
def clear
setup_sinatra
end
|
#delete(path, &block) ⇒ Object
37
38
39
|
# File 'lib/mimic/fake_host.rb', line 37
def delete(path, &block)
setup_request_stub("DELETE", path, &block)
end
|
#get(path, &block) ⇒ Object
25
26
27
|
# File 'lib/mimic/fake_host.rb', line 25
def get(path, &block)
setup_request_stub("GET", path, &block)
end
|
#head(path, &block) ⇒ Object
41
42
43
|
# File 'lib/mimic/fake_host.rb', line 41
def head(path, &block)
setup_request_stub("HEAD", path, &block)
end
|
#import(path) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/mimic/fake_host.rb', line 45
def import(path)
if File.exists?(path)
@imports << path unless @imports.include?(path)
instance_eval(File.read(path))
else
raise "Could not locate file for stub import: #{path}"
end
end
|
#inspect ⇒ Object
76
77
78
|
# File 'lib/mimic/fake_host.rb', line 76
def inspect
@stubs.inspect
end
|
#post(path, &block) ⇒ Object
29
30
31
|
# File 'lib/mimic/fake_host.rb', line 29
def post(path, &block)
setup_request_stub("POST", path, &block)
end
|
#put(path, &block) ⇒ Object
33
34
35
|
# File 'lib/mimic/fake_host.rb', line 33
def put(path, &block)
setup_request_stub("PUT", path, &block)
end
|
#received_requests ⇒ Object
21
22
23
|
# File 'lib/mimic/fake_host.rb', line 21
def received_requests
@stubs.select { |s| s.received }
end
|
#setup_sinatra ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/mimic/fake_host.rb', line 59
def setup_sinatra
@stubs = []
@app = Sinatra.new
@app.use Rack::CommonLogger, self.log if self.log
@app.not_found do
[404, {}, ""]
end
@app.helpers do
include Helpers
end
@imports.each { |file| import(file) }
end
|