deas 0.38.0 → 0.39.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/Gemfile +2 -1
  2. data/{LICENSE.txt → LICENSE} +0 -0
  3. data/deas.gemspec +4 -3
  4. data/lib/deas/deas_runner.rb +17 -12
  5. data/lib/deas/handler_proxy.rb +14 -8
  6. data/lib/deas/redirect_proxy.rb +12 -12
  7. data/lib/deas/runner.rb +169 -19
  8. data/lib/deas/server.rb +14 -10
  9. data/lib/deas/template_source.rb +2 -2
  10. data/lib/deas/test_runner.rb +59 -60
  11. data/lib/deas/version.rb +1 -1
  12. data/lib/deas/view_handler.rb +55 -30
  13. data/test/support/empty_view_handler.rb +7 -0
  14. data/test/support/factory.rb +5 -0
  15. data/test/support/fake_request.rb +29 -0
  16. data/test/support/fake_sinatra_call.rb +11 -16
  17. data/test/support/file1.txt +1 -0
  18. data/test/support/file2.txt +1 -0
  19. data/test/support/routes.rb +7 -7
  20. data/test/support/show.html +0 -0
  21. data/test/support/show.json +0 -0
  22. data/test/system/{rack_tests.rb → deas_tests.rb} +19 -14
  23. data/test/unit/deas_runner_tests.rb +209 -20
  24. data/test/unit/handler_proxy_tests.rb +27 -19
  25. data/test/unit/redirect_proxy_tests.rb +32 -33
  26. data/test/unit/respond_with_proxy_tests.rb +1 -2
  27. data/test/unit/route_proxy_tests.rb +1 -1
  28. data/test/unit/route_tests.rb +1 -1
  29. data/test/unit/router_tests.rb +5 -5
  30. data/test/unit/runner_tests.rb +619 -76
  31. data/test/unit/server_tests.rb +6 -1
  32. data/test/unit/sinatra_app_tests.rb +1 -1
  33. data/test/unit/test_runner_tests.rb +377 -106
  34. data/test/unit/url_tests.rb +1 -1
  35. data/test/unit/view_handler_tests.rb +325 -182
  36. metadata +43 -24
  37. data/lib/deas/sinatra_runner.rb +0 -55
  38. data/lib/deas/test_helpers.rb +0 -23
  39. data/test/support/view_handlers.rb +0 -83
  40. data/test/unit/sinatra_runner_tests.rb +0 -79
  41. data/test/unit/test_helpers_tests.rb +0 -53
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deas
3
3
  version: !ruby/object:Gem::Version
4
- hash: 135
4
+ hash: 131
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 38
8
+ - 39
9
9
  - 0
10
- version: 0.38.0
10
+ version: 0.39.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,10 +16,25 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2015-10-21 00:00:00 Z
19
+ date: 2015-11-24 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 9
28
+ segments:
29
+ - 0
30
+ - 1
31
+ version: "0.1"
32
+ type: :runtime
33
+ name: much-plugin
34
+ version_requirements: *id001
35
+ prerelease: false
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
23
38
  none: false
24
39
  requirements:
25
40
  - - ~>
@@ -39,10 +54,10 @@ dependencies:
39
54
  version: 1.1.4
40
55
  type: :runtime
41
56
  name: ns-options
42
- version_requirements: *id001
57
+ version_requirements: *id002
43
58
  prerelease: false
44
59
  - !ruby/object:Gem::Dependency
45
- requirement: &id002 !ruby/object:Gem::Requirement
60
+ requirement: &id003 !ruby/object:Gem::Requirement
46
61
  none: false
47
62
  requirements:
48
63
  - - ~>
@@ -54,10 +69,10 @@ dependencies:
54
69
  version: "1.5"
55
70
  type: :runtime
56
71
  name: rack
57
- version_requirements: *id002
72
+ version_requirements: *id003
58
73
  prerelease: false
59
74
  - !ruby/object:Gem::Dependency
60
- requirement: &id003 !ruby/object:Gem::Requirement
75
+ requirement: &id004 !ruby/object:Gem::Requirement
61
76
  none: false
62
77
  requirements:
63
78
  - - ~>
@@ -69,10 +84,10 @@ dependencies:
69
84
  version: "1.4"
70
85
  type: :runtime
71
86
  name: sinatra
72
- version_requirements: *id003
87
+ version_requirements: *id004
73
88
  prerelease: false
74
89
  - !ruby/object:Gem::Dependency
75
- requirement: &id004 !ruby/object:Gem::Requirement
90
+ requirement: &id005 !ruby/object:Gem::Requirement
76
91
  none: false
