Class: Mimic::Stub
- Inherits:
-
Object
- Object
- Mimic::Stub
- Defined in:
- lib/mimic/stub.rb
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object
- #echo_format ⇒ Object
- #get_stub(host) ⇒ Object
- #headers ⇒ Object
-
#initialize(data, method = nil) ⇒ Stub
constructor
A new instance of Stub.
- #on(host) ⇒ Object
- #params ⇒ Object
- #path ⇒ Object
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
#body ⇒ Object
28 29 30 |
# File 'lib/mimic/stub.rb', line 28 def body @data['body'] || '' end |
#code ⇒ Object
32 33 34 |
# File 'lib/mimic/stub.rb', line 32 def code @data['code'] || 200 end |
#echo_format ⇒ Object
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 |
#headers ⇒ Object
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 |
#params ⇒ Object
40 41 42 |
# File 'lib/mimic/stub.rb', line 40 def params @data['params'] || {} end |
#path ⇒ Object
24 25 26 |
# File 'lib/mimic/stub.rb', line 24 def path @data['path'] || '/' end |