Class: Fake::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/fake/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, status, headers, &block) ⇒ Response

Returns a new instance of Response.



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

def initialize(body, status, headers, &block)
  raise "Response created with body and block. Only other can be given" if body && block
  @body = body
  @status = status
  @block = block
  @headers = headers
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/fake/response.rb', line 4

def body
  @body
end

#headersObject

Returns the value of attribute headers.



6
7
8
# File 'lib/fake/response.rb', line 6

def headers
  @headers
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/fake/response.rb', line 5

def status
  @status
end

Instance Method Details

#evaluateObject



16
17
18
19
20
21
# File 'lib/fake/response.rb', line 16

def evaluate
  if !@body && @block
    @body = @block.call(self)
  end
  @body
end