Class: Mimic::FakeHost

Inherits:
Object
  • Object
show all
Defined in:
lib/mimic/fake_host.rb

Defined Under Namespace

Classes: StubbedRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname, remote_configuration_path = nil) ⇒ FakeHost

Returns a new instance of FakeHost.



8
9
10
11
12
13
# File 'lib/mimic/fake_host.rb', line 8

def initialize(hostname, remote_configuration_path = nil)
  @hostname = hostname
  @remote_configuration_path = remote_configuration_path
  clear      
  build_url_map!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



60
61
62
# File 'lib/mimic/fake_host.rb', line 60

def method_missing(method, *args, &block)
  @app.send(method, *args, &block)
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



6
7
8
# File 'lib/mimic/fake_host.rb', line 6

def hostname
  @hostname
end

#url_mapObject (readonly)

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



41
42
43
44
# File 'lib/mimic/fake_host.rb', line 41

def call(env)
  @stubs.each(&:build)
  @app.call(env)
end

#clearObject



46
47
48
49
50
51
52
# File 'lib/mimic/fake_host.rb', line 46

def clear
  @stubs = []
  @app = Class.new(Sinatra::Base)
  @app.not_found do
    [404, {}, ""]
  end
end

#delete(path, &block) ⇒ Object



27
28
29
# File 'lib/mimic/fake_host.rb', line 27

def delete(path, &block)
  request("DELETE", path, &block)
end

#get(path, &block) ⇒ Object



15
16
17
# File 'lib/mimic/fake_host.rb', line 15

def get(path, &block)
  request("GET", path, &block)
end

#head(path, &block) ⇒ Object



31
32
33
# File 'lib/mimic/fake_host.rb', line 31

def head(path, &block)
  request("HEAD", path, &block)
end

#import(path) ⇒ Object



35
36
37
38
39
# File 'lib/mimic/fake_host.rb', line 35

def import(path)
  if File.exists?(path)
    instance_eval(File.read(path))
  end
end

#inspectObject



54
55
56
# File 'lib/mimic/fake_host.rb', line 54

def inspect
  @stubs.inspect
end

#post(path, &block) ⇒ Object



19
20
21
# File 'lib/mimic/fake_host.rb', line 19

def post(path, &block)
  request("POST", path, &block)
end

#put(path, &block) ⇒ Object



23
24
25
# File 'lib/mimic/fake_host.rb', line 23

def put(path, &block)
  request("PUT", path, &block)
end