renee-core 0.3.11 → 0.4.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/lib/{renee_core.rb → renee/core.rb} +20 -13
  2. data/lib/{renee_core → renee/core}/chaining.rb +17 -15
  3. data/lib/{renee_core → renee/core}/env_accessors.rb +3 -3
  4. data/lib/{renee_core → renee/core}/exceptions.rb +0 -0
  5. data/lib/{renee_core → renee/core}/matcher.rb +0 -0
  6. data/lib/renee/core/plugins.rb +31 -0
  7. data/lib/{renee_core → renee/core}/rack_interaction.rb +0 -0
  8. data/lib/renee/core/request_context.rb +56 -0
  9. data/lib/{renee_core → renee/core}/responding.rb +3 -1
  10. data/lib/{renee_core → renee/core}/response.rb +0 -0
  11. data/lib/{renee_core → renee/core}/routing.rb +98 -101
  12. data/lib/{renee_core → renee/core}/transform.rb +0 -0
  13. data/test/{chaining_test.rb → renee-core/chaining_test.rb} +3 -3
  14. data/test/{env_accessors_test.rb → renee-core/env_accessors_test.rb} +1 -1
  15. data/test/{include_test.rb → renee-core/include_test.rb} +0 -0
  16. data/test/renee-core/request_context_test.rb +70 -0
  17. data/test/{responding_test.rb → renee-core/responding_test.rb} +0 -0
  18. data/test/{routing_test.rb → renee-core/routing_test.rb} +39 -82
  19. data/test/renee-core/test_helper.rb +4 -0
  20. data/test/{variable_type_test.rb → renee-core/variable_type_test.rb} +0 -0
  21. data/test/test_helper.rb +70 -4
  22. metadata +88 -129
  23. data/.yardopts +0 -6
  24. data/README.md +0 -242
  25. data/Rakefile +0 -13
  26. data/lib/renee_core/request_context.rb +0 -25
  27. data/lib/renee_core/url_generation.rb +0 -108
  28. data/lib/renee_core/version.rb +0 -6
  29. data/renee-core.gemspec +0 -26
  30. data/test/url_generation_test.rb +0 -66
@@ -6,9 +6,9 @@ describe "Route chaining" do
6
6
  type = { 'Content-Type' => 'text/plain' }
7
7
  mock_app do
8
8
  path('/').get { halt [200,type,['foo']] }
9
- path('bar').put { halt [200,type,['bar']] }
10
- path('bar').var.put { |id| halt [200,type,[id]] }
11
- path('bar').var.get.halt { |id| "wow, nice to meet you " }
9
+ continue_routing.path('bar').put { halt [200,type,['bar']] }
10
+ continue_routing.path('bar').var.put { |id| halt [200,type,[id]] }
11
+ continue_routing.path('bar').var.get.halt { |id| "wow, nice to meet you " }
12
12
  end
13
13
  get '/'
14
14
  assert_equal 200, response.status
@@ -18,7 +18,7 @@ describe Renee::Core::EnvAccessors do
18
18
  end
19
19
 
20
20
  it "should raise when you try to access weird env keys" do
