regal 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ module Regal
4
+ describe Request do
5
+ let :request do
6
+ described_class.new(env)
7
+ end
8
+
9
+ let :env do
10
+ {}
11
+ end
12
+
13
+ describe '#request_method' do
14
+ it 'returns the request method' do
15
+ env['REQUEST_METHOD'] = 'OPTIONS'
16
+ expect(request.request_method).to eq('OPTIONS')
17
+ end
18
+ end
19
+
20
+ describe '#head?' do
21
+ it 'returns true when the request method is HEAD' do
22
+ env['REQUEST_METHOD'] = 'HEAD'
23
+ expect(request.head?).to be_truthy
24
+ end
25
+
26
+ it 'returns false when the request method is not HEAD' do
27
+ env['REQUEST_METHOD'] = 'POST'
28
+ expect(request.head?).to be_falsy
29
+ end
30
+ end
31
+
32
+ describe '#env' do
33
+ it 'returns the object given to #initialize' do
34
+ expect(request.env).to equal(env)
35
+ end
36
+ end
37
+
38
+ describe '#parameters' do
39
+ context 'returns a hash that' do
40
+ it 'includes query string parameters' do
41
+ env['QUERY_STRING'] = 'hello=world'
42
+ expect(request.parameters).to include('hello' => 'world')
43
+ end
44
+
45
+ it 'includes path captures' do
46
+ env[Route::PATH_CAPTURES_KEY] = {:echo => 'polo'}
47
+ expect(request.parameters).to include(:echo => 'polo')
48
+ end
49
+
50
+ it 'is frozen' do
51
+ expect { request.parameters[:new] = 'value' }.to raise_error(/can't modify frozen/)
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '#headers' do
57
+ context 'returns a hash that' do
58
+ before do
59
+ env['CONTENT_LENGTH'] = '123'
60
+ env['HTTP_HOST'] = 'example.com'
61
+ env['HTTP_CONTENT_TYPE'] = 'application/octet-stream'
62
+ env['QUERY_STRING'] = 'hello=world'
63
+ end
64
+
65
+ it 'includes non-prefixed request headers' do
66
+ expect(request.headers).to include('Content-Length' => '123')
67
+ end
68
+
69
+ it 'includes HTTP prefixed request headers' do
70
+ expect(request.headers).to include(
71
+ 'Host' => 'example.com',
72
+ 'Content-Type' => 'application/octet-stream'
73
+ )
74
+ end
75
+
76
+ it 'does not include non-header fields' do
77
+ expect(request.headers).not_to have_key('Query-String')
78
+ end
79
+
80
+ it 'is frozen' do
81
+ expect { request.headers['NEW'] = 'value' }.to raise_error(/can't modify frozen/)
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#attributes' do
87
+ it 'returns a hash' do
88
+ request.attributes[:foo] = 'bar'
89
+ expect(request.attributes).to include(:foo => 'bar')
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,64 @@
1
+ module Regal
2
+ describe Response do
3
+ let :response do
4
+ described_class.new
5
+ end
6
+
7
+ context 'used as a response 3-tuple' do
8
+ before do
9
+ response.body = 'hello'
10
+ end
11
+
12
+ it 'implements #to_ary' do
13
+ status, headers, body = response
14
+ expect(status).to eq(200)
15
+ expect(headers).to eq({})
16
+ expect(body).to eq(%w[hello])
17
+ end
18
+
19
+ it 'implements #[]' do
20
+ expect(response[0]).to eq(200)
21
+ expect(response[1]).to eq({})
22
+ expect(response[2]).to eq(%w[hello])
23
+ expect(response[3]).to be_nil
24
+ end
25
+
26
+ it 'implements #[]=' do
27
+ response[2] = %w[foo]
28
+ expect(response[2]).to eq(%w[foo])
29
+ end
30
+
31
+ it 'ignores indexes over 2' do
32
+ response[10] = 10
33
+ expect(response.to_a.size).to eq(3)
34
+ end
35
+
36
+ it 'wraps string bodies in an array' do
37
+ expect(response[2]).to eq(%w[hello])
38
+ end
39
+
40
+ it 'leaves objects that respond to #each as-is' do
41
+ response.body = %w[one two three]
42
+ expect(response[2]).to eq(%w[one two three])
43
+ end
44
+
45
+ it 'leaves Rack incompatible bodies as-is' do
46
+ response.body = 123
47
+ expect(response[2]).to eq(123)
48
+ end
49
+
50
+ it 'uses the raw body if set' do
51
+ response.raw_body = %w[one two]
52
+ response.body = 'three'
53
+ expect(response[2]).to eq(%w[one two])
54
+ end
55
+ end
56
+
57
+ describe '#no_body' do
58
+ it 'sets the raw body to an empty array' do
59
+ response.no_body
60
+ expect(response[2]).to eq([])
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,2 @@
1
+ require 'rack/test'
2
+ require 'regal'
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: regal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Theo Hultberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ description: ''
28
+ email:
29
+ - theo@iconara.net
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".yardopts"
35
+ - lib/regal.rb
36
+ - lib/regal/app.rb
37
+ - lib/regal/request.rb
38
+ - lib/regal/response.rb
39
+ - lib/regal/version.rb
40
+ - spec/regal/app_spec.rb
41
+ - spec/regal/request_spec.rb
42
+ - spec/regal/response_spec.rb
43
+ - spec/spec_helper.rb
44
+ homepage: http://github.com/iconara/regal
45
+ licenses:
46
+ - BSD-3-Clause
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 1.9.3
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.4.5
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: ''
68
+ test_files:
69
+ - spec/regal/app_spec.rb
70
+ - spec/regal/request_spec.rb
71
+ - spec/regal/response_spec.rb
72
+ - spec/spec_helper.rb