devcenter 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/CONTRIBUTING.md +14 -0
  2. data/Gemfile +0 -4
  3. data/devcenter.gemspec +2 -1
  4. data/lib/devcenter.rb +0 -1
  5. data/lib/devcenter/previewer/web_app.rb +3 -2
  6. data/lib/devcenter/version.rb +1 -1
  7. metadata +19 -124
  8. data/vendor/sinatra/.gitignore +0 -6
  9. data/vendor/sinatra/.travis.yml +0 -16
  10. data/vendor/sinatra/.yardopts +0 -4
  11. data/vendor/sinatra/AUTHORS +0 -61
  12. data/vendor/sinatra/Gemfile +0 -91
  13. data/vendor/sinatra/LICENSE +0 -22
  14. data/vendor/sinatra/README.de.rdoc +0 -2116
  15. data/vendor/sinatra/README.es.rdoc +0 -2106
  16. data/vendor/sinatra/README.fr.rdoc +0 -2133
  17. data/vendor/sinatra/README.hu.rdoc +0 -608
  18. data/vendor/sinatra/README.jp.rdoc +0 -1056
  19. data/vendor/sinatra/README.ko.rdoc +0 -1932
  20. data/vendor/sinatra/README.pt-br.rdoc +0 -778
  21. data/vendor/sinatra/README.pt-pt.rdoc +0 -647
  22. data/vendor/sinatra/README.rdoc +0 -2049
  23. data/vendor/sinatra/README.ru.rdoc +0 -2033
  24. data/vendor/sinatra/README.zh.rdoc +0 -1816
  25. data/vendor/sinatra/Rakefile +0 -182
  26. data/vendor/sinatra/examples/chat.rb +0 -61
  27. data/vendor/sinatra/examples/simple.rb +0 -3
  28. data/vendor/sinatra/examples/stream.ru +0 -26
  29. data/vendor/sinatra/lib/sinatra.rb +0 -5
  30. data/vendor/sinatra/lib/sinatra/base.rb +0 -1820
  31. data/vendor/sinatra/lib/sinatra/images/404.png +0 -0
  32. data/vendor/sinatra/lib/sinatra/images/500.png +0 -0
  33. data/vendor/sinatra/lib/sinatra/main.rb +0 -30
  34. data/vendor/sinatra/lib/sinatra/showexceptions.rb +0 -345
  35. data/vendor/sinatra/lib/sinatra/version.rb +0 -3
  36. data/vendor/sinatra/sinatra.gemspec +0 -18
  37. data/vendor/sinatra/test/base_test.rb +0 -172
  38. data/vendor/sinatra/test/builder_test.rb +0 -91
  39. data/vendor/sinatra/test/coffee_test.rb +0 -90
  40. data/vendor/sinatra/test/compile_test.rb +0 -139
  41. data/vendor/sinatra/test/contest.rb +0 -98
  42. data/vendor/sinatra/test/creole_test.rb +0 -65
  43. data/vendor/sinatra/test/delegator_test.rb +0 -160
  44. data/vendor/sinatra/test/encoding_test.rb +0 -20
  45. data/vendor/sinatra/test/erb_test.rb +0 -98
  46. data/vendor/sinatra/test/extensions_test.rb +0 -98
  47. data/vendor/sinatra/test/filter_test.rb +0 -437
  48. data/vendor/sinatra/test/haml_test.rb +0 -91
  49. data/vendor/sinatra/test/helper.rb +0 -123
  50. data/vendor/sinatra/test/helpers_test.rb +0 -1768
  51. data/vendor/sinatra/test/integration/app.rb +0 -62
  52. data/vendor/sinatra/test/integration_helper.rb +0 -222
  53. data/vendor/sinatra/test/integration_test.rb +0 -87
  54. data/vendor/sinatra/test/less_test.rb +0 -69
  55. data/vendor/sinatra/test/liquid_test.rb +0 -59
  56. data/vendor/sinatra/test/mapped_error_test.rb +0 -305
  57. data/vendor/sinatra/test/markaby_test.rb +0 -80
  58. data/vendor/sinatra/test/markdown_test.rb +0 -82
  59. data/vendor/sinatra/test/middleware_test.rb +0 -68
  60. data/vendor/sinatra/test/nokogiri_test.rb +0 -67
  61. data/vendor/sinatra/test/public/favicon.ico +0 -0
  62. data/vendor/sinatra/test/rabl_test.rb +0 -89
  63. data/vendor/sinatra/test/rack_test.rb +0 -45
  64. data/vendor/sinatra/test/radius_test.rb +0 -59
  65. data/vendor/sinatra/test/rdoc_test.rb +0 -66
  66. data/vendor/sinatra/test/readme_test.rb +0 -120
  67. data/vendor/sinatra/test/request_test.rb +0 -45
  68. data/vendor/sinatra/test/response_test.rb +0 -64
  69. data/vendor/sinatra/test/result_test.rb +0 -76
  70. data/vendor/sinatra/test/route_added_hook_test.rb +0 -59
  71. data/vendor/sinatra/test/routing_test.rb +0 -1175
  72. data/vendor/sinatra/test/sass_test.rb +0 -116
  73. data/vendor/sinatra/test/scss_test.rb +0 -89
  74. data/vendor/sinatra/test/server_test.rb +0 -48
  75. data/vendor/sinatra/test/settings_test.rb +0 -561
  76. data/vendor/sinatra/test/sinatra_test.rb +0 -12
  77. data/vendor/sinatra/test/slim_test.rb +0 -84
  78. data/vendor/sinatra/test/static_test.rb +0 -219
  79. data/vendor/sinatra/test/streaming_test.rb +0 -149
  80. data/vendor/sinatra/test/templates_test.rb +0 -333
  81. data/vendor/sinatra/test/textile_test.rb +0 -65
  82. data/vendor/sinatra/test/views/a/in_a.str +0 -1
  83. data/vendor/sinatra/test/views/ascii.erb +0 -2
  84. data/vendor/sinatra/test/views/b/in_b.str +0 -1
  85. data/vendor/sinatra/test/views/calc.html.erb +0 -1
  86. data/vendor/sinatra/test/views/error.builder +0 -3
  87. data/vendor/sinatra/test/views/error.erb +0 -3
  88. data/vendor/sinatra/test/views/error.haml +0 -3
  89. data/vendor/sinatra/test/views/error.sass +0 -2
  90. data/vendor/sinatra/test/views/explicitly_nested.str +0 -1
  91. data/vendor/sinatra/test/views/foo/hello.test +0 -1
  92. data/vendor/sinatra/test/views/hello.builder +0 -1
  93. data/vendor/sinatra/test/views/hello.coffee +0 -1
  94. data/vendor/sinatra/test/views/hello.creole +0 -1
  95. data/vendor/sinatra/test/views/hello.erb +0 -1
  96. data/vendor/sinatra/test/views/hello.haml +0 -1
  97. data/vendor/sinatra/test/views/hello.less +0 -5
  98. data/vendor/sinatra/test/views/hello.liquid +0 -1
  99. data/vendor/sinatra/test/views/hello.mab +0 -1
  100. data/vendor/sinatra/test/views/hello.md +0 -1
  101. data/vendor/sinatra/test/views/hello.nokogiri +0 -1
  102. data/vendor/sinatra/test/views/hello.rabl +0 -2
  103. data/vendor/sinatra/test/views/hello.radius +0 -1
  104. data/vendor/sinatra/test/views/hello.rdoc +0 -1
  105. data/vendor/sinatra/test/views/hello.sass +0 -2
  106. data/vendor/sinatra/test/views/hello.scss +0 -3
  107. data/vendor/sinatra/test/views/hello.slim +0 -1
  108. data/vendor/sinatra/test/views/hello.str +0 -1
  109. data/vendor/sinatra/test/views/hello.test +0 -1
  110. data/vendor/sinatra/test/views/hello.textile +0 -1
  111. data/vendor/sinatra/test/views/hello.wlang +0 -1
  112. data/vendor/sinatra/test/views/hello.yajl +0 -1
  113. data/vendor/sinatra/test/views/layout2.builder +0 -3
  114. data/vendor/sinatra/test/views/layout2.erb +0 -2
  115. data/vendor/sinatra/test/views/layout2.haml +0 -2
  116. data/vendor/sinatra/test/views/layout2.liquid +0 -2
  117. data/vendor/sinatra/test/views/layout2.mab +0 -2
  118. data/vendor/sinatra/test/views/layout2.nokogiri +0 -3
  119. data/vendor/sinatra/test/views/layout2.rabl +0 -3
  120. data/vendor/sinatra/test/views/layout2.radius +0 -2
  121. data/vendor/sinatra/test/views/layout2.slim +0 -3
  122. data/vendor/sinatra/test/views/layout2.str +0 -2
  123. data/vendor/sinatra/test/views/layout2.test +0 -1
  124. data/vendor/sinatra/test/views/layout2.wlang +0 -2
  125. data/vendor/sinatra/test/views/nested.str +0 -1
  126. data/vendor/sinatra/test/views/utf8.erb +0 -2
  127. data/vendor/sinatra/test/wlang_test.rb +0 -70
  128. data/vendor/sinatra/test/yajl_test.rb +0 -86