21
- assert_raises(Renee::Core::EnvAccessors::InvalidEnvName) {
21
+ assert_raises(Renee::Core::EnvAccessors::InvalidEnvNameError) {
22
22
  @app = Renee.core {
23
23
  self.test_test = 'hello'
24
24
  }.setup {
@@ -0,0 +1,70 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class AddHelloThereMiddleware
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ if env['hello']
10
+ env['hello'] << "there"
11
+ else
12
+ env['hello'] = 'hello'
13
+ end
14
+ @app.call(env)
15
+ end
16
+ end
17
+
18
+ class AddWhatsThatMiddleware
19
+ def initialize(app)
20
+ @app = app
21
+ end
22
+
23
+ def call(env)
24
+ if env['hello']
25
+ env['hello'] << "that"
26
+ else
27
+ env['hello'] = 'whats'
28
+ end
29
+ @app.call(env)
30
+ end
31
+ end
32
+
33
+ describe "Route::Core::RequestContext#use" do
34
+ it "should allow the inclusion of arbitrary middlewares" do
35
+ type = { 'Content-Type' => 'text/plain' }
36
+ @app = Renee.core {
37
+ halt env['hello']
38
+ }.setup {
39
+ use AddHelloThereMiddleware
40
+ }
41
+ get '/'
42
+ assert_equal 200, response.status
43
+ assert_equal 'hello', response.body
44
+ end
45
+
46
+ it "should call middlewares in sequence (1)" do
47
+ type = { 'Content-Type' => 'text/plain' }
48
+ @app = Renee.core {
49
+ halt env['hello']
50
+ }.setup {
51
+ use AddHelloThereMiddleware
52
+ use AddWhatsThatMiddleware
53
+ }
54
+ get '/'
55
+ assert_equal 200, response.status
56
+ assert_equal 'hellothat', response.body
57
+ end
58
+
59
+ it "should call middlewares in sequence (2)" do
60
+ @app = Renee.core {
61
+ halt env['hello']
62
+ }.setup {
63
+ use AddWhatsThatMiddleware
64
+ use AddHelloThereMiddleware
65
+ }
66
+ get '/'
67
+ assert_equal 200, response.status
68
+ assert_equal 'whatsthere', response.body
69
+ end
70
+ end
@@ -40,66 +40,6 @@ describe Renee::Core::Routing do
40
40
  assert_equal 'posted', response.body
41
41
  end
42
42
 
43
- it "accepts a query string" do
44
- type = { 'Content-Type' => 'text/plain' }
45
- mock_app do
46
- path('test') { get { halt [200, type, [env['QUERY_STRING']]] } }
47
-
48
- path 'foo' do
49
- query_string 'bar' do
50
- get { halt [200,type,['bar']] }
51
- end
52
-
53
- query_string 'foo=bar' do
54
- post { halt [200,type,['foo']] }
55
- end
56
- end
57
- end
58
-
59
- get '/test?bar'
60
- assert_equal 200, response.status
61
- assert_equal 'bar', response.body
62
- get '/foo?bar'
63
- assert_equal 200, response.status
64
- assert_equal 'bar', response.body
65
- post '/foo?foo=bar'
66
- assert_equal 200, response.status
67
- assert_equal 'foo', response.body
68
- end
69
-
70
- it "accepts a set of query params (as hash)" do
71
- mock_app do
72
- path 'test' do
73
- query :foo => :integer do |h|
74
- halt "foo is #{h[:foo].inspect}"
75
- end
76
- end
77
- end
78
-
79
- get '/test?foo=123'
80
- assert_equal 200, response.status
81
- assert_equal 'foo is 123', response.body
82
- get '/test?foo=bar'
83
- assert_equal 404, response.status
84
- end
85
-
86
- it "accepts a set of query params (as an array)" do
87
- mock_app do
88
- path 'test' do
89
- query :foo do |var|
90
- case var
91
- when 'bar' then halt 200
92
- when 'bar2' then halt 500
93
- end
94
- end
95
- end
96
- end
97
- get '/test?foo=bar'
98
- assert_equal 200, response.status
99
- get '/test?foo=bar2'
100
- assert_equal 500, response.status
101
- end
102
-
103
43
  describe "with trailing slashes" do
104
44
  it "should ignore trailing slashes normally" do
105
45
  type = { 'Content-Type' => 'text/plain' }
@@ -212,6 +152,25 @@ describe Renee::Core::Routing do
212
152
  assert_equal '7', response.body
213
153
  end
214
154
 
155
+ it "can take an optional variable" do
156
+ type = { 'Content-Type' => 'text/plain' }
157
+ mock_app do
158
+ path 'add' do
159
+ var(:integer).optional(:integer) do |a, b|
160
+ b ||= a
161
+ halt [200, type, ["#{a + b}"]]
162
+ end
163
+ end
164
+ end
165
+
166
+ get '/add/3/4'
167
+ assert_equal 200, response.status
168
+ assert_equal '7', response.body
169
+ get '/add/3'
170
+ assert_equal 200, response.status
171
+ assert_equal '6', response.body
172
+ end
173
+
215
174
  it "allows arbitrary ranges of values" do
216
175
  type = { 'Content-Type' => 'text/plain' }
217
176
  mock_app do
@@ -297,16 +256,12 @@ describe Renee::Core::Routing do
297
256
  it "should match an extension" do
298
257
  type = { 'Content-Type' => 'text/plain' }
299
258
  mock_app do
300
- path '/test' do
301
- extension 'html' do
302
- halt [200, type, ['test html']]
303
- end
304
- extension 'json' do
305
- halt [200, type, ['test json']]
306
- end
307
-
308
- no_extension do
309
- halt [200, type, ['test nope']]
259
+ path('/test').get do
260
+ case extension
261
+ when 'html' then halt [200, type, ['test html']]
262
+ when 'json' then halt [200, type, ['test json']]
263
+ when nil then halt [200, type, ['test nope']]
264
+ else halt [406, type, ['unknown']]
310
265
  end
311
266
  end
312
267
 
@@ -321,20 +276,16 @@ describe Renee::Core::Routing do
321
276
  assert_equal 200, response.status
322
277
  assert_equal 'test json', response.body
323
278
  get '/test.xml'
324
- assert_equal 404, response.status
279
+ assert_equal 406, response.status
325
280
  end
326
281
 
327
282
  it "should match an extension when there is a non-specific variable before" do
328
283
  mock_app do
329
284
  var do |id|
330
- extension 'html' do
331
- halt "html #{id}"
332
- end
333
- extension 'xml' do
334
- halt "xml #{id}"
335
- end
336
- no_extension do
337
- halt "none #{id}"
285
+ case extension
286
+ when 'html' then halt "html #{id}"
287
+ when 'xml' then halt "xml #{id}"
288
+ when nil then halt "none #{id}"
338
289
  end
339
290
  end
340
291
  end
@@ -478,9 +429,15 @@ describe Renee::Core::Routing do
478
429
  assert_equal 'hiya', response.body
479
430
  end
480
431
 
481
- it "should allow optional paths in the request method" do
482
- blk = proc { get('/path') { halt [200, {}, "hiya"] } }
483
- assert_equal [200, {}, "hiya"], renee_for('/path', &blk)
432
+ it "should raise if you fail to halt" do
433
+ type = { 'Content-Type' => 'text/plain' }
434
+ mock_app do
435
+ get { }
436
+ halt :ok
437
+ end
438
+
439
+ get '/'
440
+ assert_equal 404, response.status
484
441
  end
485
442
  end
486
443
  end
@@ -0,0 +1,4 @@
1
+ $: << File.expand_path('../../lib', __FILE__)
2
+ require 'renee/core'
3
+ # Load shared test helpers
4
+ require File.expand_path('../../test_helper', __FILE__)
@@ -1,4 +1,70 @@
1
- $: << File.expand_path('../../lib', __FILE__)
2
- require 'renee_core'
3
- # Load shared test helpers
4
- require File.expand_path('../../../lib/test_helper', __FILE__)
1
+ require 'rubygems'
2
+ gem 'minitest'
3
+ require 'minitest/autorun'
4
+ gem 'rack-test'
5
+ require 'rack/test'
6
+
7
+ class ColoredIO
8
+ ESC = "\e["
9
+ NND = "#{ESC}0m"
10
+
11
+ def initialize(io)
12
+ @io = io
13
+ end
14
+
15
+ def print(o)
16
+ case o
17
+ when "."
18
+ @io.send(:print, "#{ESC}32m#{o}#{NND}")
19
+ when "E"
20
+ @io.send(:print, "#{ESC}33m#{o}#{NND}")
21
+ when "F"
22
+ @io.send(:print, "#{ESC}31m#{o}#{NND}")
23
+ else
24
+ @io.send(:print, o)
25
+ end
26
+ end
27
+
28
+ def puts(*o)
29
+ super
30
+ end
31
+ end
32
+
33
+ MiniTest::Unit.output = ColoredIO.new(MiniTest::Unit.output)
34
+
35
+ ## TEST HELPERS
36
+ class MiniTest::Spec
37
+ include Rack::Test::Methods
38
+
39
+ # Sets up a Sinatra::Base subclass defined with the block
40
+ # given. Used in setup or individual spec methods to establish
41
+ # the application.
42
+ def mock_app(&block)
43
+ path = default_views_path
44
+ @app = Renee.core(&block).setup {
45
+ views_path(path) if respond_to?(:views_path)
46
+ }
47
+ end
48
+
49
+ def default_views_path
50
+ File.dirname(__FILE__) + "/views"
51
+ end
52
+
53
+ def app
54
+ Rack::Lint.new(@app)
55
+ end
56
+
57
+ alias :response :last_response
58
+
59
+ # create_view :index, "test", :haml
60
+ def create_view(name, content, engine=:erb)
61
+ FileUtils.mkdir_p(default_views_path)
62
+ file = File.join(default_views_path, name.to_s + ".#{engine}")
63
+ File.open(file, 'w') { |io| io.write content }
64
+ end
65
+
66
+ # Removes the view folder after the test
67
+ def remove_views
68
+ FileUtils.rm_rf(File.dirname(__FILE__) + "/views")
69
+ end
70
+ end
metadata CHANGED
@@ -1,179 +1,138 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: renee-core
3
- version: !ruby/object:Gem::Version
4
- hash: 5
5
- prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 11
10
- version: 0.3.11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0.pre1
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Josh Hull
14
9
  - Nathan Esquenazi
15
10
  - Arthur Chiu
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2011-12-22 00:00:00 Z
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
14
+ date: 2012-01-23 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rack
18
+ requirement: &70111991759760 !ruby/object:Gem::Requirement
24
19
  none: false
25
- requirements:
20
+ requirements:
26
21
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 27
29
- segments:
30
- - 1
31
- - 3
32
- - 0
22
+ - !ruby/object:Gem::Version
33
23
  version: 1.3.0
34
- requirement: *id001
35
24
  type: :runtime
36
25
  prerelease: false
37
- name: rack
38
- - !ruby/object:Gem::Dependency
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
26
+ version_requirements: *70111991759760
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: &70111991759260 !ruby/object:Gem::Requirement
40
30
  none: false
41
- requirements:
31
+ requirements:
42
32
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 21
45
- segments:
46
- - 2
47
- - 6
48
- - 1
33
+ - !ruby/object:Gem::Version
49
34
  version: 2.6.1
50
- requirement: *id002
51
35
  type: :development
52
36
  prerelease: false
53
- name: minitest
54
- - !ruby/object:Gem::Dependency
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
37
+ version_requirements: *70111991759260
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &70111991758860 !ruby/object:Gem::Requirement
56
41
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
- version: "0"
64
- requirement: *id003
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
65
46
  type: :development
66
47
  prerelease: false
67
- name: bundler
68
- - !ruby/object:Gem::Dependency
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
48
+ version_requirements: *70111991758860
49
+ - !ruby/object:Gem::Dependency
50
+ name: rack-test
51
+ requirement: &70111991758280 !ruby/object:Gem::Requirement
70
52
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 11
75
- segments:
76
- - 0
77
- - 5
78
- - 0
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
79
56
  version: 0.5.0
80
- requirement: *id004
81
57
  type: :development
82
58
  prerelease: false
83
- name: rack-test
84
- - !ruby/object:Gem::Dependency
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
59
+ version_requirements: *70111991758280
60
+ - !ruby/object:Gem::Dependency
61
+ name: rake
62
+ requirement: &70111991757700 !ruby/object:Gem::Requirement
86
63
  none: false
87
- requirements:
88
- - - "="
89
- - !ruby/object:Gem::Version
90
- hash: 49
91
- segments:
92
- - 0
93
- - 8
94
- - 7
95
- version: 0.8.7
96
- requirement: *id005
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
97
68
  type: :development
98
69
  prerelease: false
99
- name: rake
70
+ version_requirements: *70111991757700
100
71
  description: The super-friendly rack helpers.
101
- email:
72
+ email:
102
73
  - joshbuddy@gmail.com
103
74
  - nesquena@gmail.com
104
75
  - mr.arthur.chiu@gmail.com
105
76
  executables: []
106
-
107
77
  extensions: []
108
-
109
78
  extra_rdoc_files: []
110
-
111
- files:
112
- - .yardopts
113
- - README.md
114
- - Rakefile
115
- - lib/renee_core.rb
116
- - lib/renee_core/chaining.rb
117
- - lib/renee_core/env_accessors.rb
118
- - lib/renee_core/exceptions.rb
119
- - lib/renee_core/matcher.rb
120
- - lib/renee_core/rack_interaction.rb
121
- - lib/renee_core/request_context.rb
122
- - lib/renee_core/responding.rb
123
- - lib/renee_core/response.rb
124
- - lib/renee_core/routing.rb
125
- - lib/renee_core/transform.rb
126
- - lib/renee_core/url_generation.rb
127
- - lib/renee_core/version.rb
128
- - renee-core.gemspec
129
- - test/chaining_test.rb
130
- - test/env_accessors_test.rb
131
- - test/include_test.rb
132
- - test/responding_test.rb
133
- - test/routing_test.rb
79
+ files:
80
+ - lib/renee/core.rb
81
+ - lib/renee/core/chaining.rb
82
+ - lib/renee/core/env_accessors.rb
83
+ - lib/renee/core/exceptions.rb
84
+ - lib/renee/core/matcher.rb
85
+ - lib/renee/core/plugins.rb
86
+ - lib/renee/core/rack_interaction.rb
87
+ - lib/renee/core/request_context.rb
88
+ - lib/renee/core/responding.rb
89
+ - lib/renee/core/response.rb
90
+ - lib/renee/core/routing.rb
91
+ - lib/renee/core/transform.rb
92
+ - test/renee-core/chaining_test.rb
93
+ - test/renee-core/env_accessors_test.rb
94
+ - test/renee-core/include_test.rb
95
+ - test/renee-core/request_context_test.rb
96
+ - test/renee-core/responding_test.rb
97
+ - test/renee-core/routing_test.rb
98
+ - test/renee-core/test_helper.rb
99
+ - test/renee-core/variable_type_test.rb
134
100
  - test/test_helper.rb
135
- - test/url_generation_test.rb
136
- - test/variable_type_test.rb
137
101
  homepage: http://reneerb.com
138
102
  licenses: []
139
-
140
103
  post_install_message:
141
104
  rdoc_options: []
142
-
143
- require_paths:
105
+ require_paths:
144
106
  - lib
145
- required_ruby_version: !ruby/object:Gem::Requirement
107
+ required_ruby_version: !ruby/object:Gem::Requirement
146
108
  none: false
147
- requirements:
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- hash: 3
151
- segments:
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ segments:
152
114
  - 0
153
- version: "0"
154
- required_rubygems_version: !ruby/object:Gem::Requirement
115
+ hash: -4060874974939787425
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
117
  none: false
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- hash: 3
160
- segments:
161
- - 0
162
- version: "0"
118
+ requirements:
119
+ - - ! '>'
120
+ - !ruby/object:Gem::Version
121
+ version: 1.3.1
163
122
  requirements: []
164
-
165
- rubyforge_project: renee
166
- rubygems_version: 1.8.10
123
+ rubyforge_project: renee-core
124
+ rubygems_version: 1.8.15
167
125
  signing_key:
168
126
  specification_version: 3
169
127
  summary: The super-friendly rack helpers
170
- test_files:
171
- - test/chaining_test.rb
172
- - test/env_accessors_test.rb
173
- - test/include_test.rb
174
- - test/responding_test.rb
175
- - test/routing_test.rb
128
+ test_files:
129
+ - test/renee-core/chaining_test.rb
130
+ - test/renee-core/env_accessors_test.rb
131
+ - test/renee-core/include_test.rb
132
+ - test/renee-core/request_context_test.rb
133
+ - test/renee-core/responding_test.rb
134
+ - test/renee-core/routing_test.rb
135
+ - test/renee-core/test_helper.rb
136
+ - test/renee-core/variable_type_test.rb
176
137
  - test/test_helper.rb
177
- - test/url_generation_test.rb
178
- - test/variable_type_test.rb
179
138
  has_rdoc: