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 13
13:     def self.deprecate(framework)
14:       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"
15:     end

[Source]

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

Public Instance methods

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

    # File lib/sinatra/test.rb, line 22
22:     def make_request(verb, path, body=nil, options={})
23:       @app = Sinatra::Application if @app.nil? && defined?(Sinatra::Application)
24:       fail "@app not set - cannot make request" if @app.nil?
25: 
26:       @request = Rack::MockRequest.new(@app)
27:       options = { :lint => true }.merge(options || {})
28: 
29:       case
30:       when body.respond_to?(:to_hash)
31:         options.merge! body.delete(:env) if body.key?(:env)
32:         options[:input] = param_string(body)
33:       when body.respond_to?(:to_str)
34:         options[:input] = body
35:       when body.nil?
36:         options[:input] = ''
37:       else
38:         raise ArgumentError, "body must be a Hash, String, or nil"
39:       end
40: 
41:       yield @request if block_given?
42:       @response = @request.request(verb, path, rack_options(options))
43:     end

Delegate other missing methods to @response.

[Source]

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

[Source]

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

[Source]

    # File lib/sinatra/test.rb, line 48
48:     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 68
68:     def respond_to?(symbol, include_private=false)
69:       super || (@response && @response.respond_to?(symbol, include_private))
70:     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 56
56:     def status ; @response.status ; end

[Validate]