1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/lib/capybara/spec/test_app.rb

131 lines
2.3 KiB
Ruby
Raw Normal View History

require 'sinatra/base'
require 'rack'
2009-12-19 05:52:08 -05:00
require 'yaml'
2009-11-04 17:32:35 -05:00
class TestApp < Sinatra::Base
2009-11-05 11:35:45 -05:00
set :root, File.dirname(__FILE__)
set :static, true
2009-11-04 17:32:35 -05:00
get '/' do
'Hello world!'
end
get '/foo' do
'Another World'
end
2009-11-12 12:58:27 -05:00
get '/redirect' do
redirect '/redirect_again'
end
get '/redirect_again' do
redirect '/landed'
end
get '/host' do
"Current host is #{request.scheme}://#{request.host}"
end
get '/redirect/:times/times' do
times = params[:times].to_i
if times.zero?
"redirection complete"
else
redirect "/redirect/#{times - 1}/times"
end
end
2009-11-12 12:58:27 -05:00
get '/landed' do
"You landed"
end
get '/with-quotes' do
%q{"No," he said, "you can't do that."}
end
2009-11-24 15:32:25 -05:00
get '/form/get' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
2009-11-07 19:13:16 -05:00
end
post '/relative' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
end
2009-11-24 15:32:25 -05:00
get '/favicon.ico' do
nil
end
post '/redirect' do
redirect '/redirect_again'
end
delete "/delete" do
"The requested object was deleted"
end
2010-02-12 08:41:41 -05:00
get '/redirect_back' do
redirect back
end
get '/slow_response' do
sleep 2
'Finally!'
end
get '/set_cookie' do
cookie_value = 'test_cookie'
response.set_cookie('capybara', cookie_value)
"Cookie set to #{cookie_value}"
end
get '/get_cookie' do
request.cookies['capybara']
end
get '/get_header' do
env['HTTP_FOO']
end
2010-02-12 08:41:41 -05:00
get '/:view' do |view|
erb view.to_sym
end
2009-11-24 15:32:25 -05:00
post '/form' do
2009-11-17 17:36:27 -05:00
'<pre id="results">' + params[:form].to_yaml + '</pre>'
end
2009-11-12 11:07:43 -05:00
post '/upload_empty' do
if params[:form][:file].nil?
'Successfully ignored empty file field.'
else
'Something went wrong.'
end
end
2009-11-12 11:07:43 -05:00
post '/upload' do
begin
buffer = []
buffer << "Content-type: #{params[:form][:document][:type]}"
buffer << "File content: #{params[:form][:document][:tempfile].read}"
buffer.join(' | ')
rescue
'No file uploaded'
end
2009-11-12 11:07:43 -05:00
end
post '/upload_multiple' do
begin
buffer = []
buffer << "Content-type: #{params[:form][:multiple_documents][0][:type]}"
buffer << "File content: #{params[:form][:multiple_documents][0][:tempfile].read}"
buffer.join(' | ')
rescue
'No files uploaded'
end
end
2009-11-07 19:13:16 -05:00
end
if __FILE__ == $0
Rack::Handler::WEBrick.run TestApp, :Port => 8070
end