77
92
  requirements:
78
93
  - - ~>
@@ -84,10 +99,10 @@ dependencies:
84
99
  version: "2.15"
85
100
  type: :development
86
101
  name: assert
87
- version_requirements: *id004
102
+ version_requirements: *id005
88
103
  prerelease: false
89
104
  - !ruby/object:Gem::Dependency
90
- requirement: &id005 !ruby/object:Gem::Requirement
105
+ requirement: &id006 !ruby/object:Gem::Requirement
91
106
  none: false
92
107
  requirements:
93
108
  - - ">="
@@ -98,7 +113,7 @@ dependencies:
98
113
  version: "0"
99
114
  type: :development
100
115
  name: assert-rack-test
101
- version_requirements: *id005
116
+ version_requirements: *id006
102
117
  prerelease: false
103
118
  description: Handler-based web framework powered by Sinatra
104
119
  email:
@@ -113,7 +128,7 @@ extra_rdoc_files: []
113
128
  files:
114
129
  - .gitignore
115
130
  - Gemfile
116
- - LICENSE.txt
131
+ - LICENSE
117
132
  - README.md
118
133
  - Rakefile
119
134
  - deas.gemspec
@@ -135,27 +150,30 @@ files:
135
150
  - lib/deas/server_data.rb
136
151
  - lib/deas/show_exceptions.rb
137
152
  - lib/deas/sinatra_app.rb
138
- - lib/deas/sinatra_runner.rb
139
153
  - lib/deas/template_engine.rb
140
154
  - lib/deas/template_source.rb
141
- - lib/deas/test_helpers.rb
142
155
  - lib/deas/test_runner.rb
143
156
  - lib/deas/url.rb
144
157
  - lib/deas/version.rb
145
158
  - lib/deas/view_handler.rb
146
159
  - log/.gitkeep
147
160
  - test/helper.rb
161
+ - test/support/empty_view_handler.rb
148
162
  - test/support/factory.rb
163
+ - test/support/fake_request.rb
149
164
  - test/support/fake_sinatra_call.rb
165
+ - test/support/file1.txt
166
+ - test/support/file2.txt
150
167
  - test/support/normalized_params_spy.rb
151
168
  - test/support/routes.rb
169
+ - test/support/show.html
170
+ - test/support/show.json
152
171
  - test/support/template.erb
153
172
  - test/support/template.json
154
173
  - test/support/test_layout1.test
155
174
  - test/support/test_layout2.test
156
175
  - test/support/test_template.test
157
- - test/support/view_handlers.rb
158
- - test/system/rack_tests.rb
176
+ - test/system/deas_tests.rb
159
177
  - test/unit/deas_runner_tests.rb
160
178
  - test/unit/error_handler_tests.rb
161
179
  - test/unit/exceptions_tests.rb
@@ -171,10 +189,8 @@ files:
171
189
  - test/unit/server_tests.rb
172
190
  - test/unit/show_exceptions_tests.rb
173
191
  - test/unit/sinatra_app_tests.rb
174
- - test/unit/sinatra_runner_tests.rb
175
192
  - test/unit/template_engine_tests.rb
176
193
  - test/unit/template_source_tests.rb
177
- - test/unit/test_helpers_tests.rb
178
194
  - test/unit/test_runner_tests.rb
179
195
  - test/unit/url_tests.rb
180
196
  - test/unit/view_handler_tests.rb
@@ -214,17 +230,22 @@ specification_version: 3
214
230
  summary: Handler-based web framework powered by Sinatra
215
231
  test_files:
216
232
  - test/helper.rb
233
+ - test/support/empty_view_handler.rb
217
234
  - test/support/factory.rb
235
+ - test/support/fake_request.rb
218
236
  - test/support/fake_sinatra_call.rb
237
+ - test/support/file1.txt
238
+ - test/support/file2.txt
219
239
  - test/support/normalized_params_spy.rb
220
240
  - test/support/routes.rb
241
+ - test/support/show.html
242
+ - test/support/show.json
221
243
  - test/support/template.erb
222
244
  - test/support/template.json
223
245
  - test/support/test_layout1.test
224
246
  - test/support/test_layout2.test
225
247
  - test/support/test_template.test
226
- - test/support/view_handlers.rb
227
- - test/system/rack_tests.rb
248
+ - test/system/deas_tests.rb
228
249
  - test/unit/deas_runner_tests.rb
229
250
  - test/unit/error_handler_tests.rb
230
251
  - test/unit/exceptions_tests.rb
