Module: Sinatra::Test

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

deprecate(framework)

[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

included(base)

[Source]

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

### Public Instance methods

body()

[Source]

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

delete(path, *args, &b)

[Source]

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

follow!()

[Source]

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

get(path, *args, &b)

[Source]

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

head(path, *args, &b)

[Source]

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

make_request(verb, path, body=nil, options={}) {|@request if block_given?| ...}

[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[: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

method_missing(name, *args, &block)

Delegate other missing methods to @response.

[Source]

        # 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

post(path, *args, &b)

[Source]

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

put(path, *args, &b)

[Source]

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

respond_to?(symbol, include_private=false)

Also check @response since we delegate there.

[Source]

        # 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

should()

[Source]

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

should()

[Source]

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

status()

[Source]

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

[Validate]