From 69aa01cabcea9924cf5d381afebcb0b467383f9e Mon Sep 17 00:00:00 2001 From: Stormwind Date: Sun, 6 Jan 2013 20:46:29 +0100 Subject: Split response_spec.rb into single test files --- spec/unit/zero/response/body_spec.rb | 12 ++ spec/unit/zero/response/content_length_spec.rb | 28 +++++ spec/unit/zero/response/content_type_spec.rb | 14 +++ spec/unit/zero/response/header_spec.rb | 12 ++ spec/unit/zero/response/redirect_spec.rb | 24 ++++ spec/unit/zero/response/response_spec.rb | 148 ------------------------- spec/unit/zero/response/status_spec.rb | 20 ++++ spec/unit/zero/response/to_a_spec.rb | 73 ++++++++++++ 8 files changed, 183 insertions(+), 148 deletions(-) create mode 100644 spec/unit/zero/response/body_spec.rb create mode 100644 spec/unit/zero/response/content_length_spec.rb create mode 100644 spec/unit/zero/response/content_type_spec.rb create mode 100644 spec/unit/zero/response/header_spec.rb create mode 100644 spec/unit/zero/response/redirect_spec.rb delete mode 100644 spec/unit/zero/response/response_spec.rb create mode 100644 spec/unit/zero/response/status_spec.rb create mode 100644 spec/unit/zero/response/to_a_spec.rb (limited to 'spec') diff --git a/spec/unit/zero/response/body_spec.rb b/spec/unit/zero/response/body_spec.rb new file mode 100644 index 0000000..b70af04 --- /dev/null +++ b/spec/unit/zero/response/body_spec.rb @@ -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 diff --git a/spec/unit/zero/response/content_length_spec.rb b/spec/unit/zero/response/content_length_spec.rb new file mode 100644 index 0000000..e4fbe48 --- /dev/null +++ b/spec/unit/zero/response/content_length_spec.rb @@ -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 diff --git a/spec/unit/zero/response/content_type_spec.rb b/spec/unit/zero/response/content_type_spec.rb new file mode 100644 index 0000000..0f89a39 --- /dev/null +++ b/spec/unit/zero/response/content_type_spec.rb @@ -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 diff --git a/spec/unit/zero/response/header_spec.rb b/spec/unit/zero/response/header_spec.rb new file mode 100644 index 0000000..e5d013b --- /dev/null +++ b/spec/unit/zero/response/header_spec.rb @@ -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 diff --git a/spec/unit/zero/response/redirect_spec.rb b/spec/unit/zero/response/redirect_spec.rb new file mode 100644 index 0000000..41ec369 --- /dev/null +++ b/spec/unit/zero/response/redirect_spec.rb @@ -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 diff --git a/spec/unit/zero/response/response_spec.rb b/spec/unit/zero/response/response_spec.rb deleted file mode 100644 index 0cdd099..0000000 --- a/spec/unit/zero/response/response_spec.rb +++ /dev/null @@ -1,148 +0,0 @@ -# encoding: UTF-8 -require 'spec_helper' - -describe Zero::Response do - subject { Zero::Response.new() } - - describe '#to_a' do - 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 be_an_instance_of(Hash) # Headers - value[2].should eq([]) # Body - end - - it "returns the content length in the header" do - subject.body = ['foobar'] - value = subject.to_a - - value[1]['Content-Length'].should eq('6') # Headers - end - - it "does not fix the Content-Length, if it's already set" do - subject.body = ['foobar'] - subject.header = {'Content-Length' => '3'} - value = subject.to_a - - value[1]['Content-Length'].should eq('3') # Headers - end - - it "returns the Content-Type in the header" do - subject.header = {'Content-Type' => 'application/json'} - value = subject.to_a - - value[1]['Content-Type'].should eq('application/json') # Headers - end - - it "returns as default 'text/html' as Content-Type" do - value = subject.to_a - - value[1]['Content-Type'].should eq('text/html') # Headers - end - - it "removes Content-Type, Content-Length and body on status code 204" do - subject.body.push '"foobar"' - subject.content_type = 'application/json' - subject.header['Content-Length'] = 8 - - subject.status = 204 - value = subject.to_a - - value[1].should eq({}) # Headers - value[2].should eq([]) # Body - end - - it "removes Content-Type, Content-Length and body on status code 304" do - subject.body.push '"foobar"' - subject.content_type = 'application/json' - subject.header['Content-Length'] = 8 - - subject.status = 304 - value = subject.to_a - - value[1].should eq({}) # Headers - 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 \ No newline at end of file diff --git a/spec/unit/zero/response/status_spec.rb b/spec/unit/zero/response/status_spec.rb new file mode 100644 index 0000000..dcb15a5 --- /dev/null +++ b/spec/unit/zero/response/status_spec.rb @@ -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 diff --git a/spec/unit/zero/response/to_a_spec.rb b/spec/unit/zero/response/to_a_spec.rb new file mode 100644 index 0000000..b016eb9 --- /dev/null +++ b/spec/unit/zero/response/to_a_spec.rb @@ -0,0 +1,73 @@ +# encoding: UTF-8 +require 'spec_helper' + +describe Zero::Response do + subject { Zero::Response.new() } + + describe '#to_a' do + 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 be_an_instance_of(Hash) # Headers + value[2].should eq([]) # Body + end + + it "returns the content length in the header" do + subject.body = ['foobar'] + value = subject.to_a + + value[1]['Content-Length'].should eq('6') # Headers + end + + it "does not fix the Content-Length, if it's already set" do + subject.body = ['foobar'] + subject.header = {'Content-Length' => '3'} + value = subject.to_a + + value[1]['Content-Length'].should eq('3') # Headers + end + + it "returns the Content-Type in the header" do + subject.header = {'Content-Type' => 'application/json'} + value = subject.to_a + + value[1]['Content-Type'].should eq('application/json') # Headers + end + + it "returns as default 'text/html' as Content-Type" do + value = subject.to_a + + value[1]['Content-Type'].should eq('text/html') # Headers + end + + it "removes Content-Type, Content-Length and body on status code 204" do + subject.body.push '"foobar"' + subject.content_type = 'application/json' + subject.header['Content-Length'] = 8 + + subject.status = 204 + value = subject.to_a + + value[1].should eq({}) # Headers + value[2].should eq([]) # Body + end + + it "removes Content-Type, Content-Length and body on status code 304" do + subject.body.push '"foobar"' + subject.content_type = 'application/json' + subject.header['Content-Length'] = 8 + + subject.status = 304 + value = subject.to_a + + value[1].should eq({}) # Headers + value[2].should eq([]) # Body + end + end +end -- cgit v1.2.3-70-g09d2