@@ -240,10 +261,8 @@ test_files:
240
261
  - test/unit/server_tests.rb
241
262
  - test/unit/show_exceptions_tests.rb
242
263
  - test/unit/sinatra_app_tests.rb
243
- - test/unit/sinatra_runner_tests.rb
244
264
  - test/unit/template_engine_tests.rb
245
265
  - test/unit/template_source_tests.rb
246
- - test/unit/test_helpers_tests.rb
247
266
  - test/unit/test_runner_tests.rb
248
267
  - test/unit/url_tests.rb
249
268
  - test/unit/view_handler_tests.rb
@@ -1,55 +0,0 @@
1
- require 'deas/deas_runner'
2
-
3
- module Deas
4
-
5
- class SinatraRunner < DeasRunner
6
-
7
- def initialize(handler_class, args = nil)
8
- @sinatra_call = (args || {})[:sinatra_call]
9
- super(handler_class, args)
10
- end
11
-
12
- # Helpers
13
-
14
- def halt(*args)
15
- @sinatra_call.halt(*args)
16
- end
17
-
18
- def redirect(*args)
19
- @sinatra_call.redirect(*args)
20
- end
21
-
22
- def content_type(*args)
23
- @sinatra_call.content_type(*args)
24
- end
25
-
26
- def status(*args)
27
- @sinatra_call.status(*args)
28
- end
29
-
30
- def headers(*args)
31
- @sinatra_call.headers(*args)
32
- end
33
-
34
- def source_render(source, template_name, locals = nil)
35
- if self.content_type.nil?
36
- self.content_type(get_content_type_ext(template_name) || 'html')
37
- end
38
- super
39
- end
40
-
41
- def send_file(file_path, opts = nil, &block)
42
- if self.content_type.nil?
43
- self.content_type(get_content_type_ext(file_path))
44
- end
45
- @sinatra_call.send_file(file_path, opts || {}, &block)
46
- end
47
-
48
- private
49
-
50
- def get_content_type_ext(file_path)
51
- File.extname(file_path)[1..-1]
52
- end
53
-
54
- end
55
- end
@@ -1,23 +0,0 @@
1
- require 'rack/request'
2
- require 'rack/response'
3
- require 'deas/test_runner'
4
-
5
- module Deas
6
-
7
- module TestHelpers
8
-
9
- def test_runner(handler_class, args = nil)
10
- args ||= {}
11
- args[:request] ||= Rack::Request.new({})
12
- args[:response] ||= Rack::Response.new
13
- args[:session] ||= args[:request].session
14
- TestRunner.new(handler_class, args)
15
- end
16
-
17
- def test_handler(handler_class, args = nil)
18
- test_runner(handler_class, args).handler
19
- end
20
-
21
- end
22
-
23
- end
@@ -1,83 +0,0 @@
1
- require 'deas/template_source'
2
- require 'deas/view_handler'
3
-
4
- class EmptyViewHandler
5
- include Deas::ViewHandler
6
-
7
- end
8
-
9
- class TestRunnerViewHandler
10
- include Deas::ViewHandler
11
-
12
- attr_reader :before_called, :init_called
13
- attr_accessor :custom_value
14
-
15
- before{ @before_called = true }
16
-
17
- def init!; @init_called = true; end
18
- def run!; 'run has run'; end
19
-
20
- end
21
-
22
- class DeasRunnerViewHandler
23
- include Deas::ViewHandler
24
-
25
- attr_reader :before_called, :after_called
26
- attr_reader :init_bang_called, :run_bang_called
27
-
28
- layout 'web'
29
-
30
- before{ @before_called = true }
31
- after{ @after_called = true }
32
-
33
- def init!; @init_bang_called = true; end
34
- def run!; @run_bang_called = true; end
35
-
36
- end
37
-
38
- class SendFileViewHandler
39
- include Deas::ViewHandler
40
-
41
- def run!
42
- send_file "my_file.txt", :some => :option
43
- end
44
- end
45
-
46
- class HaltViewHandler
47
- include Deas::ViewHandler
48
-
49
- def run!
50
- halt_args = [ params['code'].to_i, params['headers'], params['body'] ].compact
51
- halt(*halt_args)
52
- end
53
-
54
- end
55
-
56
- class ContentTypeViewHandler
57
- include Deas::ViewHandler
58
-
59
- def run!
60
- content_type 'text/plain', :charset => 'latin1'
61
- end
62
-
63
- end
64
-
65
- class StatusViewHandler
66
- include Deas::ViewHandler
67
-
68
- def run!
69
- status 422
70
- end
71
-
72
- end
73
-
74
- class HeadersViewHandler
75
- include Deas::ViewHandler
76
-
77
- def run!
78
- headers \
79
- 'other' => "other",
80
- 'a-header' => 'some value'
81
- end
82
-
83
- end
@@ -1,79 +0,0 @@
1
- require 'assert'
2
- require 'deas/sinatra_runner'
3
-
4
- require 'deas/deas_runner'
5
- require 'test/support/view_handlers'
6
-
7
- class Deas::SinatraRunner
8
-
9
- class UnitTests < Assert::Context
10
- desc "Deas::SinatraRunner"
11
- setup do
12
- @runner_class = Deas::SinatraRunner
13
- end
14
- subject{ @runner_class }
15
-
16
- should "be a `DeasRunner`" do
17
- assert subject < Deas::Runner
18
- end
19
-
20
- end
21
-
22
- class InitTests < UnitTests
23
- desc "when init"
24
- setup do
25
- @fake_sinatra_call = Factory.sinatra_call
26
- @runner = @runner_class.new(DeasRunnerViewHandler, {
27
- :sinatra_call => @fake_sinatra_call
28
- })
29
- end
30
- subject{ @runner }
31
-
32
- should have_imeths :run
33
-
34
- should "call the sinatra_call's halt with" do
35
- response_value = catch(:halt){ subject.halt('test') }
36
- assert_equal [ 'test' ], response_value
37
- end
38
-
39
- should "call the sinatra_call's redirect method with" do
40
- response_value = catch(:halt){ subject.redirect('http://google.com') }
41
- exp = [ 302, { 'Location' => 'http://google.com' } ]
42
-
43
- assert_equal exp, response_value
44
- end
45
-
46
- should "call the sinatra_call's content_type to set the response content type" do
47
- args = ['txt', { :charset => 'latin1' }]
48
- exp = @fake_sinatra_call.content_type(*args)
49
- subject.content_type(*args)
50
- assert_equal exp, subject.content_type
51
- end
52
-
53
- should "call the sinatra_call's status to set the response status" do
54
- subject.status(422)
55
- assert_equal 422, subject.status
56
- end
57
-
58
- should "call the sinatra_call's headers to set the response headers" do
59
- exp_headers = {
60
- 'a-header' => 'some value',
61
- 'other' => 'other'
62
- }
63
- subject.headers(exp_headers)
64
- assert_equal exp_headers, subject.headers
65
- end
66
-
67
- should "call the sinatra_call's send_file to set the send files" do
68
- block_called = false
69
- args = subject.send_file('a/file.txt', {:some => 'opts'}, &proc{ block_called = true })
70
- assert_equal 'a/file.txt', args.file_path
71
- assert_equal({:some => 'opts'}, args.options)
72
- assert_true block_called
73
-
74
- assert_equal 'txt', subject.content_type
75
- end
76
-
77
- end
78
-
79
- end
@@ -1,53 +0,0 @@
1
- require 'assert'
2
- require 'deas/test_helpers'
3
-
4
- require 'rack/request'
5
- require 'rack/response'
6
- require 'deas/view_handler'
7
-
8
- module Deas::TestHelpers
9
-
10
- class UnitTests < Assert::Context
11
- desc "Deas::TestHelpers"
12
- setup do
13
- @test_helpers = Deas::TestHelpers
14
- end
15
- subject{ @test_helpers }
16
-
17
- end
18
-
19
- class MixinTests < UnitTests
20
- desc "as a mixin"
21
- setup do
22
- context_class = Class.new{ include Deas::TestHelpers }
23
- @context = context_class.new
24
- end
25
- subject{ @context }
26
-
27
- should have_imeths :test_runner, :test_handler
28
-
29
- end
30
-
31
- class HandlerTestRunnerTests < MixinTests
32
- desc "for handler testing"
33
- setup do
34
- @handler_class = Class.new{ include Deas::ViewHandler }
35
- @runner = @context.test_runner(@handler_class)
36
- @handler = @context.test_handler(@handler_class)
37
- end
38
-
39
- should "build a test runner for a given handler" do
40
- assert_kind_of ::Deas::TestRunner, @runner
41
- assert_kind_of Rack::Request, @runner.request
42
- assert_kind_of Rack::Response, @runner.response
43
- assert_equal @runner.request.session, @runner.session
44
- end
45
-
46
- should "return an initialized handler instance" do
47
- assert_kind_of @handler_class, @handler
48
- assert_equal @runner.handler, @handler
49
- end
50
-
51
- end
52
-
53
- end