agent testing!
[sinatra.git] / lib / sinatra / test / methods.rb
blob11fea42f0eaf91cf9cd190e44ee3edbe73f7f571
1 class Rack::MockRequest
2   class << self
3     alias :env_for_without_env :env_for
4     def env_for(uri = "", opts = {})
5       env = { 'HTTP_USER_AGENT' => opts.delete(:agent) }
6       env_for_without_env(uri, opts).merge(env)
7     end
8   end
9 end
11 module Sinatra
12   
13   module Test
14     
15     module Methods
16   
17       def get_it(path, params = {})
18         agent = params.delete(:agent)
19         @request = Rack::MockRequest.new(Sinatra.application)
20         @response = @request.get(path, :input => params.to_params, :agent => agent)
21       end
23       def post_it(path, params = {})
24         agent = params.delete(:agent)
25         @request = Rack::MockRequest.new(Sinatra.application)
26         @response = @request.post(path, :input => params.to_params, :agent => agent)
27       end
29       def put_it(path, params = {})
30         agent = params.delete(:agent)
31         @request = Rack::MockRequest.new(Sinatra.application)
32         @response = @request.put(path, :input => params.to_params, :agent => agent)
33       end
35       def delete_it(path, params = {})
36         agent = params.delete(:agent)
37         @request = Rack::MockRequest.new(Sinatra.application)
38         @response = @request.delete(path, :input => params.to_params, :agent => agent)
39       end
40       
41       def follow!
42         get_it(@response.location)
43       end
45       def method_missing(name, *args)
46         @response.send(name, *args)
47       end
48       
49     end
51   end
52   
53 end