@@ -1,30 +0,0 @@
1
- require_relative 'base'
2
-
3
- module Sinatra
4
- class Application < Base
5
-
6
- # we assume that the first file that requires 'sinatra' is the
7
- # app_file. all other path related options are calculated based
8
- # on this path by default.
9
- set :app_file, caller_files.first || $0
10
-
11
- set :run, Proc.new { File.expand_path($0) == File.expand_path(app_file) }
12
-
13
- if run? && ARGV.any?
14
- require 'optparse'
15
- OptionParser.new { |op|
16
- op.on('-p port', 'set the port (default is 4567)') { |val| set :port, Integer(val) }
17
- op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| set :bind, val }
18
- op.on('-e env', 'set the environment (default is development)') { |val| set :environment, val.to_sym }
19
- op.on('-s server', 'specify rack server/handler (default is thin)') { |val| set :server, val }
20
- op.on('-x', 'turn on the mutex lock (default is off)') { set :lock, true }
21
- }.parse!(ARGV.dup)
22
- end
23
- end
24
-
25
- at_exit { Application.run! if $!.nil? && Application.run? }
26
- end
27
-
28
- # include would include the module in Object
29
- # extend only extends the `main` object
30
- extend Sinatra::Delegator
@@ -1,345 +0,0 @@
1
- require 'rack/showexceptions'
2
-
3
- module Sinatra
4
- # Sinatra::ShowExceptions catches all exceptions raised from the app it
5
- # wraps. It shows a useful backtrace with the sourcefile and clickable
6
- # context, the whole Rack environment and the request data.
7
- #
8
- # Be careful when you use this on public-facing sites as it could reveal
9
- # information helpful to attackers.
10
- class ShowExceptions < Rack::ShowExceptions
11
- @@eats_errors = Object.new
12
- def @@eats_errors.flush(*) end
13
- def @@eats_errors.puts(*) end
14
-
15
- def initialize(app)
16
- @app = app
17
- @template = ERB.new(TEMPLATE)
18
- end
19
-
20
- def call(env)
21
- @app.call(env)
22
- rescue Exception => e
23
- errors, env["rack.errors"] = env["rack.errors"], @@eats_errors
24
-
25
- if prefers_plain_text?(env)
26
- content_type = "text/plain"
27
- body = [dump_exception(e)]
28
- else
29
- content_type = "text/html"
30
- body = pretty(env, e)
31
- end
32
-
33
- env["rack.errors"] = errors
34
-
35
- [500,
36
- {"Content-Type" => content_type,
37
- "Content-Length" => Rack::Utils.bytesize(body.join).to_s},
38
- body]
39
- end
40
-
41
- private
42
-
43
- def prefers_plain_text?(env)
44
- !(Request.new(env).preferred_type("text/plain","text/html") == "text/html") &&
45
- [/curl/].index{|item| item =~ env["HTTP_USER_AGENT"]}
46
- end
47
-
48
- def frame_class(frame)
49
- if frame.filename =~ /lib\/sinatra.*\.rb/
50
- "framework"
51
- elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
52
- frame.filename =~ /\/bin\/(\w+)$/
53
- "system"
54
- else
55
- "app"
56
- end
57
- end
58
-
59
- TEMPLATE = <<-HTML # :nodoc:
60
- <!DOCTYPE html>
61
- <html>
62
- <head>
63
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
64
- <title><%=h exception.class %> at <%=h path %></title>
65
-
66
- <script type="text/javascript">
67
- //<!--
68
- function toggle(id) {
69
- var pre = document.getElementById("pre-" + id);
70
- var post = document.getElementById("post-" + id);
71
- var context = document.getElementById("context-" + id);
72
-
73
- if (pre.style.display == 'block') {
74
- pre.style.display = 'none';
75
- post.style.display = 'none';
76
- context.style.background = "none";
77
- } else {
78
- pre.style.display = 'block';
79
- post.style.display = 'block';
80
- context.style.background = "#fffed9";
81
- }
82
- }
83
-
84
- function toggleBacktrace(){
85
- var bt = document.getElementById("backtrace");
86
- var toggler = document.getElementById("expando");
87
-
88
- if (bt.className == 'condensed') {
89
- bt.className = 'expanded';
90
- toggler.innerHTML = "(condense)";
91
- } else {
92
- bt.className = 'condensed';
93
- toggler.innerHTML = "(expand)";
94
- }
95
- }
96
- //-->
97
- </script>
98
-
99
- <style type="text/css" media="screen">
100
- * {margin: 0; padding: 0; border: 0; outline: 0;}
101
- div.clear {clear: both;}
102
- body {background: #EEEEEE; margin: 0; padding: 0;
103
- font-family: 'Lucida Grande', 'Lucida Sans Unicode',
104
- 'Garuda';}
105
- code {font-family: 'Lucida Console', monospace;
106
- font-size: 12px;}
107
- li {height: 18px;}
108
- ul {list-style: none; margin: 0; padding: 0;}
109
- ol:hover {cursor: pointer;}
110
- ol li {white-space: pre;}
111
- #explanation {font-size: 12px; color: #666666;
112
- margin: 20px 0 0 100px;}
113
- /* WRAP */
114
- #wrap {width: 1000px; background: #FFFFFF; margin: 0 auto;
115
- padding: 30px 50px 20px 50px;
116
- border-left: 1px solid #DDDDDD;
117
- border-right: 1px solid #DDDDDD;}
118
- /* HEADER */
119
- #header {margin: 0 auto 25px auto;}
120
- #header img {float: left;}
121
- #header #summary {float: left; margin: 12px 0 0 20px; width:660px;
122
- font-family: 'Lucida Grande', 'Lucida Sans Unicode';}
123
- h1 {margin: 0; font-size: 36px; color: #981919;}
124
- h2 {margin: 0; font-size: 22px; color: #333333;}
125
- #header ul {margin: 0; font-size: 12px; color: #666666;}
126
- #header ul li strong{color: #444444;}
127
- #header ul li {display: inline; padding: 0 10px;}
128
- #header ul li.first {padding-left: 0;}
129
- #header ul li.last {border: 0; padding-right: 0;}
130
- /* BODY */
131
- #backtrace,
132
- #get,
133
- #post,
134
- #cookies,
135
- #rack {width: 980px; margin: 0 auto 10px auto;}
136
- p#nav {float: right; font-size: 14px;}
137
- /* BACKTRACE */
138
- a#expando {float: left; padding-left: 5px; color: #666666;
139
- font-size: 14px; text-decoration: none; cursor: pointer;}
140
- a#expando:hover {text-decoration: underline;}
141
- h3 {float: left; width: 100px; margin-bottom: 10px;
142
- color: #981919; font-size: 14px; font-weight: bold;}
143
- #nav a {color: #666666; text-decoration: none; padding: 0 5px;}
144
- #backtrace li.frame-info {background: #f7f7f7; padding-left: 10px;
145
- font-size: 12px; color: #333333;}
146
- #backtrace ul {list-style-position: outside; border: 1px solid #E9E9E9;
147
- border-bottom: 0;}
148
- #backtrace ol {width: 920px; margin-left: 50px;
149
- font: 10px 'Lucida Console', monospace; color: #666666;}
150
- #backtrace ol li {border: 0; border-left: 1px solid #E9E9E9;
151
- padding: 2px 0;}
152
- #backtrace ol code {font-size: 10px; color: #555555; padding-left: 5px;}
153
- #backtrace-ul li {border-bottom: 1px solid #E9E9E9; height: auto;
154
- padding: 3px 0;}
155
- #backtrace-ul .code {padding: 6px 0 4px 0;}
156
- #backtrace.condensed .system,
157
- #backtrace.condensed .framework {display:none;}
158
- /* REQUEST DATA */
159
- p.no-data {padding-top: 2px; font-size: 12px; color: #666666;}
160
- table.req {width: 980px; text-align: left; font-size: 12px;
161
- color: #666666; padding: 0; border-spacing: 0;
162
- border: 1px solid #EEEEEE; border-bottom: 0;
163
- border-left: 0;
164
- clear:both}
165
- table.req tr th {padding: 2px 10px; font-weight: bold;
166
- background: #F7F7F7; border-bottom: 1px solid #EEEEEE;
167
- border-left: 1px solid #EEEEEE;}
168
- table.req tr td {padding: 2px 20px 2px 10px;
169
- border-bottom: 1px solid #EEEEEE;
170
- border-left: 1px solid #EEEEEE;}
171
- /* HIDE PRE/POST CODE AT START */
172
- .pre-context,
173
- .post-context {display: none;}
174
-
175
- table td.code {width:750px}
176
- table td.code div {width:750px;overflow:hidden}
177
- </style>
178
- </head>
179
- <body>
180
- <div id="wrap">
181
- <div id="header">
182
- <img src="<%= env['SCRIPT_NAME'] %>/__sinatra__/500.png" alt="application error" height="161" width="313" />
183
- <div id="summary">
184
- <h1><strong><%=h exception.class %></strong> at <strong><%=h path %>
185
- </strong></h1>
186
- <h2><%=h exception.message %></h2>
187
- <ul>
188
- <li class="first"><strong>file:</strong> <code>
189
- <%=h frames.first.filename.split("/").last %></code></li>
190
- <li><strong>location:</strong> <code><%=h frames.first.function %>
191
- </code></li>
192
- <li class="last"><strong>line:
193
- </strong> <%=h frames.first.lineno %></li>
194
- </ul>
195
- </div>
196
- <div class="clear"></div>
197
- </div>
198
-
199
- <div id="backtrace" class='condensed'>
200
- <h3>BACKTRACE</h3>
201
- <p><a href="#" id="expando"
202
- onclick="toggleBacktrace(); return false">(expand)</a></p>
203
- <p id="nav"><strong>JUMP TO:</strong>
204
- <a href="#get-info">GET</a>
205
- <a href="#post-info">POST</a>
206
- <a href="#cookie-info">COOKIES</a>
207
- <a href="#env-info">ENV</a>
208
- </p>
209
- <div class="clear"></div>
210
-
211
- <ul id="backtrace-ul">
212
-
213
- <% id = 1 %>
214
- <% frames.each do |frame| %>
215
- <% if frame.context_line && frame.context_line != "#" %>
216
-
217
- <li class="frame-info <%= frame_class(frame) %>">
218
- <code><%=h frame.filename %></code> in
219
- <code><strong><%=h frame.function %></strong></code>
220
- </li>
221
-
222
- <li class="code <%= frame_class(frame) %>">
223
- <% if frame.pre_context %>
224
- <ol start="<%=h frame.pre_context_lineno + 1 %>"
225
- class="pre-context" id="pre-<%= id %>"
226
- onclick="toggle(<%= id %>);">
227
- <% frame.pre_context.each do |line| %>
228
- <li class="pre-context-line"><code><%=h line %></code></li>
229
- <% end %>
230
- </ol>
231
- <% end %>
232
-
233
- <ol start="<%= frame.lineno %>" class="context" id="<%= id %>"
234
- onclick="toggle(<%= id %>);">
235
- <li class="context-line" id="context-<%= id %>"><code><%=
236
- h frame.context_line %></code></li>
237
- </ol>
238
-
239
- <% if frame.post_context %>
240
- <ol start="<%=h frame.lineno + 1 %>" class="post-context"
241
- id="post-<%= id %>" onclick="toggle(<%= id %>);">
242
- <% frame.post_context.each do |line| %>
243
- <li class="post-context-line"><code><%=h line %></code></li>
244
- <% end %>
245
- </ol>
246
- <% end %>
247
- <div class="clear"></div>
248
- </li>
249
-
250
- <% end %>
251
-
252
- <% id += 1 %>
253
- <% end %>
254
-
255
- </ul>
256
- </div> <!-- /BACKTRACE -->
257
-
258
- <div id="get">
259
- <h3 id="get-info">GET</h3>
260
- <% if req.GET and not req.GET.empty? %>
261
- <table class="req">
262
- <tr>
263
- <th>Variable</th>
264
- <th>Value</th>
265
- </tr>
266
- <% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
267
- <tr>
268
- <td><%=h key %></td>
269
- <td class="code"><div><%=h val.inspect %></div></td>
270
- </tr>
271
- <% } %>
272
- </table>
273
- <% else %>
274
- <p class="no-data">No GET data.</p>
275
- <% end %>
276
- <div class="clear"></div>
277
- </div> <!-- /GET -->
278
-
279
- <div id="post">
280
- <h3 id="post-info">POST</h3>
281
- <% if req.POST and not req.POST.empty? %>
282
- <table class="req">
283
- <tr>
284
- <th>Variable</th>
285
- <th>Value</th>
286
- </tr>
287
- <% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
288
- <tr>
289
- <td><%=h key %></td>
290
- <td class="code"><div><%=h val.inspect %></div></td>
291
- </tr>
292
- <% } %>
293
- </table>
294
- <% else %>
295
- <p class="no-data">No POST data.</p>
296
- <% end %>
297
- <div class="clear"></div>
298
- </div> <!-- /POST -->
299
-
300
- <div id="cookies">
301
- <h3 id="cookie-info">COOKIES</h3>
302
- <% unless req.cookies.empty? %>
303
- <table class="req">
304
- <tr>
305
- <th>Variable</th>
306
- <th>Value</th>
307
- </tr>
308
- <% req.cookies.each { |key, val| %>
309
- <tr>
310
- <td><%=h key %></td>
311
- <td class="code"><div><%=h val.inspect %></div></td>
312
- </tr>
313
- <% } %>
314
- </table>
315
- <% else %>
316
- <p class="no-data">No cookie data.</p>
317
- <% end %>
318
- <div class="clear"></div>
319
- </div> <!-- /COOKIES -->
320
-
321
- <div id="rack">
322
- <h3 id="env-info">Rack ENV</h3>
323
- <table class="req">
324
- <tr>
325
- <th>Variable</th>
326
- <th>Value</th>
327
- </tr>
328
- <% env.sort_by { |k, v| k.to_s }.each { |key, val| %>
329
- <tr>
330
- <td><%=h key %></td>
331
- <td class="code"><div><%=h val %></div></td>
332
- </tr>
333
- <% } %>
334
- </table>
335
- <div class="clear"></div>
336
- </div> <!-- /RACK ENV -->
337
-
338
- <p id="explanation">You're seeing this error because you have
339
- enabled the <code>show_exceptions</code> setting.</p>
340
- </div> <!-- /WRAP -->
341
- </body>
342
- </html>
343
- HTML
344
- end
345
- end
@@ -1,3 +0,0 @@
1
- module Sinatra
2
- VERSION = '1.4.0-forked'
3
- end
@@ -1,18 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
- require 'sinatra/version'
3
-
4
- Gem::Specification.new 'sinatra', Sinatra::VERSION do |s|
5
- s.description = "Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort."
6
- s.summary = "Classy web-development dressed in a DSL"
7
- s.authors = ["Blake Mizerany", "Ryan Tomayko", "Simon Rozet", "Konstantin Haase"]
8
- s.email = "sinatrarb@googlegroups.com"
9
- s.homepage = "http://www.sinatrarb.com/"
10
- s.files = `git ls-files`.split("\n") - %w[.gitignore .travis.yml]
11
- s.test_files = s.files.select { |p| p =~ /^test\/.*_test.rb/ }
12
- s.extra_rdoc_files = s.files.select { |p| p =~ /^README/ } << 'LICENSE'
13
- s.rdoc_options = %w[--line-numbers --inline-source --title Sinatra --main README.rdoc --encoding=UTF-8]
14
-
15
- s.add_dependency 'rack', '~> 1.4'
16
- s.add_dependency 'rack-protection', '~> 1.3'
17
- s.add_dependency 'tilt', '~> 1.3', '>= 1.3.3'
18
- end
@@ -1,172 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
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('/') { 'Hello World' }
11
- end
12
-
13
- it 'include Rack::Utils' do
14
- assert TestApp.included_modules.include?(Rack::Utils)
15
- end
16
-
17
- it 'processes requests with #call' do
18
- assert TestApp.respond_to?(:call)
19
-
20
- request = Rack::MockRequest.new(TestApp)
21
- response = request.get('/')
22
- assert response.ok?
23
- assert_equal 'Hello World', response.body
24
- end
25
-
26
- class TestApp < Sinatra::Base
27
- get '/state' do
28
- @foo ||= "new"
29
- body = "Foo: #{@foo}"
30
- @foo = 'discard'
31
- body
32
- end
33
- end
34
-
35
- it 'does not maintain state between requests' do
36
- request = Rack::MockRequest.new(TestApp)
37
- 2.times do
38
- response = request.get('/state')
39
- assert response.ok?
40
- assert_equal 'Foo: new', response.body
41
- end
42
- end
43
-
44
- it "passes the subclass to configure blocks" do
45
- ref = nil
46
- TestApp.configure { |app| ref = app }
47
- assert_equal TestApp, ref
48
- end
49
-
50
- it "allows the configure block arg to be omitted and does not change context" do
51
- context = nil
52
- TestApp.configure { context = self }
53
- assert_equal self, context
54
- end
55
- end
56
-
57
- describe "Sinatra::Base#new" do
58
- it 'returns a wrapper' do
59
- assert_equal Sinatra::Wrapper, Sinatra::Base.new.class
60
- end
61
-
62
- it 'implements a nice inspect' do
63
- assert_equal '#<Sinatra::Base app_file=nil>', Sinatra::Base.new.inspect
64
- end
65
-
66
- it 'exposes settings' do
67
- assert_equal Sinatra::Base.settings, Sinatra::Base.new.settings
68
- end
69
-
70
- it 'expses helpers' do
71
- assert_equal 'image/jpeg', Sinatra::Base.new.helpers.mime_type(:jpg)
72
- end
73
- end
74
-
75
- describe "Sinatra::Base as Rack middleware" do
76
- app = lambda { |env|
77
- headers = {'X-Downstream' => 'true'}
78
- headers['X-Route-Missing'] = env['sinatra.route-missing'] || ''
79
- [210, headers, ['Hello from downstream']] }
80
-
81
- class TestMiddleware < Sinatra::Base
82
- end
83
-
84
- it 'creates a middleware that responds to #call with .new' do
85
- middleware = TestMiddleware.new(app)
86
- assert middleware.respond_to?(:call)
87
- end
88
-
89
- it 'exposes the downstream app' do
90
- middleware = TestMiddleware.new!(app)
91
- assert_same app, middleware.app
92
- end
93
-
94
- class TestMiddleware < Sinatra::Base
95
- def route_missing
96
- env['sinatra.route-missing'] = '1'
97
- super
98
- end
99
-
100
- get('/') { 'Hello from middleware' }
101
- end
102
-
103
- middleware = TestMiddleware.new(app)
104
- request = Rack::MockRequest.new(middleware)
105
-
106
- it 'intercepts requests' do
107
- response = request.get('/')
108
- assert response.ok?
109
- assert_equal 'Hello from middleware', response.body
110
- end
111
-
112
- it 'automatically forwards requests downstream when no matching route found' do
113
- response = request.get('/missing')
114
- assert_equal 210, response.status
115
- assert_equal 'Hello from downstream', response.body
116
- end
117
-
118
- it 'calls #route_missing before forwarding downstream' do
119
- response = request.get('/missing')
120
- assert_equal '1', response['X-Route-Missing']
121
- end
122
-
123
- class TestMiddleware < Sinatra::Base
124
- get('/low-level-forward') { app.call(env) }
125
- end
126
-
127
- it 'can call the downstream app directly and return result' do
128
- response = request.get('/low-level-forward')
129
- assert_equal 210, response.status
130
- assert_equal 'true', response['X-Downstream']
131
- assert_equal 'Hello from downstream', response.body
132
- end
133
-
134
- class TestMiddleware < Sinatra::Base
135
- get '/explicit-forward' do
136
- response['X-Middleware'] = 'true'
137
- res = forward
138
- assert_nil res
139
- assert_equal 210, response.status
140
- assert_equal 'true', response['X-Downstream']
141
- assert_equal ['Hello from downstream'], response.body
142
- 'Hello after explicit forward'
143
- end
144
- end
145
-
146
- it 'forwards the request downstream and integrates the response into the current context' do
147
- response = request.get('/explicit-forward')
148
- assert_equal 210, response.status
149
- assert_equal 'true', response['X-Downstream']
150
- assert_equal 'Hello after explicit forward', response.body
151
- assert_equal '28', response['Content-Length']
152
- end
153
-
154
- app_content_length = lambda {|env|
155
- [200, {'Content-Length' => '16'}, 'From downstream!']}
156
-
157
- class TestMiddlewareContentLength < Sinatra::Base
158
- get '/forward' do
159
- res = forward
160
- 'From after explicit forward!'
161
- end
162
- end
163
-
164
- middleware_content_length = TestMiddlewareContentLength.new(app_content_length)
165
- request_content_length = Rack::MockRequest.new(middleware_content_length)
166
-
167
- it "sets content length for last response" do
168
- response = request_content_length.get('/forward')
169
- assert_equal '28', response['Content-Length']
170
- end
171
- end
172
- end