sinatra 1.4.8 → 2.0.8.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

Files changed (129) hide show
  1. checksums.yaml +5 -5
  2. data/AUTHORS.md +1 -0
  3. data/CHANGELOG.md +238 -54
  4. data/CONTRIBUTING.md +8 -8
  5. data/Gemfile +47 -47
  6. data/LICENSE +4 -1
  7. data/MAINTENANCE.md +42 -0
  8. data/README.de.md +650 -442
  9. data/README.es.md +738 -357
  10. data/README.fr.md +15 -15
  11. data/README.hu.md +37 -3
  12. data/README.ja.md +124 -66
  13. data/README.ko.md +14 -14
  14. data/README.malayalam.md +3141 -0
  15. data/README.md +530 -403
  16. data/README.pt-br.md +2361 -334
  17. data/README.pt-pt.md +2 -2
  18. data/README.ru.md +856 -607
  19. data/README.zh.md +90 -28
  20. data/Rakefile +77 -51
  21. data/SECURITY.md +35 -0
  22. data/VERSION +1 -0
  23. data/lib/sinatra/base.rb +177 -239
  24. data/lib/sinatra/indifferent_hash.rb +200 -0
  25. data/lib/sinatra/main.rb +30 -10
  26. data/lib/sinatra/show_exceptions.rb +102 -62
  27. data/lib/sinatra/version.rb +1 -1
  28. data/sinatra.gemspec +44 -8
  29. metadata +41 -166
  30. data/lib/sinatra/ext.rb +0 -17
  31. data/test/asciidoctor_test.rb +0 -72
  32. data/test/base_test.rb +0 -167
  33. data/test/builder_test.rb +0 -91
  34. data/test/coffee_test.rb +0 -96
  35. data/test/compile_test.rb +0 -183
  36. data/test/contest.rb +0 -91
  37. data/test/creole_test.rb +0 -65
  38. data/test/delegator_test.rb +0 -160
  39. data/test/encoding_test.rb +0 -20
  40. data/test/erb_test.rb +0 -116
  41. data/test/extensions_test.rb +0 -98
  42. data/test/filter_test.rb +0 -487
  43. data/test/haml_test.rb +0 -109
  44. data/test/helper.rb +0 -132
  45. data/test/helpers_test.rb +0 -1917
  46. data/test/integration/app.rb +0 -79
  47. data/test/integration_helper.rb +0 -236
  48. data/test/integration_test.rb +0 -104
  49. data/test/less_test.rb +0 -69
  50. data/test/liquid_test.rb +0 -77
  51. data/test/mapped_error_test.rb +0 -285
  52. data/test/markaby_test.rb +0 -80
  53. data/test/markdown_test.rb +0 -85
  54. data/test/mediawiki_test.rb +0 -68
  55. data/test/middleware_test.rb +0 -68
  56. data/test/nokogiri_test.rb +0 -67
  57. data/test/public/favicon.ico +0 -0
  58. data/test/public/hello+world.txt +0 -1
  59. data/test/rabl_test.rb +0 -89
  60. data/test/rack_test.rb +0 -45
  61. data/test/radius_test.rb +0 -59
  62. data/test/rdoc_test.rb +0 -66
  63. data/test/readme_test.rb +0 -130
  64. data/test/request_test.rb +0 -100
  65. data/test/response_test.rb +0 -63
  66. data/test/result_test.rb +0 -76
  67. data/test/route_added_hook_test.rb +0 -59
  68. data/test/routing_test.rb +0 -1456
  69. data/test/sass_test.rb +0 -115
  70. data/test/scss_test.rb +0 -88
  71. data/test/server_test.rb +0 -56
  72. data/test/settings_test.rb +0 -582
  73. data/test/sinatra_test.rb +0 -12
  74. data/test/slim_test.rb +0 -102
  75. data/test/static_test.rb +0 -266
  76. data/test/streaming_test.rb +0 -149
  77. data/test/stylus_test.rb +0 -90
  78. data/test/templates_test.rb +0 -382
  79. data/test/textile_test.rb +0 -65
  80. data/test/views/a/in_a.str +0 -1
  81. data/test/views/ascii.erb +0 -2
  82. data/test/views/b/in_b.str +0 -1
  83. data/test/views/calc.html.erb +0 -1
  84. data/test/views/error.builder +0 -3
  85. data/test/views/error.erb +0 -3
  86. data/test/views/error.haml +0 -3
  87. data/test/views/error.sass +0 -2
  88. data/test/views/explicitly_nested.str +0 -1
  89. data/test/views/foo/hello.test +0 -1
  90. data/test/views/hello.asciidoc +0 -1
  91. data/test/views/hello.builder +0 -1
  92. data/test/views/hello.coffee +0 -1
  93. data/test/views/hello.creole +0 -1
  94. data/test/views/hello.erb +0 -1
  95. data/test/views/hello.haml +0 -1
  96. data/test/views/hello.less +0 -5
  97. data/test/views/hello.liquid +0 -1
  98. data/test/views/hello.mab +0 -1
  99. data/test/views/hello.md +0 -1
  100. data/test/views/hello.mediawiki +0 -1
  101. data/test/views/hello.nokogiri +0 -1
  102. data/test/views/hello.rabl +0 -2
  103. data/test/views/hello.radius +0 -1
  104. data/test/views/hello.rdoc +0 -1
  105. data/test/views/hello.sass +0 -2
  106. data/test/views/hello.scss +0 -3
  107. data/test/views/hello.slim +0 -1
  108. data/test/views/hello.str +0 -1
  109. data/test/views/hello.styl +0 -2
  110. data/test/views/hello.test +0 -1
  111. data/test/views/hello.textile +0 -1
  112. data/test/views/hello.wlang +0 -1
  113. data/test/views/hello.yajl +0 -1
  114. data/test/views/layout2.builder +0 -3
  115. data/test/views/layout2.erb +0 -2
  116. data/test/views/layout2.haml +0 -2
  117. data/test/views/layout2.liquid +0 -2
  118. data/test/views/layout2.mab +0 -2
  119. data/test/views/layout2.nokogiri +0 -3
  120. data/test/views/layout2.rabl +0 -3
  121. data/test/views/layout2.radius +0 -2
  122. data/test/views/layout2.slim +0 -3
  123. data/test/views/layout2.str +0 -2
  124. data/test/views/layout2.test +0 -1
  125. data/test/views/layout2.wlang +0 -2
  126. data/test/views/nested.str +0 -1
  127. data/test/views/utf8.erb +0 -2
  128. data/test/wlang_test.rb +0 -87
  129. data/test/yajl_test.rb +0 -86
