sinatra 0.1.7 → 0.2.0
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.
- data/CHANGELOG +1 -8
- data/Manifest +42 -49
- data/README.rdoc +430 -0
- data/Rakefile +22 -28
- data/images/404.png +0 -0
- data/images/500.png +0 -0
- data/index.html +9 -0
- data/lib/sinatra.rb +1144 -46
- data/lib/sinatra/test/methods.rb +56 -0
- data/lib/sinatra/test/spec.rb +10 -0
- data/lib/sinatra/test/unit.rb +13 -0
- data/sinatra.gemspec +44 -40
- data/test/app_test.rb +150 -0
- data/test/application_test.rb +175 -0
- data/test/builder_test.rb +101 -0
- data/test/custom_error_test.rb +67 -0
- data/test/diddy_test.rb +41 -0
- data/test/erb_test.rb +116 -0
- data/test/event_context_test.rb +15 -0
- data/test/events_test.rb +50 -0
- data/test/haml_test.rb +181 -0
- data/test/helper.rb +3 -16
- data/test/mapped_error_test.rb +61 -0
- data/test/public/foo.xml +1 -0
- data/test/rest_test.rb +16 -0
- data/test/sass_test.rb +57 -0
- data/test/sessions_test.rb +40 -0
- data/test/streaming_test.rb +112 -0
- data/test/sym_params_test.rb +19 -0
- data/test/template_test.rb +30 -0
- data/test/use_in_file_templates_test.rb +48 -0
- data/test/views/foo.builder +1 -0
- data/test/views/foo.erb +1 -0
- data/test/views/foo.haml +1 -0
- data/test/views/foo.sass +2 -0
- data/test/views/foo_layout.erb +2 -0
- data/test/views/foo_layout.haml +2 -0
- data/test/views/layout_test/foo.builder +1 -0
- data/test/views/layout_test/foo.erb +1 -0
- data/test/views/layout_test/foo.haml +1 -0
- data/test/views/layout_test/foo.sass +2 -0
- data/test/views/layout_test/layout.builder +3 -0
- data/test/views/layout_test/layout.erb +1 -0
- data/test/views/layout_test/layout.haml +1 -0
- data/test/views/layout_test/layout.sass +2 -0
- data/test/views/no_layout/no_layout.builder +1 -0
- data/test/views/no_layout/no_layout.haml +1 -0
- metadata +122 -98
- data/LICENSE +0 -22
- data/README +0 -100
- data/RakeFile +0 -35
- data/examples/hello/hello.rb +0 -28
- data/examples/hello/views/hello.erb +0 -1
- data/examples/todo/todo.rb +0 -38
- data/files/default_index.erb +0 -42
- data/files/error.erb +0 -9
- data/files/logo.png +0 -0
- data/files/not_found.erb +0 -52
- data/lib/sinatra/context.rb +0 -88
- data/lib/sinatra/context/renderer.rb +0 -75
- data/lib/sinatra/core_ext/array.rb +0 -5
- data/lib/sinatra/core_ext/class.rb +0 -49
- data/lib/sinatra/core_ext/hash.rb +0 -7
- data/lib/sinatra/core_ext/kernel.rb +0 -16
- data/lib/sinatra/core_ext/metaid.rb +0 -18
- data/lib/sinatra/core_ext/module.rb +0 -11
- data/lib/sinatra/core_ext/symbol.rb +0 -5
- data/lib/sinatra/dispatcher.rb +0 -27
- data/lib/sinatra/dsl.rb +0 -176
- data/lib/sinatra/environment.rb +0 -15
- data/lib/sinatra/event.rb +0 -238
- data/lib/sinatra/irb.rb +0 -56
- data/lib/sinatra/loader.rb +0 -31
- data/lib/sinatra/logger.rb +0 -22
- data/lib/sinatra/options.rb +0 -49
- data/lib/sinatra/rack_ext/request.rb +0 -15
- data/lib/sinatra/route.rb +0 -65
- data/lib/sinatra/server.rb +0 -57
- data/lib/sinatra/sessions.rb +0 -21
- data/lib/sinatra/test_methods.rb +0 -55
- data/site/index.htm +0 -104
- data/site/index.html +0 -104
- data/site/logo.png +0 -0
- data/test/sinatra/dispatcher_test.rb +0 -91
- data/test/sinatra/event_test.rb +0 -46
- data/test/sinatra/renderer_test.rb +0 -47
- data/test/sinatra/request_test.rb +0 -21
- data/test/sinatra/route_test.rb +0 -21
- data/test/sinatra/static_files/foo.txt +0 -1
- data/test/sinatra/static_files_test.rb +0 -48
- data/test/sinatra/url_test.rb +0 -18
- data/vendor/erb/init.rb +0 -3
- data/vendor/erb/lib/erb.rb +0 -41
- data/vendor/haml/init.rb +0 -3
- data/vendor/haml/lib/haml.rb +0 -41
@@ -0,0 +1,56 @@
|
|
1
|
+
class Rack::MockRequest
|
2
|
+
class << self
|
3
|
+
alias :env_for_without_env :env_for
|
4
|
+
def env_for(uri = "", opts = {})
|
5
|
+
env = { 'HTTP_USER_AGENT' => opts.delete(:agent) }
|
6
|
+
env_for_without_env(uri, opts).merge(env)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Sinatra
|
12
|
+
|
13
|
+
module Test
|
14
|
+
|
15
|
+
module Methods
|
16
|
+
|
17
|
+
def easy_env_map
|
18
|
+
{
|
19
|
+
:accept => 'HTTP_ACCEPT',
|
20
|
+
:agent => 'HTTP_AGENT',
|
21
|
+
:host => 'HTTP_POST'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def map_easys(params)
|
26
|
+
easy_env_map.inject(params.dup) do |m, (from, to)|
|
27
|
+
m[to] = m.delete(from) if m.has_key?(from); m
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
%w(get head post put delete).each do |m|
|
32
|
+
define_method("#{m}_it") do |path, *args|
|
33
|
+
request = Rack::MockRequest.new(Sinatra.build_application)
|
34
|
+
env, input = if args.size == 2
|
35
|
+
[args.last, args.first]
|
36
|
+
elsif args.size == 1
|
37
|
+
data = args.first
|
38
|
+
data.is_a?(Hash) ? [data.delete(:env), data.to_params] : [nil, data]
|
39
|
+
end
|
40
|
+
@response = request.request(m.upcase, path, {:input => input}.merge(env || {}))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def follow!
|
45
|
+
get_it(@response.location)
|
46
|
+
end
|
47
|
+
|
48
|
+
def method_missing(name, *args)
|
49
|
+
@response.send(name, *args)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/methods'
|
3
|
+
|
4
|
+
Test::Unit::TestCase.send(:include, Sinatra::Test::Methods)
|
5
|
+
|
6
|
+
Sinatra::Application.default_options.merge!(
|
7
|
+
:env => :test,
|
8
|
+
:run => false,
|
9
|
+
:raise_errors => true,
|
10
|
+
:logging => false
|
11
|
+
)
|
12
|
+
|
13
|
+
Sinatra.application.options = nil
|
data/sinatra.gemspec
CHANGED
@@ -1,59 +1,63 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Sinatra-0.
|
2
|
+
# Gem::Specification for Sinatra-0.2.0
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{sinatra}
|
7
|
-
s.version = "0.
|
8
|
-
|
9
|
-
s.
|
10
|
-
|
11
|
-
s.
|
12
|
-
s.rubyforge_project = %q{sinatra}
|
13
|
-
s.description = %q{Sinatra is a classy web-framework dressed in a DSL}
|
14
|
-
s.has_rdoc = true
|
7
|
+
s.version = "0.2.0"
|
8
|
+
|
9
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
15
12
|
s.authors = ["Blake Mizerany"]
|
16
|
-
s.
|
17
|
-
s.
|
13
|
+
s.date = %q{2008-04-11}
|
14
|
+
s.description = %q{Classy web-development dressed in a DSL}
|
15
|
+
s.email = %q{}
|
16
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/sinatra/test/methods.rb", "lib/sinatra/test/spec.rb", "lib/sinatra/test/unit.rb", "lib/sinatra.rb", "README.rdoc"]
|
17
|
+
s.files = ["CHANGELOG", "images/404.png", "images/500.png", "index.html", "lib/sinatra/test/methods.rb", "lib/sinatra/test/spec.rb", "lib/sinatra/test/unit.rb", "lib/sinatra.rb", "README.rdoc", "test/app_test.rb", "test/application_test.rb", "test/builder_test.rb", "test/custom_error_test.rb", "test/diddy_test.rb", "test/erb_test.rb", "test/event_context_test.rb", "test/events_test.rb", "test/haml_test.rb", "test/helper.rb", "test/mapped_error_test.rb", "test/public/foo.xml", "test/rest_test.rb", "test/sass_test.rb", "test/sessions_test.rb", "test/streaming_test.rb", "test/sym_params_test.rb", "test/template_test.rb", "test/use_in_file_templates_test.rb", "test/views/foo.builder", "test/views/foo.erb", "test/views/foo.haml", "test/views/foo.sass", "test/views/foo_layout.erb", "test/views/foo_layout.haml", "test/views/layout_test/foo.builder", "test/views/layout_test/foo.erb", "test/views/layout_test/foo.haml", "test/views/layout_test/foo.sass", "test/views/layout_test/layout.builder", "test/views/layout_test/layout.erb", "test/views/layout_test/layout.haml", "test/views/layout_test/layout.sass", "test/views/no_layout/no_layout.builder", "test/views/no_layout/no_layout.haml", "Manifest", "sinatra.gemspec", "Rakefile"]
|
18
|
+
s.has_rdoc = true
|
19
|
+
s.homepage = %q{http://www.sinatrarb.com}
|
20
|
+
s.post_install_message = %q{*** Be sure to checkout the site for helpful tips! sinatrarb.com ***}
|
21
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sinatra", "--main", "README.rdoc"]
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
s.rubyforge_project = %q{sinatra}
|
24
|
+
s.rubygems_version = %q{1.0.1}
|
25
|
+
s.summary = %q{Classy web-development dressed in a DSL}
|
26
|
+
s.test_files = ["test/app_test.rb", "test/application_test.rb", "test/builder_test.rb", "test/custom_error_test.rb", "test/diddy_test.rb", "test/erb_test.rb", "test/event_context_test.rb", "test/events_test.rb", "test/haml_test.rb", "test/mapped_error_test.rb", "test/rest_test.rb", "test/sass_test.rb", "test/sessions_test.rb", "test/streaming_test.rb", "test/sym_params_test.rb", "test/template_test.rb", "test/use_in_file_templates_test.rb"]
|
27
|
+
|
18
28
|
s.add_dependency(%q<mongrel>, [">= 1.0.1"])
|
19
|
-
s.add_dependency(%q<rack>, [">= 0.
|
29
|
+
s.add_dependency(%q<rack>, [">= 0", "= 0.3.0"])
|
20
30
|
end
|
21
31
|
|
22
32
|
|
23
33
|
# # Original Rakefile source (requires the Echoe gem):
|
24
34
|
#
|
35
|
+
# require 'rubygems'
|
25
36
|
# require 'rake/testtask'
|
26
|
-
# require '
|
27
|
-
#
|
28
|
-
# Version = '0.1.0'
|
37
|
+
# require 'rake/rdoctask'
|
38
|
+
# require 'echoe'
|
29
39
|
#
|
30
|
-
#
|
31
|
-
# require 'rubygems'
|
32
|
-
# gem 'echoe'
|
33
|
-
# ENV['RUBY_FLAGS'] = ""
|
34
|
-
# require 'echoe'
|
40
|
+
# task :default => :test
|
35
41
|
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
# p.author = 'Blake Mizerany'
|
43
|
-
# p.email = "blake.mizerany@gmail.com"
|
44
|
-
# p.test_pattern = 'test/**/*_test.rb'
|
45
|
-
# p.include_rakefile = true
|
46
|
-
# p.rdoc_pattern = ['README', 'LICENSE'] + Dir.glob('lib/**/*.rb') + Dir.glob('vendor/**/*.rb')
|
47
|
-
# p.docs_host = "bmizerany@rubyforge.org:/var/www/gforge-projects/"
|
48
|
-
# end
|
42
|
+
# Rake::RDocTask.new do |rd|
|
43
|
+
# rd.main = "README.rdoc"
|
44
|
+
# rd.rdoc_files += ["README.rdoc"]
|
45
|
+
# rd.rdoc_files += Dir.glob("lib/**/*.rb")
|
46
|
+
# rd.rdoc_dir = 'doc'
|
47
|
+
# end
|
49
48
|
#
|
50
|
-
#
|
49
|
+
# Rake::TestTask.new do |t|
|
50
|
+
# ENV['SINATRA_ENV'] = 'test'
|
51
|
+
# t.pattern = File.dirname(__FILE__) + "/test/*_test.rb"
|
51
52
|
# end
|
52
53
|
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
54
|
+
# Echoe.new("sinatra") do |p|
|
55
|
+
# p.author = "Blake Mizerany"
|
56
|
+
# p.summary = "Classy web-development dressed in a DSL"
|
57
|
+
# p.url = "http://www.sinatrarb.com"
|
58
|
+
# p.docs_host = "sinatrarb.com:/var/www/blakemizerany.com/public/docs/"
|
59
|
+
# p.dependencies = ["mongrel >=1.0.1", "rack >= 0.3.0"]
|
60
|
+
# p.install_message = "*** Be sure to checkout the site for helpful tips! sinatrarb.com ***"
|
61
|
+
# p.include_rakefile = true
|
59
62
|
# end
|
63
|
+
#
|
data/test/app_test.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
context "Sinatra" do
|
4
|
+
|
5
|
+
setup do
|
6
|
+
Sinatra.application = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
specify "should handle result of nil" do
|
10
|
+
get '/' do
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
|
14
|
+
get_it '/'
|
15
|
+
should.be.ok
|
16
|
+
body.should == ''
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "handles events" do
|
20
|
+
get '/:name' do
|
21
|
+
'Hello ' + params["name"]
|
22
|
+
end
|
23
|
+
|
24
|
+
get_it '/Blake'
|
25
|
+
|
26
|
+
should.be.ok
|
27
|
+
body.should.equal 'Hello Blake'
|
28
|
+
end
|
29
|
+
|
30
|
+
specify "follows redirects" do
|
31
|
+
get '/' do
|
32
|
+
redirect '/blake'
|
33
|
+
end
|
34
|
+
|
35
|
+
get '/blake' do
|
36
|
+
'Mizerany'
|
37
|
+
end
|
38
|
+
|
39
|
+
get_it '/'
|
40
|
+
should.be.redirection
|
41
|
+
body.should.equal ''
|
42
|
+
|
43
|
+
follow!
|
44
|
+
should.be.ok
|
45
|
+
body.should.equal 'Mizerany'
|
46
|
+
end
|
47
|
+
|
48
|
+
specify "renders a body with a redirect" do
|
49
|
+
Sinatra::EventContext.any_instance.expects(:foo).returns('blah')
|
50
|
+
get "/" do
|
51
|
+
redirect 'foo', :foo
|
52
|
+
end
|
53
|
+
get_it '/'
|
54
|
+
should.be.redirection
|
55
|
+
headers['Location'].should.equal 'foo'
|
56
|
+
body.should.equal 'blah'
|
57
|
+
end
|
58
|
+
|
59
|
+
specify "body sets content and ends event" do
|
60
|
+
|
61
|
+
Sinatra::EventContext.any_instance.expects(:foo).never
|
62
|
+
|
63
|
+
get '/set_body' do
|
64
|
+
stop 'Hello!'
|
65
|
+
stop 'World!'
|
66
|
+
foo
|
67
|
+
end
|
68
|
+
|
69
|
+
get_it '/set_body'
|
70
|
+
|
71
|
+
should.be.ok
|
72
|
+
body.should.equal 'Hello!'
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
specify "should set status then call helper with a var" do
|
77
|
+
Sinatra::EventContext.any_instance.expects(:foo).once.with(1).returns('bah!')
|
78
|
+
|
79
|
+
get '/set_body' do
|
80
|
+
stop [404, [:foo, 1]]
|
81
|
+
end
|
82
|
+
|
83
|
+
get_it '/set_body'
|
84
|
+
|
85
|
+
should.be.not_found
|
86
|
+
body.should.equal 'bah!'
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
specify "delegates HEAD requests to GET handlers" do
|
91
|
+
get '/invisible' do
|
92
|
+
"I am invisible to the world"
|
93
|
+
end
|
94
|
+
|
95
|
+
head_it '/invisible'
|
96
|
+
should.be.ok
|
97
|
+
body.should.not.equal "I am invisible to the world"
|
98
|
+
body.should.equal ''
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
specify "put'n with POST" do
|
103
|
+
put '/' do
|
104
|
+
'puted'
|
105
|
+
end
|
106
|
+
post_it '/', :_method => 'PUT'
|
107
|
+
assert_equal 'puted', body
|
108
|
+
end
|
109
|
+
|
110
|
+
specify "put'n wth PUT" do
|
111
|
+
put '/' do
|
112
|
+
'puted'
|
113
|
+
end
|
114
|
+
put_it '/'
|
115
|
+
assert_equal 'puted', body
|
116
|
+
end
|
117
|
+
|
118
|
+
# Some Ajax libraries downcase the _method parameter value. Make
|
119
|
+
# sure we can handle that.
|
120
|
+
specify "put'n with POST and lowercase _method param" do
|
121
|
+
put '/' do
|
122
|
+
'puted'
|
123
|
+
end
|
124
|
+
post_it '/', :_method => 'put'
|
125
|
+
body.should.equal 'puted'
|
126
|
+
end
|
127
|
+
|
128
|
+
# Ignore any _method parameters specified in GET requests or on the query string in POST requests.
|
129
|
+
specify "not put'n with GET" do
|
130
|
+
get '/' do
|
131
|
+
'getted'
|
132
|
+
end
|
133
|
+
get_it '/', :_method => 'put'
|
134
|
+
should.be.ok
|
135
|
+
body.should.equal 'getted'
|
136
|
+
end
|
137
|
+
|
138
|
+
specify "_method query string parameter ignored on POST" do
|
139
|
+
post '/' do
|
140
|
+
'posted'
|
141
|
+
end
|
142
|
+
put '/' do
|
143
|
+
'booo'
|
144
|
+
end
|
145
|
+
post_it "/?_method=PUT"
|
146
|
+
should.be.ok
|
147
|
+
body.should.equal 'posted'
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
class TesterWithEach
|
6
|
+
def each
|
7
|
+
yield 'foo'
|
8
|
+
yield 'bar'
|
9
|
+
yield 'baz'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "Looking up a request" do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
Sinatra.application = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "returns what's at the end" do
|
20
|
+
block = Proc.new { 'Hello' }
|
21
|
+
get '/', &block
|
22
|
+
|
23
|
+
result = Sinatra.application.lookup(
|
24
|
+
Rack::Request.new(
|
25
|
+
'REQUEST_METHOD' => 'GET',
|
26
|
+
'PATH_INFO' => '/'
|
27
|
+
)
|
28
|
+
)
|
29
|
+
|
30
|
+
result.should.not.be.nil
|
31
|
+
result.block.should.be block
|
32
|
+
end
|
33
|
+
|
34
|
+
specify "takes params in path" do
|
35
|
+
block = Proc.new { 'Hello' }
|
36
|
+
get '/:foo', &block
|
37
|
+
|
38
|
+
result = Sinatra.application.lookup(
|
39
|
+
Rack::Request.new(
|
40
|
+
'REQUEST_METHOD' => 'GET',
|
41
|
+
'PATH_INFO' => '/bar'
|
42
|
+
)
|
43
|
+
)
|
44
|
+
|
45
|
+
result.should.not.be.nil
|
46
|
+
result.block.should.be block
|
47
|
+
result.params.should.equal "foo" => 'bar'
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
context "An app returns" do
|
53
|
+
|
54
|
+
setup do
|
55
|
+
Sinatra.application = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
specify "404 if no events found" do
|
59
|
+
request = Rack::MockRequest.new(@app)
|
60
|
+
get_it '/'
|
61
|
+
should.be.not_found
|
62
|
+
body.should.equal '<h1>Not Found</h1>'
|
63
|
+
end
|
64
|
+
|
65
|
+
specify "200 if success" do
|
66
|
+
get '/' do
|
67
|
+
'Hello World'
|
68
|
+
end
|
69
|
+
get_it '/'
|
70
|
+
should.be.ok
|
71
|
+
body.should.equal 'Hello World'
|
72
|
+
end
|
73
|
+
|
74
|
+
specify "an objects result from each if it has it" do
|
75
|
+
|
76
|
+
get '/' do
|
77
|
+
TesterWithEach.new
|
78
|
+
end
|
79
|
+
|
80
|
+
get_it '/'
|
81
|
+
should.be.ok
|
82
|
+
body.should.equal 'foobarbaz'
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
specify "the body set if set before the last" do
|
87
|
+
|
88
|
+
get '/' do
|
89
|
+
body 'Blake'
|
90
|
+
'Mizerany'
|
91
|
+
end
|
92
|
+
|
93
|
+
get_it '/'
|
94
|
+
should.be.ok
|
95
|
+
body.should.equal 'Blake'
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
context "Events in an app" do
|
102
|
+
|
103
|
+
setup do
|
104
|
+
Sinatra.application = nil
|
105
|
+
end
|
106
|
+
|
107
|
+
specify "evaluate in a clean context" do
|
108
|
+
helpers do
|
109
|
+
def foo
|
110
|
+
'foo'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
get '/foo' do
|
115
|
+
foo
|
116
|
+
end
|
117
|
+
|
118
|
+
get_it '/foo'
|
119
|
+
should.be.ok
|
120
|
+
body.should.equal 'foo'
|
121
|
+
end
|
122
|
+
|
123
|
+
specify "get access to request, response, and params" do
|
124
|
+
get '/:foo' do
|
125
|
+
params["foo"] + params["bar"]
|
126
|
+
end
|
127
|
+
|
128
|
+
get_it '/foo?bar=baz'
|
129
|
+
should.be.ok
|
130
|
+
body.should.equal 'foobaz'
|
131
|
+
end
|
132
|
+
|
133
|
+
specify "can filters by agent" do
|
134
|
+
|
135
|
+
get '/', :agent => /Windows/ do
|
136
|
+
request.env['HTTP_USER_AGENT']
|
137
|
+
end
|
138
|
+
|
139
|
+
get_it '/', :env => { :agent => 'Windows' }
|
140
|
+
should.be.ok
|
141
|
+
body.should.equal 'Windows'
|
142
|
+
|
143
|
+
get_it '/', :agent => 'Mac'
|
144
|
+
should.not.be.ok
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
specify "can filters by agent" do
|
149
|
+
|
150
|
+
get '/', :agent => /Windows (NT)/ do
|
151
|
+
params[:agent].first
|
152
|
+
end
|
153
|
+
|
154
|
+
get_it '/', :env => { :agent => 'Windows NT' }
|
155
|
+
|
156
|
+
body.should.equal 'NT'
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
specify "can deal with spaces in paths" do
|
161
|
+
|
162
|
+
path = '/path with spaces'
|
163
|
+
|
164
|
+
get path do
|
165
|
+
"Look ma, a path with spaces!"
|
166
|
+
end
|
167
|
+
|
168
|
+
get_it URI.encode(path)
|
169
|
+
|
170
|
+
body.should.equal "Look ma, a path with spaces!"
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
|