Class: Mimic::FakeHost
- Inherits:
-
Object
show all
- Defined in:
- lib/mimic/fake_host.rb
Defined Under Namespace
Modules: Helpers
Classes: RequestEcho, StubbedRequest
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ FakeHost
Returns a new instance of FakeHost.
9
10
11
12
13
14
15
16
|
# File 'lib/mimic/fake_host.rb', line 9
def initialize(options = {})
@hostname = options[:hostname]
@remote_configuration_path = options[:remote_configuration_path]
@log = options[:log]
@imports = []
clear
build_url_map!
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
75
76
77
|
# File 'lib/mimic/fake_host.rb', line 75
def method_missing(method, *args, &block)
@app.send(method, *args, &block)
end
|
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
6
7
8
|
# File 'lib/mimic/fake_host.rb', line 6
def hostname
@hostname
end
|
#log ⇒ Object
Returns the value of attribute log.
7
8
9
|
# File 'lib/mimic/fake_host.rb', line 7
def log
@log
end
|
#url_map ⇒ Object
Returns the value of attribute url_map.
6
7
8
|
# File 'lib/mimic/fake_host.rb', line 6
def url_map
@url_map
end
|
Instance Method Details
#call(env) ⇒ Object
51
52
53
54
|
# File 'lib/mimic/fake_host.rb', line 51
def call(env)
@stubs.each(&:build)
@app.call(env)
end
|
#clear ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/mimic/fake_host.rb', line 56
def clear
@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
|
#delete(path, &block) ⇒ Object
34
35
36
|
# File 'lib/mimic/fake_host.rb', line 34
def delete(path, &block)
request("DELETE", path, &block)
end
|
#get(path, &block) ⇒ Object
22
23
24
|
# File 'lib/mimic/fake_host.rb', line 22
def get(path, &block)
request("GET", path, &block)
end
|
#head(path, &block) ⇒ Object
38
39
40
|
# File 'lib/mimic/fake_host.rb', line 38
def head(path, &block)
request("HEAD", path, &block)
end
|
#import(path) ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/mimic/fake_host.rb', line 42
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
69
70
71
|
# File 'lib/mimic/fake_host.rb', line 69
def inspect
@stubs.inspect
end
|
#post(path, &block) ⇒ Object
26
27
28
|
# File 'lib/mimic/fake_host.rb', line 26
def post(path, &block)
request("POST", path, &block)
end
|
#put(path, &block) ⇒ Object
30
31
32
|
# File 'lib/mimic/fake_host.rb', line 30
def put(path, &block)
request("PUT", path, &block)
end
|
#received_requests ⇒ Object
18
19
20
|
# File 'lib/mimic/fake_host.rb', line 18
def received_requests
@stubs.select { |s| s.received }
end
|