sinatra-bundles 0.1.2 → 0.1.3
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.
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/sinatra/bundles/bundle.rb +36 -0
- data/lib/sinatra/bundles/helpers.rb +22 -0
- data/lib/sinatra/bundles/javascript_bundle.rb +37 -0
- data/lib/sinatra/bundles/stylesheet_bundle.rb +36 -0
- data/lib/sinatra/bundles.rb +4 -114
- data/sinatra-bundles.gemspec +11 -58
- data/spec/app.rb +1 -1
- data/spec/production_app.rb +1 -1
- data/spec/public/javascripts/eval.js +5 -0
- data/spec/sinatra-bundles_spec.rb +10 -1
- data/spec/spec_helper.rb +5 -6
- metadata +17 -57
- data/vendor/cache/sinatra-0.10.1.gem +0 -0
- data/vendor/gems/sinatra-0.10.1/AUTHORS +0 -43
- data/vendor/gems/sinatra-0.10.1/CHANGES +0 -467
- data/vendor/gems/sinatra-0.10.1/LICENSE +0 -22
- data/vendor/gems/sinatra-0.10.1/README.jp.rdoc +0 -552
- data/vendor/gems/sinatra-0.10.1/README.rdoc +0 -622
- data/vendor/gems/sinatra-0.10.1/Rakefile +0 -129
- data/vendor/gems/sinatra-0.10.1/lib/sinatra/base.rb +0 -1143
- data/vendor/gems/sinatra-0.10.1/lib/sinatra/images/404.png +0 -0
- data/vendor/gems/sinatra-0.10.1/lib/sinatra/images/500.png +0 -0
- data/vendor/gems/sinatra-0.10.1/lib/sinatra/main.rb +0 -28
- data/vendor/gems/sinatra-0.10.1/lib/sinatra/showexceptions.rb +0 -303
- data/vendor/gems/sinatra-0.10.1/lib/sinatra/tilt.rb +0 -509
- data/vendor/gems/sinatra-0.10.1/lib/sinatra.rb +0 -7
- data/vendor/gems/sinatra-0.10.1/sinatra.gemspec +0 -86
- data/vendor/gems/sinatra-0.10.1/test/base_test.rb +0 -160
- data/vendor/gems/sinatra-0.10.1/test/builder_test.rb +0 -65
- data/vendor/gems/sinatra-0.10.1/test/contest.rb +0 -64
- data/vendor/gems/sinatra-0.10.1/test/erb_test.rb +0 -81
- data/vendor/gems/sinatra-0.10.1/test/erubis_test.rb +0 -82
- data/vendor/gems/sinatra-0.10.1/test/extensions_test.rb +0 -100
- data/vendor/gems/sinatra-0.10.1/test/filter_test.rb +0 -195
- data/vendor/gems/sinatra-0.10.1/test/haml_test.rb +0 -90
- data/vendor/gems/sinatra-0.10.1/test/helper.rb +0 -76
- data/vendor/gems/sinatra-0.10.1/test/helpers_test.rb +0 -573
- data/vendor/gems/sinatra-0.10.1/test/mapped_error_test.rb +0 -186
- data/vendor/gems/sinatra-0.10.1/test/middleware_test.rb +0 -68
- data/vendor/gems/sinatra-0.10.1/test/request_test.rb +0 -33
- data/vendor/gems/sinatra-0.10.1/test/response_test.rb +0 -42
- data/vendor/gems/sinatra-0.10.1/test/result_test.rb +0 -98
- data/vendor/gems/sinatra-0.10.1/test/route_added_hook_test.rb +0 -59
- data/vendor/gems/sinatra-0.10.1/test/routing_test.rb +0 -878
- data/vendor/gems/sinatra-0.10.1/test/sass_test.rb +0 -79
- data/vendor/gems/sinatra-0.10.1/test/server_test.rb +0 -47
- data/vendor/gems/sinatra-0.10.1/test/sinatra_test.rb +0 -13
- data/vendor/gems/sinatra-0.10.1/test/static_test.rb +0 -87
- data/vendor/gems/sinatra-0.10.1/test/templates_test.rb +0 -155
- data/vendor/gems/sinatra-0.10.1/test/views/error.builder +0 -3
- data/vendor/gems/sinatra-0.10.1/test/views/error.erb +0 -3
- data/vendor/gems/sinatra-0.10.1/test/views/error.erubis +0 -3
- data/vendor/gems/sinatra-0.10.1/test/views/error.haml +0 -3
- data/vendor/gems/sinatra-0.10.1/test/views/error.sass +0 -2
- data/vendor/gems/sinatra-0.10.1/test/views/foo/hello.test +0 -1
- data/vendor/gems/sinatra-0.10.1/test/views/hello.builder +0 -1
- data/vendor/gems/sinatra-0.10.1/test/views/hello.erb +0 -1
- data/vendor/gems/sinatra-0.10.1/test/views/hello.erubis +0 -1
- data/vendor/gems/sinatra-0.10.1/test/views/hello.haml +0 -1
- data/vendor/gems/sinatra-0.10.1/test/views/hello.sass +0 -2
- data/vendor/gems/sinatra-0.10.1/test/views/hello.test +0 -1
- data/vendor/gems/sinatra-0.10.1/test/views/layout2.builder +0 -3
- data/vendor/gems/sinatra-0.10.1/test/views/layout2.erb +0 -2
- data/vendor/gems/sinatra-0.10.1/test/views/layout2.erubis +0 -2
- data/vendor/gems/sinatra-0.10.1/test/views/layout2.haml +0 -2
- data/vendor/gems/sinatra-0.10.1/test/views/layout2.test +0 -1
- data/vendor/specifications/sinatra-0.10.1.gemspec +0 -40
@@ -1,160 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class BaseTest < Test::Unit::TestCase
|
4
|
-
def test_default
|
5
|
-
assert true
|
6
|
-
end
|
7
|
-
|
8
|
-
describe 'Sinatra::Base subclasses' do
|
9
|
-
class TestApp < Sinatra::Base
|
10
|
-
get '/' do
|
11
|
-
'Hello World'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'include Rack::Utils' do
|
16
|
-
assert TestApp.included_modules.include?(Rack::Utils)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'processes requests with #call' do
|
20
|
-
assert TestApp.respond_to?(:call)
|
21
|
-
|
22
|
-
request = Rack::MockRequest.new(TestApp)
|
23
|
-
response = request.get('/')
|
24
|
-
assert response.ok?
|
25
|
-
assert_equal 'Hello World', response.body
|
26
|
-
end
|
27
|
-
|
28
|
-
class TestApp < Sinatra::Base
|
29
|
-
get '/state' do
|
30
|
-
@foo ||= "new"
|
31
|
-
body = "Foo: #{@foo}"
|
32
|
-
@foo = 'discard'
|
33
|
-
body
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'does not maintain state between requests' do
|
38
|
-
request = Rack::MockRequest.new(TestApp)
|
39
|
-
2.times do
|
40
|
-
response = request.get('/state')
|
41
|
-
assert response.ok?
|
42
|
-
assert_equal 'Foo: new', response.body
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "passes the subclass to configure blocks" do
|
47
|
-
ref = nil
|
48
|
-
TestApp.configure { |app| ref = app }
|
49
|
-
assert_equal TestApp, ref
|
50
|
-
end
|
51
|
-
|
52
|
-
it "allows the configure block arg to be omitted and does not change context" do
|
53
|
-
context = nil
|
54
|
-
TestApp.configure { context = self }
|
55
|
-
assert_equal self, context
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "Sinatra::Base as Rack middleware" do
|
60
|
-
app = lambda { |env|
|
61
|
-
headers = {'X-Downstream' => 'true'}
|
62
|
-
headers['X-Route-Missing'] = env['sinatra.route-missing'] || ''
|
63
|
-
[210, headers, ['Hello from downstream']] }
|
64
|
-
|
65
|
-
class TestMiddleware < Sinatra::Base
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'creates a middleware that responds to #call with .new' do
|
69
|
-
middleware = TestMiddleware.new(app)
|
70
|
-
assert middleware.respond_to?(:call)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'exposes the downstream app' do
|
74
|
-
middleware = TestMiddleware.new(app)
|
75
|
-
assert_same app, middleware.app
|
76
|
-
end
|
77
|
-
|
78
|
-
class TestMiddleware < Sinatra::Base
|
79
|
-
def route_missing
|
80
|
-
env['sinatra.route-missing'] = '1'
|
81
|
-
super
|
82
|
-
end
|
83
|
-
|
84
|
-
get '/' do
|
85
|
-
'Hello from middleware'
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
middleware = TestMiddleware.new(app)
|
90
|
-
request = Rack::MockRequest.new(middleware)
|
91
|
-
|
92
|
-
it 'intercepts requests' do
|
93
|
-
response = request.get('/')
|
94
|
-
assert response.ok?
|
95
|
-
assert_equal 'Hello from middleware', response.body
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'automatically forwards requests downstream when no matching route found' do
|
99
|
-
response = request.get('/missing')
|
100
|
-
assert_equal 210, response.status
|
101
|
-
assert_equal 'Hello from downstream', response.body
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'calls #route_missing before forwarding downstream' do
|
105
|
-
response = request.get('/missing')
|
106
|
-
assert_equal '1', response['X-Route-Missing']
|
107
|
-
end
|
108
|
-
|
109
|
-
class TestMiddleware < Sinatra::Base
|
110
|
-
get '/low-level-forward' do
|
111
|
-
app.call(env)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'can call the downstream app directly and return result' do
|
116
|
-
response = request.get('/low-level-forward')
|
117
|
-
assert_equal 210, response.status
|
118
|
-
assert_equal 'true', response['X-Downstream']
|
119
|
-
assert_equal 'Hello from downstream', response.body
|
120
|
-
end
|
121
|
-
|
122
|
-
class TestMiddleware < Sinatra::Base
|
123
|
-
get '/explicit-forward' do
|
124
|
-
response['X-Middleware'] = 'true'
|
125
|
-
res = forward
|
126
|
-
assert_nil res
|
127
|
-
assert_equal 210, response.status
|
128
|
-
assert_equal 'true', response['X-Downstream']
|
129
|
-
assert_equal ['Hello from downstream'], response.body
|
130
|
-
'Hello after explicit forward'
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'forwards the request downstream and integrates the response into the current context' do
|
135
|
-
response = request.get('/explicit-forward')
|
136
|
-
assert_equal 210, response.status
|
137
|
-
assert_equal 'true', response['X-Downstream']
|
138
|
-
assert_equal 'Hello after explicit forward', response.body
|
139
|
-
assert_equal '28', response['Content-Length']
|
140
|
-
end
|
141
|
-
|
142
|
-
app_content_length = lambda {|env|
|
143
|
-
[200, {'Content-Length' => '16'}, 'From downstream!']}
|
144
|
-
|
145
|
-
class TestMiddlewareContentLength < Sinatra::Base
|
146
|
-
get '/forward' do
|
147
|
-
res = forward
|
148
|
-
'From after explicit forward!'
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
middleware_content_length = TestMiddlewareContentLength.new(app_content_length)
|
153
|
-
request_content_length = Rack::MockRequest.new(middleware_content_length)
|
154
|
-
|
155
|
-
it "sets content length for last response" do
|
156
|
-
response = request_content_length.get('/forward')
|
157
|
-
assert_equal '28', response['Content-Length']
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require 'builder'
|
3
|
-
|
4
|
-
class BuilderTest < Test::Unit::TestCase
|
5
|
-
def builder_app(&block)
|
6
|
-
mock_app {
|
7
|
-
set :views, File.dirname(__FILE__) + '/views'
|
8
|
-
get '/', &block
|
9
|
-
}
|
10
|
-
get '/'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'renders inline Builder strings' do
|
14
|
-
builder_app { builder 'xml.instruct!' }
|
15
|
-
assert ok?
|
16
|
-
assert_equal %{<?xml version="1.0" encoding="UTF-8"?>\n}, body
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'renders inline blocks' do
|
20
|
-
builder_app {
|
21
|
-
@name = "Frank & Mary"
|
22
|
-
builder do |xml|
|
23
|
-
xml.couple @name
|
24
|
-
end
|
25
|
-
}
|
26
|
-
assert ok?
|
27
|
-
assert_equal "<couple>Frank & Mary</couple>\n", body
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'renders .builder files in views path' do
|
31
|
-
builder_app {
|
32
|
-
@name = "Blue"
|
33
|
-
builder :hello
|
34
|
-
}
|
35
|
-
assert ok?
|
36
|
-
assert_equal %(<exclaim>You're my boy, Blue!</exclaim>\n), body
|
37
|
-
end
|
38
|
-
|
39
|
-
it "renders with inline layouts" do
|
40
|
-
mock_app {
|
41
|
-
layout do
|
42
|
-
%(xml.layout { xml << yield })
|
43
|
-
end
|
44
|
-
get('/') { builder %(xml.em 'Hello World') }
|
45
|
-
}
|
46
|
-
get '/'
|
47
|
-
assert ok?
|
48
|
-
assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
|
49
|
-
end
|
50
|
-
|
51
|
-
it "renders with file layouts" do
|
52
|
-
builder_app {
|
53
|
-
builder %(xml.em 'Hello World'), :layout => :layout2
|
54
|
-
}
|
55
|
-
assert ok?
|
56
|
-
assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
|
57
|
-
end
|
58
|
-
|
59
|
-
it "raises error if template not found" do
|
60
|
-
mock_app {
|
61
|
-
get('/') { builder :no_such_template }
|
62
|
-
}
|
63
|
-
assert_raise(Errno::ENOENT) { get('/') }
|
64
|
-
end
|
65
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
|
3
|
-
# Test::Unit loads a default test if the suite is empty, and the only
|
4
|
-
# purpose of that test is to fail. As having empty contexts is a common
|
5
|
-
# practice, we decided to overwrite TestSuite#empty? in order to
|
6
|
-
# allow them. Having a failure when no tests have been defined seems
|
7
|
-
# counter-intuitive.
|
8
|
-
class Test::Unit::TestSuite
|
9
|
-
unless method_defined?(:empty?)
|
10
|
-
def empty?
|
11
|
-
false
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# We added setup, test and context as class methods, and the instance
|
17
|
-
# method setup now iterates on the setup blocks. Note that all setup
|
18
|
-
# blocks must be defined with the block syntax. Adding a setup instance
|
19
|
-
# method defeats the purpose of this library.
|
20
|
-
class Test::Unit::TestCase
|
21
|
-
def self.setup(&block)
|
22
|
-
setup_blocks << block
|
23
|
-
end
|
24
|
-
|
25
|
-
def setup
|
26
|
-
self.class.setup_blocks.each do |block|
|
27
|
-
instance_eval(&block)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.context(name, &block)
|
32
|
-
subclass = Class.new(self.superclass)
|
33
|
-
subclass.setup_blocks.unshift(*setup_blocks)
|
34
|
-
subclass.class_eval(&block)
|
35
|
-
const_set(context_name(name), subclass)
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.test(name, &block)
|
39
|
-
define_method(test_name(name), &block)
|
40
|
-
end
|
41
|
-
|
42
|
-
class << self
|
43
|
-
alias_method :should, :test
|
44
|
-
alias_method :describe, :context
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def self.setup_blocks
|
50
|
-
@setup_blocks ||= []
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.context_name(name)
|
54
|
-
"Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.test_name(name)
|
58
|
-
"test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.sanitize_name(name)
|
62
|
-
name.gsub(/\W+/, ' ').strip
|
63
|
-
end
|
64
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class ERBTest < Test::Unit::TestCase
|
4
|
-
def erb_app(&block)
|
5
|
-
mock_app {
|
6
|
-
set :views, File.dirname(__FILE__) + '/views'
|
7
|
-
get '/', &block
|
8
|
-
}
|
9
|
-
get '/'
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'renders inline ERB strings' do
|
13
|
-
erb_app { erb '<%= 1 + 1 %>' }
|
14
|
-
assert ok?
|
15
|
-
assert_equal '2', body
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'renders .erb files in views path' do
|
19
|
-
erb_app { erb :hello }
|
20
|
-
assert ok?
|
21
|
-
assert_equal "Hello World\n", body
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'takes a :locals option' do
|
25
|
-
erb_app {
|
26
|
-
locals = {:foo => 'Bar'}
|
27
|
-
erb '<%= foo %>', :locals => locals
|
28
|
-
}
|
29
|
-
assert ok?
|
30
|
-
assert_equal 'Bar', body
|
31
|
-
end
|
32
|
-
|
33
|
-
it "renders with inline layouts" do
|
34
|
-
mock_app {
|
35
|
-
layout { 'THIS. IS. <%= yield.upcase %>!' }
|
36
|
-
get('/') { erb 'Sparta' }
|
37
|
-
}
|
38
|
-
get '/'
|
39
|
-
assert ok?
|
40
|
-
assert_equal 'THIS. IS. SPARTA!', body
|
41
|
-
end
|
42
|
-
|
43
|
-
it "renders with file layouts" do
|
44
|
-
erb_app {
|
45
|
-
erb 'Hello World', :layout => :layout2
|
46
|
-
}
|
47
|
-
assert ok?
|
48
|
-
assert_equal "ERB Layout!\nHello World\n", body
|
49
|
-
end
|
50
|
-
|
51
|
-
it "renders erb with blocks" do
|
52
|
-
mock_app {
|
53
|
-
def container
|
54
|
-
@_out_buf << "THIS."
|
55
|
-
yield
|
56
|
-
@_out_buf << "SPARTA!"
|
57
|
-
end
|
58
|
-
def is; "IS." end
|
59
|
-
get '/' do
|
60
|
-
erb '<% container do %> <%= is %> <% end %>'
|
61
|
-
end
|
62
|
-
}
|
63
|
-
get '/'
|
64
|
-
assert ok?
|
65
|
-
assert_equal 'THIS. IS. SPARTA!', body
|
66
|
-
end
|
67
|
-
|
68
|
-
it "can be used in a nested fashion for partials and whatnot" do
|
69
|
-
mock_app {
|
70
|
-
template(:inner) { "<inner><%= 'hi' %></inner>" }
|
71
|
-
template(:outer) { "<outer><%= erb :inner %></outer>" }
|
72
|
-
get '/' do
|
73
|
-
erb :outer
|
74
|
-
end
|
75
|
-
}
|
76
|
-
|
77
|
-
get '/'
|
78
|
-
assert ok?
|
79
|
-
assert_equal '<outer><inner>hi</inner></outer>', body
|
80
|
-
end
|
81
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require 'erubis'
|
3
|
-
|
4
|
-
class ERubisTest < Test::Unit::TestCase
|
5
|
-
def erubis_app(&block)
|
6
|
-
mock_app {
|
7
|
-
set :views, File.dirname(__FILE__) + '/views'
|
8
|
-
get '/', &block
|
9
|
-
}
|
10
|
-
get '/'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'renders inline ERubis strings' do
|
14
|
-
erubis_app { erubis '<%= 1 + 1 %>' }
|
15
|
-
assert ok?
|
16
|
-
assert_equal '2', body
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'renders .erubis files in views path' do
|
20
|
-
erubis_app { erubis :hello }
|
21
|
-
assert ok?
|
22
|
-
assert_equal "Hello World\n", body
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'takes a :locals option' do
|
26
|
-
erubis_app {
|
27
|
-
locals = {:foo => 'Bar'}
|
28
|
-
erubis '<%= foo %>', :locals => locals
|
29
|
-
}
|
30
|
-
assert ok?
|
31
|
-
assert_equal 'Bar', body
|
32
|
-
end
|
33
|
-
|
34
|
-
it "renders with inline layouts" do
|
35
|
-
mock_app {
|
36
|
-
layout { 'THIS. IS. <%= yield.upcase %>!' }
|
37
|
-
get('/') { erubis 'Sparta' }
|
38
|
-
}
|
39
|
-
get '/'
|
40
|
-
assert ok?
|
41
|
-
assert_equal 'THIS. IS. SPARTA!', body
|
42
|
-
end
|
43
|
-
|
44
|
-
it "renders with file layouts" do
|
45
|
-
erubis_app {
|
46
|
-
erubis 'Hello World', :layout => :layout2
|
47
|
-
}
|
48
|
-
assert ok?
|
49
|
-
assert_equal "ERubis Layout!\nHello World\n", body
|
50
|
-
end
|
51
|
-
|
52
|
-
it "renders erubis with blocks" do
|
53
|
-
mock_app {
|
54
|
-
def container
|
55
|
-
@_out_buf << "THIS."
|
56
|
-
yield
|
57
|
-
@_out_buf << "SPARTA!"
|
58
|
-
end
|
59
|
-
def is; "IS." end
|
60
|
-
get '/' do
|
61
|
-
erubis '<% container do %> <%= is %> <% end %>'
|
62
|
-
end
|
63
|
-
}
|
64
|
-
get '/'
|
65
|
-
assert ok?
|
66
|
-
assert_equal 'THIS. IS. SPARTA!', body
|
67
|
-
end
|
68
|
-
|
69
|
-
it "can be used in a nested fashion for partials and whatnot" do
|
70
|
-
mock_app {
|
71
|
-
template(:inner) { "<inner><%= 'hi' %></inner>" }
|
72
|
-
template(:outer) { "<outer><%= erubis :inner %></outer>" }
|
73
|
-
get '/' do
|
74
|
-
erubis :outer
|
75
|
-
end
|
76
|
-
}
|
77
|
-
|
78
|
-
get '/'
|
79
|
-
assert ok?
|
80
|
-
assert_equal '<outer><inner>hi</inner></outer>', body
|
81
|
-
end
|
82
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class ExtensionsTest < Test::Unit::TestCase
|
4
|
-
module FooExtensions
|
5
|
-
def foo
|
6
|
-
end
|
7
|
-
|
8
|
-
private
|
9
|
-
def im_hiding_in_ur_foos
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module BarExtensions
|
14
|
-
def bar
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module BazExtensions
|
19
|
-
def baz
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module QuuxExtensions
|
24
|
-
def quux
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
module PainExtensions
|
29
|
-
def foo=(name); end
|
30
|
-
def bar?(name); end
|
31
|
-
def fizz!(name); end
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'will add the methods to the DSL for the class in which you register them and its subclasses' do
|
35
|
-
Sinatra::Base.register FooExtensions
|
36
|
-
assert Sinatra::Base.respond_to?(:foo)
|
37
|
-
|
38
|
-
Sinatra::Application.register BarExtensions
|
39
|
-
assert Sinatra::Application.respond_to?(:bar)
|
40
|
-
assert Sinatra::Application.respond_to?(:foo)
|
41
|
-
assert !Sinatra::Base.respond_to?(:bar)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'allows extending by passing a block' do
|
45
|
-
Sinatra::Base.register {
|
46
|
-
def im_in_ur_anonymous_module; end
|
47
|
-
}
|
48
|
-
assert Sinatra::Base.respond_to?(:im_in_ur_anonymous_module)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'will make sure any public methods added via Application#register are delegated to Sinatra::Delegator' do
|
52
|
-
Sinatra::Application.register FooExtensions
|
53
|
-
assert Sinatra::Delegator.private_instance_methods.
|
54
|
-
map { |m| m.to_sym }.include?(:foo)
|
55
|
-
assert !Sinatra::Delegator.private_instance_methods.
|
56
|
-
map { |m| m.to_sym }.include?(:im_hiding_in_ur_foos)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'will handle special method names' do
|
60
|
-
Sinatra::Application.register PainExtensions
|
61
|
-
assert Sinatra::Delegator.private_instance_methods.
|
62
|
-
map { |m| m.to_sym }.include?(:foo=)
|
63
|
-
assert Sinatra::Delegator.private_instance_methods.
|
64
|
-
map { |m| m.to_sym }.include?(:bar?)
|
65
|
-
assert Sinatra::Delegator.private_instance_methods.
|
66
|
-
map { |m| m.to_sym }.include?(:fizz!)
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'will not delegate methods on Base#register' do
|
70
|
-
Sinatra::Base.register QuuxExtensions
|
71
|
-
assert !Sinatra::Delegator.private_instance_methods.include?("quux")
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'will extend the Sinatra::Application application by default' do
|
75
|
-
Sinatra.register BazExtensions
|
76
|
-
assert !Sinatra::Base.respond_to?(:baz)
|
77
|
-
assert Sinatra::Application.respond_to?(:baz)
|
78
|
-
end
|
79
|
-
|
80
|
-
module BizzleExtension
|
81
|
-
def bizzle
|
82
|
-
bizzle_option
|
83
|
-
end
|
84
|
-
|
85
|
-
def self.registered(base)
|
86
|
-
fail "base should be BizzleApp" unless base == BizzleApp
|
87
|
-
fail "base should have already extended BizzleExtension" unless base.respond_to?(:bizzle)
|
88
|
-
base.set :bizzle_option, 'bizzle!'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class BizzleApp < Sinatra::Base
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'sends .registered to the extension module after extending the class' do
|
96
|
-
BizzleApp.register BizzleExtension
|
97
|
-
assert_equal 'bizzle!', BizzleApp.bizzle_option
|
98
|
-
assert_equal 'bizzle!', BizzleApp.bizzle
|
99
|
-
end
|
100
|
-
end
|