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

Methods

body   delete   env_for   follow!   get   head   method_missing   param_string   post   put   rack_opts   respond_to?   should   should   status   test_request  

Included Modules

Rack::Utils

Constants

RACK_OPT_NAMES = { :accept => "HTTP_ACCEPT", :agent => "HTTP_USER_AGENT", :host => "HTTP_HOST", :session => "HTTP_COOKIE", :cookies => "HTTP_COOKIE", :content_type => "CONTENT_TYPE"

Attributes

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

Public Instance methods

[Source]

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

[Source]

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

[Source]

    # File lib/sinatra/test.rb, line 85
85:     def env_for(opts={})
86:       opts = rack_opts(opts)
87:       Rack::MockRequest.env_for(opts)
88:     end

[Source]

    # File lib/sinatra/test.rb, line 47
47:     def follow!
48:       test_request 'GET', @response.location
49:     end

[Source]

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

[Source]

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

Delegate other missing methods to @response.

[Source]

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

[Source]

    # File lib/sinatra/test.rb, line 90
90:     def param_string(hash)
91:       hash.map { |pair| pair.map{|v|escape(v)}.join('=') }.join('&')
92:     end

[Source]

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

[Source]

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

[Source]

    # File lib/sinatra/test.rb, line 77
77:     def rack_opts(opts)
78:       opts.inject({}) do |hash,(key,val)|
79:         key = RACK_OPT_NAMES[key] || key
80:         hash[key] = val
81:         hash
82:       end
83:     end

Also check @response since we delegate there.

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

    # File lib/sinatra/test.rb, line 10
10:     def test_request(verb, path, *args)
11:       @app = Sinatra::Application if @app.nil? && defined?(Sinatra::Application)
12:       fail "@app not set - cannot make request" if @app.nil?
13:       @request = Rack::MockRequest.new(@app)
14:       opts, input =
15:         case args.size
16:         when 2 # input, env
17:           input, env = args
18:           if input.kind_of?(Hash) # params, env
19:             [env, param_string(input)]
20:           else
21:             [env, input]
22:           end
23:         when 1 # params
24:           if (data = args.first).kind_of?(Hash)
25:             env = (data.delete(:env) || {})
26:             [env, param_string(data)]
27:           else
28:             [{}, data]
29:           end
30:         when 0
31:           [{}, '']
32:         else
33:           raise ArgumentError, "zero, one, or two arguments expected"
34:         end
35:       opts = rack_opts(opts)
36:       opts[:input] ||= input
37:       yield @request if block_given?
38:       @response = @request.request(verb, path, opts)
39:     end

[Validate]