module Sinatra::Test
def self.deprecate(framework)
def self.deprecate(framework) warn <<-EOF ing: support for the #{framework} testing framework is deprecated and be dropped in Sinatra 1.0. See <http://sinatra.github.com/testing.html> more information. EOF end
def self.included(base)
def self.included(base) Sinatra::Application.set(:environment, :test) end
def body ; @response.body ; end
def body ; @response.body ; end
def delete(path, *args, &b) ; make_request('DELETE', path, *args, &b) ; end
def delete(path, *args, &b) ; make_request('DELETE', path, *args, &b) ; end
def follow!
def follow! make_request 'GET', @response.location end
def get(path, *args, &b) ; make_request('GET', path, *args, &b) ; end
def get(path, *args, &b) ; make_request('GET', path, *args, &b) ; end
def head(path, *args, &b) ; make_request('HEAD', path, *args, &b) ; end
def head(path, *args, &b) ; make_request('HEAD', path, *args, &b) ; end
def make_request(verb, path, body=nil, options={})
def make_request(verb, path, body=nil, options={}) @app = Sinatra::Application if @app.nil? && defined?(Sinatra::Application) fail "@app not set - cannot make request" if @app.nil? @request = Rack::MockRequest.new(@app) options = { :lint => true }.merge(options || {}) case when body.respond_to?(:to_hash) options.merge! body.delete(:env) if body.key?(:env) options[:content_type] ||= 'application/x-www-form-urlencoded' options[:input] = param_string(body) when body.respond_to?(:to_str) options[:input] = body when body.nil? options[:input] = '' else raise ArgumentError, "body must be a Hash, String, or nil" end yield @request if block_given? @response = @request.request(verb, path, rack_options(options)) end
def method_missing(name, *args, &block)
def method_missing(name, *args, &block) if @response && @response.respond_to?(name) @response.send(name, *args, &block) else super end end
def param_string(value, prefix = nil)
def param_string(value, prefix = nil) case value when Array value.map { |v| param_string(v, "#{prefix}[]") } * "&" when Hash value.map { |k, v| param_string(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k)) } * "&" else "#{prefix}=#{escape(value)}" end end
def post(path, *args, &b) ; make_request('POST', path, *args, &b) ; end
def post(path, *args, &b) ; make_request('POST', path, *args, &b) ; end
def put(path, *args, &b) ; make_request('PUT', path, *args, &b) ; end
def put(path, *args, &b) ; make_request('PUT', path, *args, &b) ; end
def rack_options(opts)
def rack_options(opts) opts.merge(:lint => true).inject({}) do |hash,(key,val)| key = RACK_OPTIONS[key] || key hash[key] = val hash end end
def respond_to?(symbol, include_private=false)
def respond_to?(symbol, include_private=false) super || (@response && @response.respond_to?(symbol, include_private)) end
def should
def should @response.should end
def should
def should @response.should end
def status ; @response.status ; end
def status ; @response.status ; end