bmizerany-sinatra 0.9.0 → 0.9.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +40 -0
- data/CHANGES +43 -11
- data/README.rdoc +138 -91
- data/Rakefile +7 -1
- data/compat/events_test.rb +10 -7
- data/compat/helper.rb +13 -1
- data/lib/sinatra/base.rb +72 -26
- data/lib/sinatra/compat.rb +142 -44
- data/lib/sinatra/test/bacon.rb +17 -0
- data/lib/sinatra/test/rspec.rb +7 -0
- data/lib/sinatra/test/spec.rb +7 -0
- data/lib/sinatra/test/unit.rb +1 -1
- data/lib/sinatra/test.rb +94 -90
- data/lib/sinatra.rb +5 -0
- data/sinatra.gemspec +7 -3
- data/test/base_test.rb +33 -14
- data/test/builder_test.rb +12 -16
- data/test/erb_test.rb +11 -16
- data/test/filter_test.rb +48 -12
- data/test/haml_test.rb +14 -18
- data/test/helper.rb +25 -0
- data/test/helpers_test.rb +55 -62
- data/test/mapped_error_test.rb +43 -24
- data/test/middleware_test.rb +8 -13
- data/test/options_test.rb +29 -35
- data/test/reload_test.rb +16 -20
- data/test/request_test.rb +12 -5
- data/test/result_test.rb +16 -20
- data/test/routing_test.rb +124 -71
- data/test/sass_test.rb +8 -12
- data/test/sinatra_test.rb +2 -4
- data/test/static_test.rb +16 -19
- data/test/templates_test.rb +23 -19
- metadata +7 -4
data/lib/sinatra/test.rb
CHANGED
@@ -1,110 +1,114 @@
|
|
1
1
|
require 'sinatra/base'
|
2
|
-
require 'test/unit'
|
3
2
|
|
4
|
-
module Sinatra
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
3
|
+
module Sinatra
|
4
|
+
|
5
|
+
module Test
|
6
|
+
include Rack::Utils
|
7
|
+
|
8
|
+
attr_reader :app, :request, :response
|
9
|
+
|
10
|
+
def test_request(verb, path, *args)
|
11
|
+
@app = Sinatra::Application if @app.nil? && defined?(Sinatra::Application)
|
12
|
+
fail "@app not set - cannot make request" if @app.nil?
|
13
|
+
@request = Rack::MockRequest.new(@app)
|
14
|
+
opts, input =
|
15
|
+
case args.size
|
16
|
+
when 2 # input, env
|
17
|
+
input, env = args
|
18
|
+
if input.kind_of?(Hash) # params, env
|
19
|
+
[env, param_string(input)]
|
20
|
+
else
|
21
|
+
[env, input]
|
22
|
+
end
|
23
|
+
when 1 # params
|
24
|
+
if (data = args.first).kind_of?(Hash)
|
25
|
+
env = (data.delete(:env) || {})
|
26
|
+
[env, param_string(data)]
|
27
|
+
else
|
28
|
+
[{}, data]
|
29
|
+
end
|
30
|
+
when 0
|
31
|
+
[{}, '']
|
29
32
|
else
|
30
|
-
|
33
|
+
raise ArgumentError, "zero, one, or two arguments expected"
|
31
34
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
opts = rack_opts(opts)
|
38
|
-
opts[:input] ||= input
|
39
|
-
yield @request if block_given?
|
40
|
-
@response = @request.request(verb, path, opts)
|
41
|
-
end
|
35
|
+
opts = rack_opts(opts)
|
36
|
+
opts[:input] ||= input
|
37
|
+
yield @request if block_given?
|
38
|
+
@response = @request.request(verb, path, opts)
|
39
|
+
end
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
def get(path, *args, &b) ; test_request('GET', path, *args, &b) ; end
|
42
|
+
def head(path, *args, &b) ; test_request('HEAD', path, *args, &b) ; end
|
43
|
+
def post(path, *args, &b) ; test_request('POST', path, *args, &b) ; end
|
44
|
+
def put(path, *args, &b) ; test_request('PUT', path, *args, &b) ; end
|
45
|
+
def delete(path, *args, &b) ; test_request('DELETE', path, *args, &b) ; end
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
def follow!
|
48
|
+
test_request 'GET', @response.location
|
49
|
+
end
|
52
50
|
|
53
|
-
|
54
|
-
@response.
|
55
|
-
end
|
51
|
+
def body ; @response.body ; end
|
52
|
+
def status ; @response.status ; end
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
# Delegate other missing methods to @response.
|
55
|
+
def method_missing(name, *args, &block)
|
56
|
+
if @response && @response.respond_to?(name)
|
57
|
+
@response.send(name, *args, &block)
|
58
|
+
else
|
59
|
+
super
|
60
|
+
end
|
61
|
+
end
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
# Also check @response since we delegate there.
|
64
|
+
def respond_to?(symbol, include_private=false)
|
65
|
+
super || (@response && @response.respond_to?(symbol, include_private))
|
66
|
+
end
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
68
|
+
RACK_OPT_NAMES = {
|
69
|
+
:accept => "HTTP_ACCEPT",
|
70
|
+
:agent => "HTTP_USER_AGENT",
|
71
|
+
:host => "HTTP_HOST",
|
72
|
+
:session => "HTTP_COOKIE",
|
73
|
+
:cookies => "HTTP_COOKIE",
|
74
|
+
:content_type => "CONTENT_TYPE"
|
75
|
+
}
|
76
|
+
|
77
|
+
def rack_opts(opts)
|
78
|
+
opts.inject({}) do |hash,(key,val)|
|
79
|
+
key = RACK_OPT_NAMES[key] || key
|
80
|
+
hash[key] = val
|
81
|
+
hash
|
82
|
+
end
|
79
83
|
end
|
80
|
-
end
|
81
84
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
85
|
+
def env_for(opts={})
|
86
|
+
opts = rack_opts(opts)
|
87
|
+
Rack::MockRequest.env_for(opts)
|
88
|
+
end
|
86
89
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
+
def param_string(hash)
|
91
|
+
hash.map { |pair| pair.map{|v|escape(v)}.join('=') }.join('&')
|
92
|
+
end
|
90
93
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
if defined? Sinatra::Compat
|
95
|
+
# Deprecated. Use: "get" instead of "get_it".
|
96
|
+
%w(get head post put delete).each do |verb|
|
97
|
+
eval <<-RUBY, binding, __FILE__, __LINE__
|
98
|
+
def #{verb}_it(*args, &block)
|
99
|
+
sinatra_warn "The #{verb}_it method is deprecated; use #{verb} instead."
|
100
|
+
test_request('#{verb.upcase}', *args, &block)
|
101
|
+
end
|
102
|
+
RUBY
|
103
|
+
end
|
96
104
|
end
|
105
|
+
end
|
97
106
|
|
98
|
-
|
107
|
+
class TestHarness
|
108
|
+
include Test
|
99
109
|
|
100
|
-
|
101
|
-
|
102
|
-
def method_missing(name, *args, &block)
|
103
|
-
if @response && @response.respond_to?(name)
|
104
|
-
@response.send(name, *args, &block)
|
105
|
-
else
|
106
|
-
super
|
107
|
-
end
|
110
|
+
def initialize(app=nil)
|
111
|
+
@app = app || Sinatra::Application
|
108
112
|
end
|
109
113
|
end
|
110
114
|
end
|
data/lib/sinatra.rb
CHANGED
data/sinatra.gemspec
CHANGED
@@ -3,16 +3,18 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'sinatra'
|
6
|
-
s.version = '0.9.0'
|
7
|
-
s.date = '2009-01-
|
6
|
+
s.version = '0.9.0.2'
|
7
|
+
s.date = '2009-01-18'
|
8
8
|
|
9
9
|
s.description = "Classy web-development dressed in a DSL"
|
10
10
|
s.summary = "Classy web-development dressed in a DSL"
|
11
11
|
|
12
12
|
s.authors = ["Blake Mizerany"]
|
13
|
+
s.email = "sinatrarb@googlegroups.com"
|
13
14
|
|
14
15
|
# = MANIFEST =
|
15
16
|
s.files = %w[
|
17
|
+
AUTHORS
|
16
18
|
CHANGES
|
17
19
|
LICENSE
|
18
20
|
README.rdoc
|
@@ -58,6 +60,7 @@ Gem::Specification.new do |s|
|
|
58
60
|
lib/sinatra/images/500.png
|
59
61
|
lib/sinatra/main.rb
|
60
62
|
lib/sinatra/test.rb
|
63
|
+
lib/sinatra/test/bacon.rb
|
61
64
|
lib/sinatra/test/rspec.rb
|
62
65
|
lib/sinatra/test/spec.rb
|
63
66
|
lib/sinatra/test/unit.rb
|
@@ -68,6 +71,7 @@ Gem::Specification.new do |s|
|
|
68
71
|
test/erb_test.rb
|
69
72
|
test/filter_test.rb
|
70
73
|
test/haml_test.rb
|
74
|
+
test/helper.rb
|
71
75
|
test/helpers_test.rb
|
72
76
|
test/mapped_error_test.rb
|
73
77
|
test/middleware_test.rb
|
@@ -95,7 +99,7 @@ Gem::Specification.new do |s|
|
|
95
99
|
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
|
96
100
|
|
97
101
|
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
98
|
-
s.add_dependency 'rack', '>= 0.9.
|
102
|
+
s.add_dependency 'rack', '>= 0.9.1'
|
99
103
|
|
100
104
|
s.has_rdoc = true
|
101
105
|
s.homepage = "http://sinatra.rubyforge.org"
|
data/test/base_test.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe 'Sinatra::Base' do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
it 'includes Rack::Utils' do
|
9
|
-
Sinatra::Base.
|
5
|
+
assert Sinatra::Base.included_modules.include?(Rack::Utils)
|
10
6
|
end
|
11
7
|
|
12
8
|
it 'can be used as a Rack application' do
|
@@ -15,12 +11,12 @@ describe 'Sinatra::Base' do
|
|
15
11
|
'Hello World'
|
16
12
|
end
|
17
13
|
}
|
18
|
-
@app.
|
14
|
+
assert @app.respond_to?(:call)
|
19
15
|
|
20
16
|
request = Rack::MockRequest.new(@app)
|
21
17
|
response = request.get('/')
|
22
|
-
response.
|
23
|
-
|
18
|
+
assert response.ok?
|
19
|
+
assert_equal 'Hello World', response.body
|
24
20
|
end
|
25
21
|
|
26
22
|
it 'can be used as Rack middleware' do
|
@@ -35,15 +31,38 @@ describe 'Sinatra::Base' do
|
|
35
31
|
end
|
36
32
|
}
|
37
33
|
middleware = mock_middleware.new(app)
|
38
|
-
middleware.app
|
34
|
+
assert_same app, middleware.app
|
39
35
|
|
40
36
|
request = Rack::MockRequest.new(middleware)
|
41
37
|
response = request.get('/')
|
42
|
-
response.
|
43
|
-
|
38
|
+
assert response.ok?
|
39
|
+
assert_equal 'Hello World', response.body
|
44
40
|
|
45
41
|
response = request.get('/goodbye')
|
46
|
-
response.
|
47
|
-
|
42
|
+
assert response.ok?
|
43
|
+
assert_equal 'Goodbye World', response.body
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'can take multiple definitions of a route' do
|
47
|
+
app = mock_app {
|
48
|
+
user_agent(/Foo/)
|
49
|
+
get '/foo' do
|
50
|
+
'foo'
|
51
|
+
end
|
52
|
+
|
53
|
+
get '/foo' do
|
54
|
+
'not foo'
|
55
|
+
end
|
56
|
+
}
|
57
|
+
|
58
|
+
request = Rack::MockRequest.new(app)
|
59
|
+
response = request.get('/foo', 'HTTP_USER_AGENT' => 'Foo')
|
60
|
+
assert response.ok?
|
61
|
+
assert_equal 'foo', response.body
|
62
|
+
|
63
|
+
request = Rack::MockRequest.new(app)
|
64
|
+
response = request.get('/foo')
|
65
|
+
assert response.ok?
|
66
|
+
assert_equal 'not foo', response.body
|
48
67
|
end
|
49
68
|
end
|
data/test/builder_test.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe "Builder Templates" do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
def builder_app(&block)
|
9
5
|
mock_app {
|
10
6
|
set :views, File.dirname(__FILE__) + '/views'
|
@@ -15,8 +11,8 @@ describe "Builder Templates" do
|
|
15
11
|
|
16
12
|
it 'renders inline Builder strings' do
|
17
13
|
builder_app { builder 'xml.instruct!' }
|
18
|
-
|
19
|
-
|
14
|
+
assert ok?
|
15
|
+
assert_equal %{<?xml version="1.0" encoding="UTF-8"?>\n}, body
|
20
16
|
end
|
21
17
|
|
22
18
|
it 'renders inline blocks' do
|
@@ -26,8 +22,8 @@ describe "Builder Templates" do
|
|
26
22
|
xml.couple @name
|
27
23
|
end
|
28
24
|
}
|
29
|
-
|
30
|
-
|
25
|
+
assert ok?
|
26
|
+
assert_equal "<couple>Frank & Mary</couple>\n", body
|
31
27
|
end
|
32
28
|
|
33
29
|
it 'renders .builder files in views path' do
|
@@ -35,8 +31,8 @@ describe "Builder Templates" do
|
|
35
31
|
@name = "Blue"
|
36
32
|
builder :hello
|
37
33
|
}
|
38
|
-
|
39
|
-
|
34
|
+
assert ok?
|
35
|
+
assert_equal %(<exclaim>You're my boy, Blue!</exclaim>\n), body
|
40
36
|
end
|
41
37
|
|
42
38
|
it "renders with inline layouts" do
|
@@ -47,22 +43,22 @@ describe "Builder Templates" do
|
|
47
43
|
get('/') { builder %(xml.em 'Hello World') }
|
48
44
|
}
|
49
45
|
get '/'
|
50
|
-
|
51
|
-
|
46
|
+
assert ok?
|
47
|
+
assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
|
52
48
|
end
|
53
49
|
|
54
50
|
it "renders with file layouts" do
|
55
51
|
builder_app {
|
56
52
|
builder %(xml.em 'Hello World'), :layout => :layout2
|
57
53
|
}
|
58
|
-
|
59
|
-
|
54
|
+
assert ok?
|
55
|
+
assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
|
60
56
|
end
|
61
57
|
|
62
58
|
it "raises error if template not found" do
|
63
59
|
mock_app {
|
64
60
|
get('/') { builder :no_such_template }
|
65
61
|
}
|
66
|
-
|
62
|
+
assert_raise(Errno::ENOENT) { get('/') }
|
67
63
|
end
|
68
64
|
end
|
data/test/erb_test.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe "ERB Templates" do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
def erb_app(&block)
|
9
5
|
mock_app {
|
10
6
|
set :views, File.dirname(__FILE__) + '/views'
|
@@ -15,14 +11,14 @@ describe "ERB Templates" do
|
|
15
11
|
|
16
12
|
it 'renders inline ERB strings' do
|
17
13
|
erb_app { erb '<%= 1 + 1 %>' }
|
18
|
-
|
19
|
-
|
14
|
+
assert ok?
|
15
|
+
assert_equal '2', body
|
20
16
|
end
|
21
17
|
|
22
18
|
it 'renders .erb files in views path' do
|
23
19
|
erb_app { erb :hello }
|
24
|
-
|
25
|
-
|
20
|
+
assert ok?
|
21
|
+
assert_equal "Hello World\n", body
|
26
22
|
end
|
27
23
|
|
28
24
|
it 'takes a :locals option' do
|
@@ -30,8 +26,8 @@ describe "ERB Templates" do
|
|
30
26
|
locals = {:foo => 'Bar'}
|
31
27
|
erb '<%= foo %>', :locals => locals
|
32
28
|
}
|
33
|
-
|
34
|
-
|
29
|
+
assert ok?
|
30
|
+
assert_equal 'Bar', body
|
35
31
|
end
|
36
32
|
|
37
33
|
it "renders with inline layouts" do
|
@@ -40,16 +36,15 @@ describe "ERB Templates" do
|
|
40
36
|
get('/') { erb 'Sparta' }
|
41
37
|
}
|
42
38
|
get '/'
|
43
|
-
|
44
|
-
|
39
|
+
assert ok?
|
40
|
+
assert_equal 'THIS. IS. SPARTA!', body
|
45
41
|
end
|
46
42
|
|
47
43
|
it "renders with file layouts" do
|
48
44
|
erb_app {
|
49
45
|
erb 'Hello World', :layout => :layout2
|
50
46
|
}
|
51
|
-
|
52
|
-
|
47
|
+
assert ok?
|
48
|
+
assert_equal "ERB Layout!\nHello World\n", body
|
53
49
|
end
|
54
|
-
|
55
50
|
end
|
data/test/filter_test.rb
CHANGED
@@ -1,28 +1,24 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe "Filters" do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
it "executes filters in the order defined" do
|
9
5
|
count = 0
|
10
6
|
mock_app do
|
11
7
|
get('/') { 'Hello World' }
|
12
8
|
before {
|
13
|
-
|
9
|
+
assert_equal 0, count
|
14
10
|
count = 1
|
15
11
|
}
|
16
12
|
before {
|
17
|
-
|
13
|
+
assert_equal 1, count
|
18
14
|
count = 2
|
19
15
|
}
|
20
16
|
end
|
21
17
|
|
22
18
|
get '/'
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
assert ok?
|
20
|
+
assert_equal 2, count
|
21
|
+
assert_equal 'Hello World', body
|
26
22
|
end
|
27
23
|
|
28
24
|
it "allows filters to modify the request" do
|
@@ -33,7 +29,47 @@ describe "Filters" do
|
|
33
29
|
}
|
34
30
|
|
35
31
|
get '/foo'
|
36
|
-
|
37
|
-
|
32
|
+
assert ok?
|
33
|
+
assert_equal 'bar', body
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can modify instance variables available to routes" do
|
37
|
+
mock_app {
|
38
|
+
before { @foo = 'bar' }
|
39
|
+
get('/foo') { @foo }
|
40
|
+
}
|
41
|
+
|
42
|
+
get '/foo'
|
43
|
+
assert ok?
|
44
|
+
assert_equal 'bar', body
|
45
|
+
end
|
46
|
+
|
47
|
+
it "allows redirects in filters" do
|
48
|
+
mock_app {
|
49
|
+
before { redirect '/bar' }
|
50
|
+
get('/foo') do
|
51
|
+
fail 'before block should have halted processing'
|
52
|
+
'ORLY?!'
|
53
|
+
end
|
54
|
+
}
|
55
|
+
|
56
|
+
get '/foo'
|
57
|
+
assert redirect?
|
58
|
+
assert_equal '/bar', response['Location']
|
59
|
+
assert_equal '', body
|
60
|
+
end
|
61
|
+
|
62
|
+
it "does not modify the response with its return value" do
|
63
|
+
mock_app {
|
64
|
+
before { 'Hello World!' }
|
65
|
+
get '/foo' do
|
66
|
+
assert_equal [], response.body
|
67
|
+
'cool'
|
68
|
+
end
|
69
|
+
}
|
70
|
+
|
71
|
+
get '/foo'
|
72
|
+
assert ok?
|
73
|
+
assert_equal 'cool', body
|
38
74
|
end
|
39
75
|
end
|
data/test/haml_test.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe "HAML Templates" do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
def haml_app(&block)
|
9
5
|
mock_app {
|
10
6
|
set :views, File.dirname(__FILE__) + '/views'
|
@@ -15,14 +11,14 @@ describe "HAML Templates" do
|
|
15
11
|
|
16
12
|
it 'renders inline HAML strings' do
|
17
13
|
haml_app { haml '%h1 Hiya' }
|
18
|
-
|
19
|
-
|
14
|
+
assert ok?
|
15
|
+
assert_equal "<h1>Hiya</h1>\n", body
|
20
16
|
end
|
21
17
|
|
22
18
|
it 'renders .haml files in views path' do
|
23
19
|
haml_app { haml :hello }
|
24
|
-
|
25
|
-
|
20
|
+
assert ok?
|
21
|
+
assert_equal "<h1>Hello From Haml</h1>\n", body
|
26
22
|
end
|
27
23
|
|
28
24
|
it "renders with inline layouts" do
|
@@ -31,31 +27,31 @@ describe "HAML Templates" do
|
|
31
27
|
get('/') { haml '%em Sparta' }
|
32
28
|
}
|
33
29
|
get '/'
|
34
|
-
|
35
|
-
|
30
|
+
assert ok?
|
31
|
+
assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n", body
|
36
32
|
end
|
37
33
|
|
38
34
|
it "renders with file layouts" do
|
39
35
|
haml_app {
|
40
36
|
haml 'Hello World', :layout => :layout2
|
41
37
|
}
|
42
|
-
|
43
|
-
|
38
|
+
assert ok?
|
39
|
+
assert_equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n", body
|
44
40
|
end
|
45
41
|
|
46
42
|
it "raises error if template not found" do
|
47
43
|
mock_app {
|
48
44
|
get('/') { haml :no_such_template }
|
49
45
|
}
|
50
|
-
|
46
|
+
assert_raise(Errno::ENOENT) { get('/') }
|
51
47
|
end
|
52
48
|
|
53
49
|
it "passes HAML options to the Haml engine" do
|
54
50
|
haml_app {
|
55
51
|
haml "!!!\n%h1 Hello World", :options => {:format => :html5}
|
56
52
|
}
|
57
|
-
|
58
|
-
|
53
|
+
assert ok?
|
54
|
+
assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
|
59
55
|
end
|
60
56
|
|
61
57
|
it "passes default HAML options to the Haml engine" do
|
@@ -66,7 +62,7 @@ describe "HAML Templates" do
|
|
66
62
|
end
|
67
63
|
}
|
68
64
|
get '/'
|
69
|
-
|
70
|
-
|
65
|
+
assert ok?
|
66
|
+
assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
|
71
67
|
end
|
72
68
|
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
begin
|
2
|
+
require 'test/spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'test/spec'
|
6
|
+
end
|
7
|
+
|
8
|
+
$:.unshift File.dirname(File.dirname(__FILE__)) + '/lib'
|
9
|
+
require 'sinatra/base'
|
10
|
+
require 'sinatra/test'
|
11
|
+
require 'sinatra/test/spec'
|
12
|
+
|
13
|
+
module Sinatra::Test
|
14
|
+
# Sets up a Sinatra::Base subclass defined with the block
|
15
|
+
# given. Used in setup or individual spec methods to establish
|
16
|
+
# the application.
|
17
|
+
def mock_app(base=Sinatra::Base, &block)
|
18
|
+
@app = Sinatra.new(base, &block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Sinatra::Base
|
23
|
+
# Allow assertions in request context
|
24
|
+
include Test::Unit::Assertions
|
25
|
+
end
|