diff options
Diffstat (limited to 'spec/unit/request')
31 files changed, 0 insertions, 487 deletions
diff --git a/spec/unit/request/accept/encoding_spec.rb b/spec/unit/request/accept/encoding_spec.rb deleted file mode 100644 index 9353cd1..0000000 --- a/spec/unit/request/accept/encoding_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Accept, '#encoding' do -  subject { Zero::Request::Accept.new(env) } -  let(:encoding) { 'en_US' } -  let(:env) { EnvGenerator.get('/foo', {'HTTP_ACCEPT_ENCODING' => encoding}) } - -  it 'sets the encoding to the given value' do -    subject.encoding.preferred.should eq('en_US') -  end -end diff --git a/spec/unit/request/accept/language_spec.rb b/spec/unit/request/accept/language_spec.rb deleted file mode 100644 index 188d8af..0000000 --- a/spec/unit/request/accept/language_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Accept, '#language' do -  subject { Zero::Request::Accept.new(env) } -  let(:language) { 'en_US' } -  let(:env) { EnvGenerator.get('/foo', {'HTTP_ACCEPT_LANGUAGE' => language}) } - -  it 'sets the language to the given value' do -    subject.language.preferred.should eq('en_US') -  end -end diff --git a/spec/unit/request/accept/types_spec.rb b/spec/unit/request/accept/types_spec.rb deleted file mode 100644 index b5f2da7..0000000 --- a/spec/unit/request/accept/types_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Accept, '#types' do -  subject { Zero::Request::Accept.new(env) } -  let(:media_types) { 'text/html' } -  let(:env) { EnvGenerator.get('/foo', {'HTTP_ACCEPT' => media_types}) } - -  it 'sets the media type to the given value' do -    subject.types.preferred.should eq('text/html') -  end -end diff --git a/spec/unit/request/accept_spec.rb b/spec/unit/request/accept_spec.rb deleted file mode 100644 index 67840ac..0000000 --- a/spec/unit/request/accept_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#accept' do -  subject { Zero::Request.new(env) } -  let(:env) { EnvGenerator.get('/foo') } -  its(:accept) { should be_an_instance_of(Zero::Request::Accept) } -end diff --git a/spec/unit/request/accepttype/each_spec.rb b/spec/unit/request/accepttype/each_spec.rb deleted file mode 100644 index 964a63e..0000000 --- a/spec/unit/request/accepttype/each_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::AcceptType, '#each' do -  subject { Zero::Request::AcceptType.new(types) } -  let(:html) { 'text/html' } -  let(:json) { 'application/json' } -  let(:types) { [html, json].join(',') } - -  specify { expect {|b| subject.each(&b) }.to yield_successive_args(html, json) } -end diff --git a/spec/unit/request/accepttype/preferred_spec.rb b/spec/unit/request/accepttype/preferred_spec.rb deleted file mode 100644 index ef21e8d..0000000 --- a/spec/unit/request/accepttype/preferred_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::AcceptType, '#preferred' do -  subject { Zero::Request::AcceptType } -  let(:html) { 'text/html' } -  let(:json) { 'application/json' } -  let(:foo)  { 'text/foo' } -  let(:lower_quality) { foo + ';q=0.5' } -  let(:default) { '*/*;q=0.1' } -  let(:option)  { [foo + ';b=23', html].join(',') } -  let(:simple_accept)  { [html, json].join(',') } -  let(:quality_accept) { [html, lower_quality, default].join(',') } -  let(:random_accept)  { [lower_quality, default, html].join(',') } -  let(:lower_accept)   { [lower_quality, default].join(',') } -   -  context 'without mapping' do -    it { subject.new(html).preferred.should           == html  } -    it { subject.new(json).preferred.should           == json  } -    it { subject.new(option).preferred.should         == foo   } -    it { subject.new(simple_accept).preferred.should  == html  } -    it { subject.new(quality_accept).preferred.should == html  } -    it { subject.new(random_accept).preferred.should  == html  } -    it { subject.new(lower_accept).preferred.should   == foo   } -    it { subject.new(nil).preferred.should            == '*/*' } -    it { subject.new('').preferred.should             == '*/*' } -    it { subject.new('text / html').preferred.should  == html  } -  end - -#  context 'with mapping' do -#    before :all do -#      Zero::Request::Accept.map = {'text/html' => 'html'} -#    end -# -#    after :all do -#      Zero::Request::Accept.map = {} -#    end -# -#    it { subject.new(html).preferred.should == 'html' } -#  end -end diff --git a/spec/unit/request/client/address_spec.rb b/spec/unit/request/client/address_spec.rb deleted file mode 100644 index 5e0b65d..0000000 --- a/spec/unit/request/client/address_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Client, '#address' do -  subject { Zero::Request::Client.new(env) } -  let(:address) { '127.0.0.1' } -  let(:env) { {'REMOTE_ADDR' => address} } - -  its(:address) { should == address } -end diff --git a/spec/unit/request/client/hostname_spec.rb b/spec/unit/request/client/hostname_spec.rb deleted file mode 100644 index 2742641..0000000 --- a/spec/unit/request/client/hostname_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Client, '#hostname' do -  subject { Zero::Request::Client.new(env) } -  let(:hostname) { 'foo.bar' } -  let(:env) { {'REMOTE_HOST' => hostname} } - -  its(:hostname) { should == hostname } -end diff --git a/spec/unit/request/client/user_agent_spec.rb b/spec/unit/request/client/user_agent_spec.rb deleted file mode 100644 index 2f29bf1..0000000 --- a/spec/unit/request/client/user_agent_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Client, '#user_agent' do -  subject { Zero::Request::Client.new(env) } -  let(:user_agent) { 'Mozilla (dummy agent)' } -  let(:env) { {'HTTP_USER_AGENT' => user_agent} } - -  its(:user_agent) { should == user_agent } -end diff --git a/spec/unit/request/client_spec.rb b/spec/unit/request/client_spec.rb deleted file mode 100644 index 5ccd155..0000000 --- a/spec/unit/request/client_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#client' do -  subject { Zero::Request.new(env) } -  let(:env) { EnvGenerator.get('/foo') } - -  its(:client) { should be_an_instance_of(Zero::Request::Client) } -end diff --git a/spec/unit/request/content_type_spec.rb b/spec/unit/request/content_type_spec.rb deleted file mode 100644 index 7482ccc..0000000 --- a/spec/unit/request/content_type_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#content_type' do -  subject { Zero::Request.new(env) } - -  context 'returns nil with no content type' do -    let(:env) { EnvGenerator.get('/foo') } -    its('content_type') { should be(nil) } -  end - -  context 'returns the set content type' do -    let(:content_type) { 'bogus/type' } -    let(:env) { EnvGenerator.post('/foo', {'CONTENT_TYPE' => content_type}) } -    its('content_type') { should be(content_type) } -  end -end diff --git a/spec/unit/request/delete_spec.rb b/spec/unit/request/delete_spec.rb deleted file mode 100644 index 9a5737d..0000000 --- a/spec/unit/request/delete_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#delete?' do -  subject { Zero::Request.new(env) } - -  context "with a delete request" do -    let(:env) { EnvGenerator.delete('/foo') } -    its(:delete?) { should be(true) } -  end - -  context "with a get request" do -    let(:env) { EnvGenerator.get('/foo') } -    its(:delete?) { should be(false) } -  end -end diff --git a/spec/unit/request/get_spec.rb b/spec/unit/request/get_spec.rb deleted file mode 100644 index 0b96abc..0000000 --- a/spec/unit/request/get_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#get?' do -  subject { Zero::Request.new(env) } - -  context "with a get request" do -    let(:env) { EnvGenerator.get('/foo') } -    its(:get?) { should be(true) } -  end - -  context "with a post request" do -    let(:env) { EnvGenerator.post('/foo') } -    its(:get?) { should be(false) } -  end -end diff --git a/spec/unit/request/head_spec.rb b/spec/unit/request/head_spec.rb deleted file mode 100644 index 5622fd6..0000000 --- a/spec/unit/request/head_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#head?' do -  subject { Zero::Request.new(env) } - -  context "with a head request" do -    let(:env) { EnvGenerator.head('/foo') } -    its(:head?) { should be(true) } -  end - -  context "with a get request" do -    let(:env) { EnvGenerator.get('/foo') } -    its(:head?) { should be(false) } -  end -end diff --git a/spec/unit/request/method_spec.rb b/spec/unit/request/method_spec.rb deleted file mode 100644 index 42ea56a..0000000 --- a/spec/unit/request/method_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#method' do -  subject { Zero::Request.new(env) } -  let(:env) { EnvGenerator.get('/foo') } - -  its(:method) { should == :get } -end diff --git a/spec/unit/request/new_spec.rb b/spec/unit/request/new_spec.rb deleted file mode 100644 index d057800..0000000 --- a/spec/unit/request/new_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '.new' do -  subject { Zero::Request.new(env) } - -  context "with a fresh environment" do -    let(:env) { EnvGenerator.get('/foo') } -    it "creates an instance of Zero::Request" do -      Zero::Request.new(env).should be_an_instance_of(Zero::Request) -    end -  end - -  context "with an already used environment" do -    let(:env) { EnvGenerator.get('/foo') } -    let(:new_env) { subject.env } - -    it "returns an already build request" do -      Zero::Request.new(new_env).should be(subject) -    end -  end -end diff --git a/spec/unit/request/parameter/custom_spec.rb b/spec/unit/request/parameter/custom_spec.rb deleted file mode 100644 index 1abebc9..0000000 --- a/spec/unit/request/parameter/custom_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Parameter, '#custom' do -  subject { Zero::Request::Parameter.new(env) } -  let(:env) { EnvGenerator.get('/foo') } - -  it 'returns a set custom parameter' do -    subject['foo'] = 'bar' -    expect(subject.custom['foo']).to eq('bar') -  end - -  it 'returns the latest set value' do -    subject['foo'] = 'first' -    subject['foo'] = 'latest' - -    expect(subject.custom['foo']).to eq('latest') -  end - -  it 'is empty if no custom parameter is set' do -    expect(subject.custom).to eq({}) -    expect(env['zero.params.custom']).to eq({}) -  end -end diff --git a/spec/unit/request/parameter/element_reference_spec.rb b/spec/unit/request/parameter/element_reference_spec.rb deleted file mode 100644 index 1136eae..0000000 --- a/spec/unit/request/parameter/element_reference_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Parameter, '#[]' do -  subject { Zero::Request::Parameter.new(env) } - -  context 'without parameters' do -    let(:env) { EnvGenerator.get('/foo') } - -    it 'returns the custom parameter' do -      subject['foo'] = 'bar' -      expect(subject['foo']).to eq('bar') -    end -  end - -  context 'with query parameters' do -    let(:env) { EnvGenerator.get('/foo?foo=bar') } - -    it 'returns the query parameter' do -      expect(subject['foo']).to eq('bar') -    end - -    it 'returns the custom parameter' do -      subject['foo'] = 'baz' -      expect(subject['foo']).to eq('baz') -    end -  end - -  context 'with payload parameters' do -    let(:env) do -      EnvGenerator.post('/foo', { -        :input => 'foo=bar', 'CONTENT_TYPE' => 'multipart/form-data' -      }) -    end - -    it 'returns the payload value' do -      expect(subject['foo']).to eq('bar') -    end - -    it 'returns the custom parameter' do -      subject['foo'] = 'baz' -      expect(subject['foo']).to eq('baz') -    end -  end - -  context 'with query and payload parameters' do -    let(:env) do -      EnvGenerator.post('/foo?foo=baz', { -        :input => 'foo=bar', 'CONTENT_TYPE' => 'multipart/form-data' -      }) -    end - -    it 'returns the payload parameter' do -      expect(subject['foo']).to eq('bar') -    end -  end -end diff --git a/spec/unit/request/parameter/initialize_spec.rb b/spec/unit/request/parameter/initialize_spec.rb deleted file mode 100644 index 58432cb..0000000 --- a/spec/unit/request/parameter/initialize_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Parameter, '#initialize' do -  subject { Zero::Request::Parameter.new(env) } -  let(:env) { EnvGenerator.get('/get', { -    'zero.params.custom' => {'foo' => 'bar'} -  }) } - -  it 'does not overwrite parameters' do -    subject -    expect(env['zero.params.custom']).to have_key('foo') -  end -end diff --git a/spec/unit/request/parameter/payload_spec.rb b/spec/unit/request/parameter/payload_spec.rb deleted file mode 100644 index 563b21d..0000000 --- a/spec/unit/request/parameter/payload_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Parameter, '#payload' do -  subject { Zero::Request::Parameter.new(env) } - -  context 'without parameters' do -    let(:env) { EnvGenerator.get('/foo') } -    its(:payload) { should == {} } -  end - -  context 'with a query string' do -    let(:env) { EnvGenerator.get('/foo?bar=baz') } -    its(:payload) { should == {} } -  end - -  context 'with a post body' do -    let(:env) do -      EnvGenerator.post('/foo', { -        :input => 'bar=baz', 'CONTENT_TYPE' => 'multipart/form-data' -      }) -    end -    its(:payload) { should == {'bar' => 'baz'} } -  end - -  context 'with special characters' do -    let(:env) do -      EnvGenerator.post('/foo', { -        :input => 'bar=foo%20bar', 'CONTENT_TYPE' => 'multipart/form-data' -      }) -    end -    its(:payload) { should == {'bar' => 'foo bar'} } -  end - -  # TODO behaves like this, but is this really good like this? -  context 'with a post body and content type application/json' do -    let(:env) do -      EnvGenerator.post('/foo', { -        :input => '"foobar"', 'CONTENT_TYPE' => 'application/json' -      }) -    end -    its(:payload) { should == {} } -  end -end diff --git a/spec/unit/request/parameter/query_spec.rb b/spec/unit/request/parameter/query_spec.rb deleted file mode 100644 index 940e80e..0000000 --- a/spec/unit/request/parameter/query_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Parameter, '#query' do -  subject { Zero::Request::Parameter.new(env) } - -  context 'without parameters' do -    let(:env) { EnvGenerator.get('/foo') } -    its(:query) { should == {} } -  end - -  context 'with a query string' do -    let(:env) { EnvGenerator.get('/foo?bar=baz') } -    its(:query) { should == {'bar' => 'baz'} } -  end - -  context 'with a post body' do -    let(:env) { EnvGenerator.post('/foo', {:input => 'bar=baz'}) } -    its(:query) { should == {} } -  end - -  context 'with special characters' do -    let(:env) { EnvGenerator.get('/foo?bar=foo%20bar') } -    its(:query) { should == {'bar' => 'foo bar'} } -  end -end diff --git a/spec/unit/request/params_spec.rb b/spec/unit/request/params_spec.rb deleted file mode 100644 index 116e57e..0000000 --- a/spec/unit/request/params_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#params' do -  subject { Zero::Request.new(env) } -  let(:env) { EnvGenerator.get('/foo?bar=baz') } - -  its(:params) { should be_an_instance_of(Zero::Request::Parameter) } -end diff --git a/spec/unit/request/patch_spec.rb b/spec/unit/request/patch_spec.rb deleted file mode 100644 index ae0d2db..0000000 --- a/spec/unit/request/patch_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#patch?' do -  subject { Zero::Request.new(env) } - -  context "with a patch request" do -    let(:env) { EnvGenerator.patch('/foo') } -    its(:patch?) { should be(true) } -  end - -  context "with a get request" do -    let(:env) { EnvGenerator.get('/foo') } -    its(:patch?) { should be(false) } -  end -end diff --git a/spec/unit/request/path_spec.rb b/spec/unit/request/path_spec.rb deleted file mode 100644 index 3873e48..0000000 --- a/spec/unit/request/path_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#path' do -  subject { Zero::Request.new(env) } -  let(:path) { '/foo' } -  let(:env) { EnvGenerator.get(path) } - -  its(:path) { should == path } -end diff --git a/spec/unit/request/post_spec.rb b/spec/unit/request/post_spec.rb deleted file mode 100644 index 2bfa834..0000000 --- a/spec/unit/request/post_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#post?' do -  subject { Zero::Request.new(env) } - -  context "with a post request" do -    let(:env) { EnvGenerator.post('/foo') } -    its(:post?) { should be(true) } -  end - -  context "with a get request" do -    let(:env) { EnvGenerator.get('/foo') } -    its(:post?) { should be(false) } -  end -end diff --git a/spec/unit/request/put_spec.rb b/spec/unit/request/put_spec.rb deleted file mode 100644 index 937d904..0000000 --- a/spec/unit/request/put_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#put?' do -  subject { Zero::Request.new(env) } - -  context "with a put request" do -    let(:env) { EnvGenerator.put('/foo') } -    its(:put?) { should be(true) } -  end - -  context "with a get request" do -    let(:env) { EnvGenerator.get('/foo') } -    its(:put?) { should be(false) } -  end -end diff --git a/spec/unit/request/server/hostname_spec.rb b/spec/unit/request/server/hostname_spec.rb deleted file mode 100644 index b2275b4..0000000 --- a/spec/unit/request/server/hostname_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Server, '#hostname' do -  subject { Zero::Request::Server.new(env) } -  let(:hostname) { 'FooName' } -  let(:env) { EnvGenerator.get('/foo', {'SERVER_NAME' => hostname}) } -  its(:hostname) { should be(hostname) } -end - diff --git a/spec/unit/request/server/port_spec.rb b/spec/unit/request/server/port_spec.rb deleted file mode 100644 index 24f6b5c..0000000 --- a/spec/unit/request/server/port_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Server, '#port' do -  subject { Zero::Request::Server.new(env) } - -  context 'sets the port to the given value' do -    let(:env) { EnvGenerator.get('/foo', {'SERVER_PORT' => 80}) } -    its(:port) { should be(80) } -  end - -  context 'casts also the port to an integer, while setting it' do -    let(:env) { EnvGenerator.get('/foo', {'SERVER_PORT' => '80'}) } -    its(:port) { should be(80) } -  end -end diff --git a/spec/unit/request/server/protocol_spec.rb b/spec/unit/request/server/protocol_spec.rb deleted file mode 100644 index 5aac149..0000000 --- a/spec/unit/request/server/protocol_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Server, '#protocol' do -  subject { Zero::Request::Server.new(env) } -  let(:protocol) { 'HTTP FOO' } -  let(:env) { EnvGenerator.get('/foo', {'SERVER_PROTOCOL' => protocol}) } -  its(:protocol) { should be(protocol) } -end - diff --git a/spec/unit/request/server/software_spec.rb b/spec/unit/request/server/software_spec.rb deleted file mode 100644 index 374f8a2..0000000 --- a/spec/unit/request/server/software_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -describe Zero::Request::Server, '#software' do -  subject { Zero::Request::Server.new(env) } -  let(:software) { 'SpecWare Server' } -  let(:env) { EnvGenerator.get('/foo', {'SERVER_SOFTWARE' => software}) } -  its(:software) { should be(software) } -end - diff --git a/spec/unit/request/server_spec.rb b/spec/unit/request/server_spec.rb deleted file mode 100644 index ea16fbe..0000000 --- a/spec/unit/request/server_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'spec_helper' - -describe Zero::Request, '#server' do -  subject { Zero::Request.new(env) } -  let(:env) { EnvGenerator.get('/foo') } - -  its(:server) { should be_an_instance_of(Zero::Request::Server) } -end  | 