data/test/coffee_test.rb DELETED
@@ -1,96 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'coffee-script'
5
- require 'execjs'
6
-
7
- begin
8
- ExecJS.compile '1'
9
- rescue Exception
10
- raise LoadError, 'unable to execute JavaScript'
11
- end
12
-
13
- class CoffeeTest < Minitest::Test
14
- def coffee_app(options = {}, &block)
15
- mock_app do
16
- set :views, File.dirname(__FILE__) + '/views'
17
- set(options)
18
- get('/', &block)
19
- end
20
- get '/'
21
- end
22
-
23
- it 'renders inline Coffee strings' do
24
- coffee_app { coffee "alert 'Aye!'\n" }
25
- assert ok?
26
- assert body.include?("alert('Aye!');")
27
- end
28
-
29
- it 'defaults content type to javascript' do
30
- coffee_app { coffee "alert 'Aye!'\n" }
31
- assert ok?
32
- assert_equal "application/javascript;charset=utf-8", response['Content-Type']
33
- end
34
-
35
- it 'defaults allows setting content type per route' do
36
- coffee_app do
37
- content_type :html
38
- coffee "alert 'Aye!'\n"
39
- end
40
- assert ok?
41
- assert_equal "text/html;charset=utf-8", response['Content-Type']
42
- end
43
-
44
- it 'defaults allows setting content type globally' do
45
- coffee_app(:coffee => { :content_type => 'html' }) do
46
- coffee "alert 'Aye!'\n"
47
- end
48
- assert ok?
49
- assert_equal "text/html;charset=utf-8", response['Content-Type']
50
- end
51
-
52
- it 'renders .coffee files in views path' do
53
- coffee_app { coffee :hello }
54
- assert ok?
55
- assert_include body, "alert(\"Aye!\");"
56
- end
57
-
58
- it 'ignores the layout option' do
59
- coffee_app { coffee :hello, :layout => :layout2 }
60
- assert ok?
61
- assert_include body, "alert(\"Aye!\");"
62
- end
63
-
64
- it "raises error if template not found" do
65
- mock_app {
66
- get('/') { coffee :no_such_template }
67
- }
68
- assert_raises(Errno::ENOENT) { get('/') }
69
- end
70
-
71
- it "passes coffee options to the coffee engine" do
72
- coffee_app { coffee "alert 'Aye!'\n", :no_wrap => true }
73
- assert ok?
74
- assert_body "alert('Aye!');"
75
- end
76
-
77
- it "passes default coffee options to the coffee engine" do
78
- mock_app do
79
- set :coffee, :no_wrap => true # default coffee style is :nested
80
- get('/') { coffee "alert 'Aye!'\n" }
81
- end
82
- get '/'
83
- assert ok?
84
- assert_body "alert('Aye!');"
85
- end
86
- end
87
-
88
- rescue LoadError
89
- warn "#{$!.to_s}: skipping coffee tests"
90
- rescue
91
- if $!.class.name == 'ExecJS::RuntimeUnavailable'
92
- warn "#{$!.to_s}: skipping coffee tests"
93
- else
94
- raise
95
- end
96
- end
data/test/compile_test.rb DELETED
@@ -1,183 +0,0 @@
1
- # I like coding: UTF-8
2
- require File.expand_path('../helper', __FILE__)
3
-
4
- class CompileTest < Minitest::Test
5
-
6
- def self.converts pattern, expected_regexp
7
- it "generates #{expected_regexp.source} from #{pattern}" do
8
- compiled, _ = compiled pattern
9
- assert_equal expected_regexp, compiled, "Pattern #{pattern} is not compiled into #{expected_regexp.source}. Was #{compiled.source}."
10
- end
11
- end
12
- def self.parses pattern, example, expected_params
13
- it "parses #{example} with #{pattern} into params #{expected_params}" do
14
- compiled, keys = compiled pattern
15
- match = compiled.match(example)
16
- fail %Q{"#{example}" does not parse on pattern "#{pattern}" (compiled pattern is #{compiled.source}).} unless match
17
-
18
- # Aggregate e.g. multiple splat values into one array.
19
- #
20
- params = keys.zip(match.captures).reduce({}) do |hash, mapping|
21
- key, value = mapping
22
- hash[key] = if existing = hash[key]
23
- existing.respond_to?(:to_ary) ? existing << value : [existing, value]
24
- else
25
- value
26
- end
27
- hash
28
- end
29
-
30
- assert_equal expected_params, params, "Pattern #{pattern} does not match path #{example}."
31
- end
32
- end
33
- def self.fails pattern, example
34
- it "does not parse #{example} with #{pattern}" do
35
- compiled, _ = compiled pattern
36
- match = compiled.match(example)
37
- fail %Q{"#{pattern}" does parse "#{example}" but it should fail} if match
38
- end
39
- end
40
- def compiled pattern
41
- app ||= mock_app {}
42
- compiled, keys = app.send(:compile, pattern)
43
- [compiled, keys]
44
- end
45
-
46
- converts "/", %r{\A/\z}
47
- parses "/", "/", {}
48
-
49
- converts "/foo", %r{\A/foo\z}
50
- parses "/foo", "/foo", {}
51
-
52
- converts "/:foo", %r{\A/([^/?#]+)\z}
53
- parses "/:foo", "/foo", "foo" => "foo"
54
- parses "/:foo", "/foo.bar", "foo" => "foo.bar"
55
- parses "/:foo", "/foo%2Fbar", "foo" => "foo%2Fbar"
56
- parses "/:foo", "/%0Afoo", "foo" => "%0Afoo"
57
- fails "/:foo", "/foo?"
58
- fails "/:foo", "/foo/bar"
59
- fails "/:foo", "/"
60
- fails "/:foo", "/foo/"
61
-
62
- converts "/föö", %r{\A/f%[Cc]3%[Bb]6%[Cc]3%[Bb]6\z}
63
- parses "/föö", "/f%C3%B6%C3%B6", {}
64
-
65
- converts "/:foo/:bar", %r{\A/([^/?#]+)/([^/?#]+)\z}
66
- parses "/:foo/:bar", "/foo/bar", "foo" => "foo", "bar" => "bar"
67
-
68
- converts "/hello/:person", %r{\A/hello/([^/?#]+)\z}
69
- parses "/hello/:person", "/hello/Frank", "person" => "Frank"
70
-
71
- converts "/?:foo?/?:bar?", %r{\A/?([^/?#]+)?/?([^/?#]+)?\z}
72
- parses "/?:foo?/?:bar?", "/hello/world", "foo" => "hello", "bar" => "world"
73
- parses "/?:foo?/?:bar?", "/hello", "foo" => "hello", "bar" => nil
74
- parses "/?:foo?/?:bar?", "/", "foo" => nil, "bar" => nil
75
- parses "/?:foo?/?:bar?", "", "foo" => nil, "bar" => nil
76
-
77
- converts "/*", %r{\A/(.*?)\z}
78
- parses "/*", "/", "splat" => ""
79
- parses "/*", "/foo", "splat" => "foo"
80
- parses "/*", "/foo/bar", "splat" => "foo/bar"
81
-
82
- converts "/:foo/*", %r{\A/([^/?#]+)/(.*?)\z}
83
- parses "/:foo/*", "/foo/bar/baz", "foo" => "foo", "splat" => "bar/baz"
84
-
85
- converts "/:foo/:bar", %r{\A/([^/?#]+)/([^/?#]+)\z}
86
- parses "/:foo/:bar", "/user@example.com/name", "foo" => "user@example.com", "bar" => "name"
87
-
88
- converts "/test$/", %r{\A/test(?:\$|%24)/\z}
89
- parses "/test$/", "/test$/", {}
90
-
91
- converts "/te+st/", %r{\A/te(?:\+|%2[Bb])st/\z}
92
- parses "/te+st/", "/te+st/", {}
93
- fails "/te+st/", "/test/"
94
- fails "/te+st/", "/teeest/"
95
-
96
- converts "/test(bar)/", %r{\A/test(?:\(|%28)bar(?:\)|%29)/\z}
97
- parses "/test(bar)/", "/test(bar)/", {}
98
-
99
- converts "/path with spaces", %r{\A/path(?:%20|(?:\+|%2[Bb]))with(?:%20|(?:\+|%2[Bb]))spaces\z}
100
- parses "/path with spaces", "/path%20with%20spaces", {}
101
- parses "/path with spaces", "/path%2Bwith%2Bspaces", {}
102
- parses "/path with spaces", "/path+with+spaces", {}
103
-
104
- converts "/foo&bar", %r{\A/foo(?:&|%26)bar\z}
105
- parses "/foo&bar", "/foo&bar", {}
106
-
107
- converts "/:foo/*", %r{\A/([^/?#]+)/(.*?)\z}
108
- parses "/:foo/*", "/hello%20world/how%20are%20you", "foo" => "hello%20world", "splat" => "how%20are%20you"
109
-
110
- converts "/*/foo/*/*", %r{\A/(.*?)/foo/(.*?)/(.*?)\z}
111
- parses "/*/foo/*/*", "/bar/foo/bling/baz/boom", "splat" => ["bar", "bling", "baz/boom"]
112
- fails "/*/foo/*/*", "/bar/foo/baz"
113
-
114
- converts "/test.bar", %r{\A/test(?:\.|%2[Ee])bar\z}
115
- parses "/test.bar", "/test.bar", {}
116
- fails "/test.bar", "/test0bar"
117
-
118
- converts "/:file.:ext", %r{\A/((?:[^\./?#%]|(?:%[^2].|%[2][^Ee]))+)(?:\.|%2[Ee])((?:[^/?#%]|(?:%[^2].|%[2][^Ee]))+)\z}
119
- parses "/:file.:ext", "/pony.jpg", "file" => "pony", "ext" => "jpg"
120
- parses "/:file.:ext", "/pony%2Ejpg", "file" => "pony", "ext" => "jpg"
121
- fails "/:file.:ext", "/.jpg"
122
-
123
- converts "/:name.?:format?", %r{\A/((?:[^\./?#%]|(?:%[^2].|%[2][^Ee]))+)(?:\.|%2[Ee])?((?:[^/?#%]|(?:%[^2].|%[2][^Ee]))+)?\z}
124
- parses "/:name.?:format?", "/foo", "name" => "foo", "format" => nil
125
- parses "/:name.?:format?", "/foo.bar", "name" => "foo", "format" => "bar"
126
- parses "/:name.?:format?", "/foo%2Ebar", "name" => "foo", "format" => "bar"
127
- parses "/:name?.?:format", "/.bar", "name" => nil, "format" => "bar"
128
- parses "/:name?.?:format?", "/.bar", "name" => nil, "format" => "bar"
129
- parses "/:name?.:format?", "/.bar", "name" => nil, "format" => "bar"
130
- fails "/:name.:format", "/.bar"
131
- fails "/:name.?:format?", "/.bar"
132
-
133
- converts "/:user@?:host?", %r{\A/((?:[^@/?#%]|(?:%[^4].|%[4][^0]))+)(?:@|%40)?((?:[^@/?#%]|(?:%[^4].|%[4][^0]))+)?\z}
134
- parses "/:user@?:host?", "/foo@bar", "user" => "foo", "host" => "bar"
135
- parses "/:user@?:host?", "/foo.foo@bar", "user" => "foo.foo", "host" => "bar"
136
- parses "/:user@?:host?", "/foo@bar.bar", "user" => "foo", "host" => "bar.bar"
137
-
138
- # From https://gist.github.com/2154980#gistcomment-169469.
139
- #
140
- # converts "/:name(.:format)?", %r{\A/([^\.%2E/?#]+)(?:\(|%28)(?:\.|%2E)([^\.%2E/?#]+)(?:\)|%29)?\z}
141
- # parses "/:name(.:format)?", "/foo", "name" => "foo", "format" => nil
142
- # parses "/:name(.:format)?", "/foo.bar", "name" => "foo", "format" => "bar"
143
- fails "/:name(.:format)?", "/foo."
144
-
145
- parses "/:id/test.bar", "/3/test.bar", {"id" => "3"}
146
- parses "/:id/test.bar", "/2/test.bar", {"id" => "2"}
147
- parses "/:id/test.bar", "/2E/test.bar", {"id" => "2E"}
148
- parses "/:id/test.bar", "/2e/test.bar", {"id" => "2e"}
149
- parses "/:id/test.bar", "/%2E/test.bar", {"id" => "%2E"}
150
-
151
- parses '/10/:id', '/10/test', "id" => "test"
152
- parses '/10/:id', '/10/te.st', "id" => "te.st"
153
-
154
- parses '/10.1/:id', '/10.1/test', "id" => "test"
155
- parses '/10.1/:id', '/10.1/te.st', "id" => "te.st"
156
- parses '/:foo/:id', '/10.1/te.st', "foo" => "10.1", "id" => "te.st"
157
- parses '/:foo/:id', '/10.1.2/te.st', "foo" => "10.1.2", "id" => "te.st"
158
- parses '/:foo.:bar/:id', '/10.1/te.st', "foo" => "10", "bar" => "1", "id" => "te.st"
159
- fails '/:foo.:bar/:id', '/10.1.2/te.st' # We don't do crazy.
160
-
161
- parses '/:a/:b.?:c?', '/a/b', "a" => "a", "b" => "b", "c" => nil
162
- parses '/:a/:b.?:c?', '/a/b.c', "a" => "a", "b" => "b", "c" => "c"
163
- parses '/:a/:b.?:c?', '/a.b/c', "a" => "a.b", "b" => "c", "c" => nil
164
- parses '/:a/:b.?:c?', '/a.b/c.d', "a" => "a.b", "b" => "c", "c" => "d"
165
- fails '/:a/:b.?:c?', '/a.b/c.d/e'
166
-
167
- parses "/:file.:ext", "/pony%2ejpg", "file" => "pony", "ext" => "jpg"
168
- parses "/:file.:ext", "/pony%E6%AD%A3%2Ejpg", "file" => "pony%E6%AD%A3", "ext" => "jpg"
169
- parses "/:file.:ext", "/pony%e6%ad%a3%2ejpg", "file" => "pony%e6%ad%a3", "ext" => "jpg"
170
- parses "/:file.:ext", "/pony正%2Ejpg", "file" => "pony正", "ext" => "jpg"
171
- parses "/:file.:ext", "/pony正%2ejpg", "file" => "pony正", "ext" => "jpg"
172
- parses "/:file.:ext", "/pony正..jpg", "file" => "pony正", "ext" => ".jpg"
173
- fails "/:file.:ext", "/pony正.%2ejpg"
174
-
175
- converts "/:name.:format", %r{\A/((?:[^\./?#%]|(?:%[^2].|%[2][^Ee]))+)(?:\.|%2[Ee])((?:[^/?#%]|(?:%[^2].|%[2][^Ee]))+)\z}
176
- parses "/:name.:format", "/file.tar.gz", "name" => "file", "format" => "tar.gz"
177
- parses "/:name.:format1.:format2", "/file.tar.gz", "name" => "file", "format1" => "tar", "format2" => "gz"
178
- parses "/:name.:format1.:format2", "/file.temp.tar.gz", "name" => "file", "format1" => "temp", "format2" => "tar.gz"
179
-
180
- # From issue #688.
181
- #
182
- parses "/articles/10.1103/:doi", "/articles/10.1103/PhysRevLett.110.026401", "doi" => "PhysRevLett.110.026401"
183
- end
data/test/contest.rb DELETED
@@ -1,91 +0,0 @@
1
- # Copyright (c) 2009 Damian Janowski and Michel Martens for Citrusbyte
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
- require "rubygems"
21
- require "minitest/autorun"
22
-
23
- # Contest adds +teardown+, +test+ and +context+ as class methods, and the
24
- # instance methods +setup+ and +teardown+ now iterate on the corresponding
25
- # blocks. Note that all setup and teardown blocks must be defined with the
26
- # block syntax. Adding setup or teardown instance methods defeats the purpose
27
- # of this library.
28
- class Minitest::Test
29
- def self.setup(&block) setup_blocks << block end
30
- def self.teardown(&block) teardown_blocks << block end
31
- def self.setup_blocks() @setup_blocks ||= [] end
32
- def self.teardown_blocks() @teardown_blocks ||= [] end
33
-
34
- def setup_blocks(base = self.class)
35
- setup_blocks base.superclass if base.superclass.respond_to? :setup_blocks
36
- base.setup_blocks.each do |block|
37
- instance_eval(&block)
38
- end
39
- end
40
-
41
- def teardown_blocks(base = self.class)
42
- teardown_blocks base.superclass if base.superclass.respond_to? :teardown_blocks
43
- base.teardown_blocks.each do |block|
44
- instance_eval(&block)
45
- end
46
- end
47
-
48
- alias setup setup_blocks
49
- alias teardown teardown_blocks
50
-
51
- def self.context(*name, &block)
52
- subclass = Class.new(self)
53
- remove_tests(subclass)
54
- subclass.class_eval(&block) if block_given?
55
- const_set(context_name(name.join(" ")), subclass)
56
- end
57
-
58
- def self.test(name, &block)
59
- define_method(test_name(name), &block)
60
- end
61
-
62
- class << self
63
- alias_method :should, :test
64
- alias_method :describe, :context
65
- end
66
-
67
- private
68
-
69
- def self.context_name(name)
70
- # "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
71
- name = "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}"
72
- name.tr(" ", "_").to_sym
73
- end
74
-
75
- def self.test_name(name)
76
- name = "test_#{sanitize_name(name).gsub(/\s+/,'_')}_0"
77
- name = name.succ while method_defined? name
78
- name.to_sym
79
- end
80
-
81
- def self.sanitize_name(name)
82
- # name.gsub(/\W+/, ' ').strip
83
- name.gsub(/\W+/, ' ')
84
- end
85
-
86
- def self.remove_tests(subclass)
87
- subclass.public_instance_methods.grep(/^test_/).each do |meth|
88
- subclass.send(:undef_method, meth.to_sym)
89
- end
90
- end
91
- end
data/test/creole_test.rb DELETED
@@ -1,65 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'creole'
5
-
6
- class CreoleTest < Minitest::Test
7
- def creole_app(&block)
8
- mock_app do
9
- set :views, File.dirname(__FILE__) + '/views'
10
- get('/', &block)
11
- end
12
- get '/'
13
- end
14
-
15
- it 'renders inline creole strings' do
16
- creole_app { creole '= Hiya' }
17
- assert ok?
18
- assert_body "<h1>Hiya</h1>"
19
- end
20
-
21
- it 'renders .creole files in views path' do
22
- creole_app { creole :hello }
23
- assert ok?
24
- assert_body "<h1>Hello From Creole</h1>"
25
- end
26
-
27
- it "raises error if template not found" do
28
- mock_app { get('/') { creole :no_such_template } }
29
- assert_raises(Errno::ENOENT) { get('/') }
30
- end
31
-
32
- it "renders with inline layouts" do
33
- mock_app do
34
- layout { 'THIS. IS. #{yield.upcase}!' }
35
- get('/') { creole 'Sparta', :layout_engine => :str }
36
- end
37
- get '/'
38
- assert ok?
39
- assert_like 'THIS. IS. <P>SPARTA</P>!', body
40
- end
41
-
42
- it "renders with file layouts" do
43
- creole_app do
44
- creole 'Hello World', :layout => :layout2, :layout_engine => :erb
45
- end
46
- assert ok?
47
- assert_body "ERB Layout!\n<p>Hello World</p>"
48
- end
49
-
50
- it "can be used in a nested fashion for partials and whatnot" do
51
- mock_app do
52
- template(:inner) { "hi" }
53
- template(:outer) { "<outer><%= creole :inner %></outer>" }
54
- get('/') { erb :outer }
55
- end
56
-
57
- get '/'
58
- assert ok?
59
- assert_like '<outer><p>hi</p></outer>', body
60
- end
61
- end
62
-
63
- rescue LoadError
64
- warn "#{$!.to_s}: skipping creole tests"
65
- end
@@ -1,160 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- class DelegatorTest < Minitest::Test
4
- class Mirror
5
- attr_reader :last_call
6
- def method_missing(*a, &b)
7
- @last_call = [*a.map(&:to_s)]
8
- @last_call << b if b
9
- end
10
- end
11
-
12
- def self.delegates(name)
13
- it "delegates #{name}" do
14
- m = mirror { send name }
15
- assert_equal [name.to_s], m.last_call
16
- end
17
-
18
- it "delegates #{name} with arguments" do
19
- m = mirror { send name, "foo", "bar" }
20
- assert_equal [name.to_s, "foo", "bar"], m.last_call
21
- end
22
-
23
- it "delegates #{name} with block" do
24
- block = proc { }
25
- m = mirror { send(name, &block) }
26
- assert_equal [name.to_s, block], m.last_call
27
- end
28
- end
29
-
30
- setup do
31
- @target_was = Sinatra::Delegator.target
32
- end
33
-
34
- def teardown
35
- Sinatra::Delegator.target = @target_was
36
- end
37
-
38
- def delegation_app(&block)
39
- mock_app { Sinatra::Delegator.target = self }
40
- delegate(&block)
41
- end
42
-
43
- def mirror(&block)
44
- mirror = Mirror.new
45
- Sinatra::Delegator.target = mirror
46
- delegate(&block)
47
- end
48
-
49
- def delegate(&block)
50
- assert Sinatra::Delegator.target != Sinatra::Application
51
- Object.new.extend(Sinatra::Delegator).instance_eval(&block) if block
52
- Sinatra::Delegator.target
53
- end
54
-
55
- def target
56
- Sinatra::Delegator.target
57
- end
58
-
59
- it 'defaults to Sinatra::Application as target' do
60
- assert_equal Sinatra::Application, Sinatra::Delegator.target
61
- end
62
-
63
- %w[get put post delete options patch link unlink].each do |verb|
64
- it "delegates #{verb} correctly" do
65
- delegation_app do
66
- send(verb, '/hello') { 'Hello World' }
67
- end
68
-
69
- request = Rack::MockRequest.new(@app)
70
- response = request.request(verb.upcase, '/hello', {})
71
- assert response.ok?
72
- assert_equal 'Hello World', response.body
73
- end
74
- end
75
-
76
- it "delegates head correctly" do
77
- delegation_app do
78
- head '/hello' do
79
- response['X-Hello'] = 'World!'
80
- 'remove me'
81
- end
82
- end
83
-
84
- request = Rack::MockRequest.new(@app)
85
- response = request.request('HEAD', '/hello', {})
86
- assert response.ok?
87
- assert_equal 'World!', response['X-Hello']
88
- assert_equal '', response.body
89
- end
90
-
91
- it "registers extensions with the delegation target" do
92
- app, mixin = mirror, Module.new
93
- Sinatra.register mixin
94
- assert_equal ["register", mixin.to_s], app.last_call
95
- end
96
-
97
- it "registers helpers with the delegation target" do
98
- app, mixin = mirror, Module.new
99
- Sinatra.helpers mixin
100
- assert_equal ["helpers", mixin.to_s], app.last_call
101
- end
102
-
103
- it "registers middleware with the delegation target" do
104
- app, mixin = mirror, Module.new
105
- Sinatra.use mixin
106
- assert_equal ["use", mixin.to_s], app.last_call
107
- end
108
-
109
- it "should work with method_missing proxies for options" do
110
- mixin = Module.new do
111
- def respond_to?(method, *)
112
- method.to_sym == :options or super
113
- end
114
-
115
- def method_missing(method, *args, &block)
116
- return super unless method.to_sym == :options
117
- {:some => :option}
118
- end
119
- end
120
-
121
- value = nil
122
- mirror do
123
- extend mixin
124
- value = options
125
- end
126
-
127
- assert_equal({:some => :option}, value)
128
- end
129
-
130
- it "delegates crazy method names" do
131
- Sinatra::Delegator.delegate "foo:bar:"
132
- method = mirror { send "foo:bar:" }.last_call.first
133
- assert_equal "foo:bar:", method
134
- end
135
-
136
- delegates 'get'
137
- delegates 'patch'
138
- delegates 'put'
139
- delegates 'post'
140
- delegates 'delete'
141
- delegates 'head'
142
- delegates 'options'
143
- delegates 'template'
144
- delegates 'layout'
145
- delegates 'before'
146
- delegates 'after'
147
- delegates 'error'
148
- delegates 'not_found'
149
- delegates 'configure'
150
- delegates 'set'
151
- delegates 'mime_type'
152
- delegates 'enable'
153
- delegates 'disable'
154
- delegates 'use'
155
- delegates 'development?'
156
- delegates 'test?'
157
- delegates 'production?'
158
- delegates 'helpers'
159
- delegates 'settings'
160
- end
@@ -1,20 +0,0 @@
1
- # encoding: UTF-8
2
- require File.expand_path('../helper', __FILE__)
3
- require 'erb'
4
-
5
- class BaseTest < Minitest::Test
6
- setup do
7
- @base = Sinatra.new(Sinatra::Base)
8
- @base.set :views, File.dirname(__FILE__) + "/views"
9
- end
10
-
11
- it 'allows unicode strings in ascii templates per default (1.9)' do
12
- next unless defined? Encoding
13
- @base.new!.erb(File.read(@base.views + "/ascii.erb").encode("ASCII"), {}, :value => "åkej")
14
- end
15
-
16
- it 'allows ascii strings in unicode templates per default (1.9)' do
17
- next unless defined? Encoding
18
- @base.new!.erb(:utf8, {}, :value => "Some Lyrics".encode("ASCII"))
19
- end
20
- end