2011-05-01 07:51:11 -04:00
|
|
|
# Tests to check if all the README examples work.
|
2011-05-11 03:44:02 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2011-05-01 07:51:11 -04:00
|
|
|
|
2015-01-10 14:30:47 -05:00
|
|
|
class ReadmeTest < Minitest::Test
|
2011-05-02 04:31:22 -04:00
|
|
|
example do
|
|
|
|
mock_app { get('/') { 'Hello world!' } }
|
|
|
|
get '/'
|
|
|
|
assert_body 'Hello world!'
|
2011-05-01 07:51:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
section "Routes" do
|
|
|
|
example do
|
|
|
|
mock_app do
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/') { ".. show something .." }
|
2011-05-01 07:51:11 -04:00
|
|
|
|
2012-05-21 17:21:59 -04:00
|
|
|
post('/') { ".. create something .." }
|
2011-05-01 07:51:11 -04:00
|
|
|
|
2012-05-21 17:21:59 -04:00
|
|
|
put('/') { ".. replace something .." }
|
2011-05-01 07:51:11 -04:00
|
|
|
|
2012-05-21 17:21:59 -04:00
|
|
|
patch('/') { ".. modify something .." }
|
2011-05-01 07:51:11 -04:00
|
|
|
|
2012-05-21 17:21:59 -04:00
|
|
|
delete('/') { ".. annihilate something .." }
|
2011-05-01 07:51:11 -04:00
|
|
|
|
2012-05-21 17:21:59 -04:00
|
|
|
options('/') { ".. appease something .." }
|
2013-03-09 12:09:56 -05:00
|
|
|
|
|
|
|
link('/') { ".. affiliate something .." }
|
|
|
|
|
|
|
|
unlink('/') { ".. separate something .." }
|
2011-05-01 07:51:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
get '/'
|
|
|
|
assert_body '.. show something ..'
|
|
|
|
|
|
|
|
post '/'
|
|
|
|
assert_body '.. create something ..'
|
|
|
|
|
|
|
|
put '/'
|
|
|
|
assert_body '.. replace something ..'
|
|
|
|
|
|
|
|
patch '/'
|
|
|
|
assert_body '.. modify something ..'
|
|
|
|
|
|
|
|
delete '/'
|
|
|
|
assert_body '.. annihilate something ..'
|
|
|
|
|
|
|
|
options '/'
|
|
|
|
assert_body '.. appease something ..'
|
2013-03-09 12:09:56 -05:00
|
|
|
|
|
|
|
link '/'
|
|
|
|
assert_body '.. affiliate something ..'
|
|
|
|
|
|
|
|
unlink '/'
|
|
|
|
assert_body '.. separate something ..'
|
2011-05-01 07:51:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
example do
|
|
|
|
mock_app do
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/hello/:name') do
|
2011-05-01 07:51:11 -04:00
|
|
|
# matches "GET /hello/foo" and "GET /hello/bar"
|
|
|
|
# params[:name] is 'foo' or 'bar'
|
|
|
|
"Hello #{params[:name]}!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/hello/foo'
|
|
|
|
assert_body 'Hello foo!'
|
|
|
|
|
|
|
|
get '/hello/bar'
|
|
|
|
assert_body 'Hello bar!'
|
|
|
|
end
|
|
|
|
|
|
|
|
example do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app { get('/hello/:name') { |n| "Hello #{n}!" } }
|
2011-05-01 07:51:11 -04:00
|
|
|
|
|
|
|
get '/hello/foo'
|
|
|
|
assert_body 'Hello foo!'
|
|
|
|
|
|
|
|
get '/hello/bar'
|
|
|
|
assert_body 'Hello bar!'
|
|
|
|
end
|
|
|
|
|
|
|
|
example do
|
|
|
|
mock_app do
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/say/*/to/*') do
|
2011-05-01 07:51:11 -04:00
|
|
|
# matches /say/hello/to/world
|
|
|
|
params[:splat].inspect # => ["hello", "world"]
|
|
|
|
end
|
|
|
|
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/download/*.*') do
|
2011-05-01 07:51:11 -04:00
|
|
|
# matches /download/path/to/file.xml
|
|
|
|
params[:splat].inspect # => ["path/to/file", "xml"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
get "/say/hello/to/world"
|
|
|
|
assert_body '["hello", "world"]'
|
|
|
|
|
|
|
|
get "/download/path/to/file.xml"
|
|
|
|
assert_body '["path/to/file", "xml"]'
|
|
|
|
end
|
|
|
|
|
|
|
|
example do
|
|
|
|
mock_app do
|
2012-05-21 17:21:59 -04:00
|
|
|
get(%r{/hello/([\w]+)}) {
|
2011-05-01 07:51:11 -04:00
|
|
|
"Hello, #{params[:captures].first}!"
|
2012-05-21 17:21:59 -04:00
|
|
|
}
|
2011-05-01 07:51:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
get '/hello/foo'
|
|
|
|
assert_body 'Hello, foo!'
|
|
|
|
|
|
|
|
get '/hello/bar'
|
|
|
|
assert_body 'Hello, bar!'
|
|
|
|
end
|
|
|
|
|
|
|
|
example do
|
|
|
|
mock_app do
|
2012-05-21 17:21:59 -04:00
|
|
|
get( %r{/hello/([\w]+)}) { |c|
|
2011-05-01 07:51:11 -04:00
|
|
|
"Hello, #{c}!"
|
2012-05-21 17:21:59 -04:00
|
|
|
}
|
2011-05-01 07:51:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
get '/hello/foo'
|
|
|
|
assert_body 'Hello, foo!'
|
|
|
|
|
|
|
|
get '/hello/bar'
|
|
|
|
assert_body 'Hello, bar!'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|