1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/spec/test_app.rb
Thorbjørn Hermansen fe6f5a1bde Wrote failing specs which highlights missing content-type with rack test driver
Don't know if this could have been written any better, guess it can as
this is my first "deep" look into Capybara. The problem is found in the
Capybara::Driver::RackTest; it doesn't forward the content type of the
file being uplloaded to Rack::Test::UploadedFile.new. UploadFile's
initializer sets the content type to text/plain as a default.

This will make for instance Paperclip's attachment validation fail when
testing with Cucumber and Capybara even though we are uploading a type
which should pass.
2010-01-07 23:43:11 +01:00

67 lines
1.1 KiB
Ruby

require 'sinatra/base'
require 'rack'
require 'yaml'
class TestApp < Sinatra::Base
set :root, File.dirname(__FILE__)
set :static, true
get '/' do
'Hello world!'
end
get '/foo' do
'Another World'
end
get '/redirect' do
redirect '/redirect_again'
end
get '/redirect_again' do
redirect '/landed'
end
get '/landed' do
"You landed"
end
get '/with-quotes' do
%q{"No," he said, "you can't do that."}
end
get '/form/get' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
end
get '/favicon.ico' do
nil
end
get '/:view' do |view|
erb view.to_sym
end
post '/redirect' do
redirect '/redirect_again'
end
post '/form' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
end
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
end
end
if __FILE__ == $0
Rack::Handler::Mongrel.run TestApp, :Port => 8070
end