Class: Mimic::Stub

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

Instance Method Summary collapse

Constructor Details

#initialize(data, method = nil) ⇒ Stub

Returns a new instance of Stub.



3
4
5
6
# File 'lib/mimic/stub.rb', line 3

def initialize(data, method = nil)
  @data = data
  @method = method
end

Instance Method Details

#bodyObject



28
29
30
# File 'lib/mimic/stub.rb', line 28

def body
  @data['body'] || ''
end

#codeObject



32
33
34
# File 'lib/mimic/stub.rb', line 32

def code
  @data['code'] || 200
end

#echo_formatObject



20
21
22
# File 'lib/mimic/stub.rb', line 20

def echo_format
  @data['echo'].to_sym rescue nil
end

#get_stub(host) ⇒ Object



16
17
18
# File 'lib/mimic/stub.rb', line 16

def get_stub(host)
  host.send(@method.downcase.to_sym, path)
end

#headersObject



36
37
38
# File 'lib/mimic/stub.rb', line 36

def headers
  @data['headers'] || {}
end

#on(host) ⇒ Object



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

def on(host)
  get_stub(host).tap do |stub|
    stub.returning(body, code, headers)
    stub.with_query_parameters(params)
    stub.echo_request!(echo_format)
  end
end

#paramsObject



40
41
42
# File 'lib/mimic/stub.rb', line 40

def params
  @data['params'] || {}
end

#pathObject



24
25
26
# File 'lib/mimic/stub.rb', line 24

def path
  @data['path'] || '/'
end