Module Sinatra::Test
In: lib/sinatra/test.rb
lib/sinatra/test/bacon.rb
lib/sinatra/test/spec.rb

Methods

body   delete   deprecate   follow!   get   head   included   make_request   method_missing   post   put   respond_to?   should   should   status  

Included Modules

Rack::Utils

Constants

RACK_OPTIONS = { :accept => 'HTTP_ACCEPT', :agent => 'HTTP_USER_AGENT', :host => 'HTTP_HOST', :session => 'rack.session', :cookies => 'HTTP_COOKIE', :content_type => 'CONTENT_TYPE'

Attributes

app  [R] 
request  [R] 
response  [R] 

Public Class methods

[Source]

    # 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

[Source]

    # File lib/sinatra/test.rb, line 9
 9:     def self.included(base)
10:       Sinatra::Application.set(:environment, :test)
11:     end

Public Instance methods

[Source]

    # File lib/sinatra/test.rb, line 58
58:     def body ; @response.body ; end

[Source]

    # File lib/sinatra/test.rb, line 52
52:     def delete(path, *args, &b) ; make_request('DELETE', path, *args, &b) ; end

[Source]

    # File lib/sinatra/test.rb, line 54
54:     def follow!
55:       make_request 'GET', @response.location
56:     end

[Source]

    # File lib/sinatra/test.rb, line 48
48:     def get(path, *args, &b)  ; make_request('GET', path, *args, &b) ; end

[Source]

    # File lib/sinatra/test.rb, line 49
49:     def head(path, *args, &b) ; make_request('HEAD', path, *args, &b) ; end

[Source]

    # 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[:content_type] ||= 'application/x-www-form-urlencoded'
35:         options[:input] = param_string(body)
36:       when body.respond_to?(:to_str)
37:         options[:input] = body
38:       when body.nil?
39:         options[:input] = ''
40:       else
41:         raise ArgumentError, "body must be a Hash, String, or nil"
42:       end
43: 
44:       yield @request if block_given?
45:       @response = @request.request(verb, path, rack_options(options))
46:     end

Delegate other missing methods to @response.

[Source]

    # File lib/sinatra/test.rb, line 62
62:     def method_missing(name, *args, &block)
63:       if @response && @response.respond_to?(name)
64:         @response.send(name, *args, &block)
65:       else
66:         super
67:       end
68:     end

[Source]

    # File lib/sinatra/test.rb, line 50
50:     def post(path, *args, &b) ; make_request('POST', path, *args, &b) ; end

[Source]

    # File lib/sinatra/test.rb, line 51
51:     def put(path, *args, &b)  ; make_request('PUT', path, *args, &b) ; end

Also check @response since we delegate there.

[Source]

    # File lib/sinatra/test.rb, line 71
71:     def respond_to?(symbol, include_private=false)
72:       super || (@response && @response.respond_to?(symbol, include_private))
73:     end

[Source]

    # File lib/sinatra/test/spec.rb, line 8
 8:   def should
 9:     @response.should
10:   end

[Source]

    # File lib/sinatra/test/bacon.rb, line 14
14:   def should
15:     @response.should
16:   end

[Source]

    # File lib/sinatra/test.rb, line 59
59:     def status ; @response.status ; end

[Validate]