Add simple response object
This commit is contained in:
parent
f37cc87fe5
commit
0986ca27f5
|
@ -2,3 +2,4 @@ require_relative 'controller'
|
|||
require_relative 'router'
|
||||
require_relative 'renderer'
|
||||
require_relative 'request'
|
||||
require_relative 'response'
|
|
@ -0,0 +1,19 @@
|
|||
module Zero
|
||||
|
||||
# This is the representation of a response
|
||||
#
|
||||
class Response
|
||||
attr_accessor :status, :header, :body
|
||||
|
||||
# Returns the data of the response as an array:
|
||||
# [status, header, body]
|
||||
# to be usable by any webserver
|
||||
#
|
||||
# @return Array
|
||||
#
|
||||
def to_a()
|
||||
[@status, @header, @body]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Zero::Response, '#finish' do
|
||||
subject { Zero::Response.new() }
|
||||
|
||||
it "returns an array within status header and body" do
|
||||
subject.status = 200
|
||||
subject.header = {}
|
||||
subject.body = []
|
||||
|
||||
value = subject.to_a
|
||||
|
||||
value.should be_an_instance_of(Array)
|
||||
value[0].should eq(200) # Status code
|
||||
value[1].should eq({}) # Headers
|
||||
value[2].should eq([]) # Body
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue