Module | Sinatra::Test |
In: |
lib/sinatra/test.rb
lib/sinatra/test/bacon.rb lib/sinatra/test/spec.rb |
RACK_OPTIONS | = | { :accept => 'HTTP_ACCEPT', :agent => 'HTTP_USER_AGENT', :host => 'HTTP_HOST', :session => 'rack.session', :cookies => 'HTTP_COOKIE', :content_type => 'CONTENT_TYPE' |
app | [R] | |
request | [R] | |
response | [R] |
# File lib/sinatra/test.rb, line 15 15: def self.deprecate(framework) 16: warn "Warning: support for the \#{framework} testing framework is deprecated and\nwill be dropped in Sinatra 1.0. See <http://sinatra.github.com/testing.html>\nfor more information.\n" 17: end
# File lib/sinatra/test.rb, line 9 9: def self.included(base) 10: Sinatra::Default.set(:environment, :test) 11: end
# File lib/sinatra/test.rb, line 51 51: def delete(path, *args, &b) ; make_request('DELETE', path, *args, &b) ; end
# File lib/sinatra/test.rb, line 53 53: def follow! 54: make_request 'GET', @response.location 55: end
# File lib/sinatra/test.rb, line 47 47: def get(path, *args, &b) ; make_request('GET', path, *args, &b) ; end
# File lib/sinatra/test.rb, line 48 48: def head(path, *args, &b) ; make_request('HEAD', path, *args, &b) ; end
# File lib/sinatra/test.rb, line 24 24: def make_request(verb, path, body=nil, options={}) 25: @app = Sinatra::Application if @app.nil? && defined?(Sinatra::Application) 26: fail "@app not set - cannot make request" if @app.nil? 27: 28: @request = Rack::MockRequest.new(@app) 29: options = { :lint => true }.merge(options || {}) 30: 31: case 32: when body.respond_to?(:to_hash) 33: options.merge! body.delete(:env) if body.key?(:env) 34: options[:input] = param_string(body) 35: when body.respond_to?(:to_str) 36: options[:input] = body 37: when body.nil? 38: options[:input] = '' 39: else 40: raise ArgumentError, "body must be a Hash, String, or nil" 41: end 42: 43: yield @request if block_given? 44: @response = @request.request(verb, path, rack_options(options)) 45: end
Delegate other missing methods to @response.
# File lib/sinatra/test.rb, line 61 61: def method_missing(name, *args, &block) 62: if @response && @response.respond_to?(name) 63: @response.send(name, *args, &block) 64: else 65: super 66: end 67: end
# File lib/sinatra/test.rb, line 49 49: def post(path, *args, &b) ; make_request('POST', path, *args, &b) ; end
# File lib/sinatra/test.rb, line 50 50: def put(path, *args, &b) ; make_request('PUT', path, *args, &b) ; end
Also check @response since we delegate there.
# File lib/sinatra/test.rb, line 70 70: def respond_to?(symbol, include_private=false) 71: super || (@response && @response.respond_to?(symbol, include_private)) 72: end