Split response_spec.rb into single test files
This commit is contained in:
parent
3a82183563
commit
69aa01cabc
|
@ -0,0 +1,12 @@
|
|||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Zero::Response do
|
||||
subject { Zero::Response.new() }
|
||||
|
||||
describe '#body' do
|
||||
it "must return an empty array, if no body was set" do
|
||||
subject.body.should eq([])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,28 @@
|
|||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Zero::Response do
|
||||
subject { Zero::Response.new() }
|
||||
|
||||
describe '#content_length' do
|
||||
it "sets the Content-Length to '0', if there is no content" do
|
||||
subject.content_length
|
||||
|
||||
subject.header['Content-Length'].should eq('0')
|
||||
end
|
||||
|
||||
it "sets the Content-Length to the size of the message body" do
|
||||
subject.body = ['foo', 'bar']
|
||||
subject.content_length
|
||||
|
||||
subject.header['Content-Length'].should eq('6')
|
||||
end
|
||||
|
||||
it "sets the Content-Length to the bytesize of the message body" do
|
||||
subject.body = ['föö', 'bär']
|
||||
subject.content_length
|
||||
|
||||
subject.header['Content-Length'].should eq('9')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Zero::Response do
|
||||
subject { Zero::Response.new() }
|
||||
|
||||
describe '#content_type' do
|
||||
it "sets the Content-Type to the given value" do
|
||||
subject.content_type = 'application/json'
|
||||
|
||||
subject.header['Content-Type'].should eq('application/json')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Zero::Response do
|
||||
subject { Zero::Response.new() }
|
||||
|
||||
describe '#header' do
|
||||
it "must return an empty hash, if no header was set" do
|
||||
subject.header.should eq({})
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,24 @@
|
|||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Zero::Response do
|
||||
subject { Zero::Response.new() }
|
||||
|
||||
describe '#redirect' do
|
||||
it "sets the status to 302 and the given Location URL in header" do
|
||||
subject.redirect 'http://foo.bar/relocated/thingy'
|
||||
value = subject.to_a
|
||||
|
||||
value[0].should eq(302)
|
||||
value[1]['Location'].should eq('http://foo.bar/relocated/thingy')
|
||||
end
|
||||
|
||||
it "sets the given status code and the given Location" do
|
||||
subject.redirect('http://foo.bar/relocated/other_thingy', 307)
|
||||
value = subject.to_a
|
||||
|
||||
value[0].should eq(307)
|
||||
value[1]['Location'].should eq('http://foo.bar/relocated/other_thingy')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Zero::Response do
|
||||
subject { Zero::Response.new() }
|
||||
|
||||
describe '#status' do
|
||||
it "must return the status always as an integer" do
|
||||
subject.status = "foobar"
|
||||
subject.status.should eq(0)
|
||||
|
||||
subject.status = 240.5
|
||||
subject.status.should eq(240)
|
||||
end
|
||||
|
||||
it "must return 200, if no status code was set" do
|
||||
subject.status.should eq(200)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -70,79 +70,4 @@ describe Zero::Response do
|
|||
value[2].should eq([]) # Body
|
||||
end
|
||||
end
|
||||
|
||||
describe '#status' do
|
||||
it "must return the status always as an integer" do
|
||||
subject.status = "foobar"
|
||||
subject.status.should eq(0)
|
||||
|
||||
subject.status = 240.5
|
||||
subject.status.should eq(240)
|
||||
end
|
||||
|
||||
it "must return 200, if no status code was set" do
|
||||
subject.status.should eq(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#header' do
|
||||
it "must return an empty hash, if no header was set" do
|
||||
subject.header.should eq({})
|
||||
end
|
||||
end
|
||||
|
||||
describe '#body' do
|
||||
it "must return an empty array, if no body was set" do
|
||||
subject.body.should eq([])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#content_length' do
|
||||
it "sets the Content-Length to '0', if there is no content" do
|
||||
subject.content_length
|
||||
|
||||
subject.header['Content-Length'].should eq('0')
|
||||
end
|
||||
|
||||
it "sets the Content-Length to the size of the message body" do
|
||||
subject.body = ['foo', 'bar']
|
||||
subject.content_length
|
||||
|
||||
subject.header['Content-Length'].should eq('6')
|
||||
end
|
||||
|
||||
it "sets the Content-Length to the bytesize of the message body" do
|
||||
subject.body = ['föö', 'bär']
|
||||
subject.content_length
|
||||
|
||||
subject.header['Content-Length'].should eq('9')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#content_type' do
|
||||
it "sets the Content-Type to the given value" do
|
||||
subject.content_type = 'application/json'
|
||||
|
||||
subject.header['Content-Type'].should eq('application/json')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#redirect' do
|
||||
it "sets the status to 302 and the given Location URL in header" do
|
||||
subject.redirect 'http://foo.bar/relocated/thingy'
|
||||
value = subject.to_a
|
||||
|
||||
value[0].should eq(302)
|
||||
value[1]['Location'].should eq('http://foo.bar/relocated/thingy')
|
||||
end
|
||||
|
||||
it "sets the given status code and the given Location" do
|
||||
subject.redirect('http://foo.bar/relocated/other_thingy', 307)
|
||||
value = subject.to_a
|
||||
|
||||
value[0].should eq(307)
|
||||
value[1]['Location'].should eq('http://foo.bar/relocated/other_thingy')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue