Module: Sinatra::Test
- Includes:
- Rack::Utils
- Included in:
- TestHarness
- Defined in:
- lib/sinatra/test.rb,
lib/sinatra/test/spec.rb,
lib/sinatra/test/bacon.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#body ⇒ Object
-
#delete(path, *args, &b) ⇒ Object
-
#follow! ⇒ Object
-
#get(path, *args, &b) ⇒ Object
-
#head(path, *args, &b) ⇒ Object
-
#make_request(verb, path, body = nil, options = {}) {|@request| ... } ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
Delegate other missing methods to @response.
-
#post(path, *args, &b) ⇒ Object
-
#put(path, *args, &b) ⇒ Object
-
#respond_to?(symbol, include_private = false) ⇒ Boolean
Also check @response since we delegate there.
-
#should ⇒ Object
-
#status ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Delegate other missing methods to @response.
54
55
56
57
58
59
60
|
# File 'lib/sinatra/test.rb', line 54
def method_missing(name, *args, &block)
if @response && @response.respond_to?(name)
@response.send(name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
7
8
9
|
# File 'lib/sinatra/test.rb', line 7
def app
@app
end
|
#request ⇒ Object
Returns the value of attribute request.
7
8
9
|
# File 'lib/sinatra/test.rb', line 7
def request
@request
end
|
#response ⇒ Object
Returns the value of attribute response.
7
8
9
|
# File 'lib/sinatra/test.rb', line 7
def response
@response
end
|
Class Method Details
.deprecate(framework) ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/sinatra/test.rb', line 9
def self.deprecate(framework)
warn <<-EOF
Warning: support for the #{framework} testing framework is deprecated and
will be dropped in Sinatra 1.0. See <http://sinatra.github.com/testing.html>
for more information.
EOF
end
|
Instance Method Details
#body ⇒ Object
50
|
# File 'lib/sinatra/test.rb', line 50
def body ; @response.body ; end
|
#delete(path, *args, &b) ⇒ Object
44
|
# File 'lib/sinatra/test.rb', line 44
def delete(path, *args, &b) ; make_request('DELETE', path, *args, &b) ; end
|
#follow! ⇒ Object
46
47
48
|
# File 'lib/sinatra/test.rb', line 46
def follow!
make_request 'GET', @response.location
end
|
#get(path, *args, &b) ⇒ Object
40
|
# File 'lib/sinatra/test.rb', line 40
def get(path, *args, &b) ; make_request('GET', path, *args, &b) ; end
|
#head(path, *args, &b) ⇒ Object
41
|
# File 'lib/sinatra/test.rb', line 41
def head(path, *args, &b) ; make_request('HEAD', path, *args, &b) ; end
|
#make_request(verb, path, body = nil, options = {}) {|@request| ... } ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/sinatra/test.rb', line 17
def make_request(verb, path, body=nil, options={})
@app = Sinatra::Application if @app.nil? && defined?(Sinatra::Application)
fail "@app not set - cannot make request" if @app.nil?
@request = Rack::MockRequest.new(@app)
options = { :lint => true }.merge(options || {})
case
when body.respond_to?(:to_hash)
options.merge! body.delete(:env) if body.key?(:env)
options[:input] = param_string(body)
when body.respond_to?(:to_str)
options[:input] = body
when body.nil?
options[:input] = ''
else
raise ArgumentError, "body must be a Hash, String, or nil"
end
yield @request if block_given?
@response = @request.request(verb, path, rack_options(options))
end
|
#post(path, *args, &b) ⇒ Object
42
|
# File 'lib/sinatra/test.rb', line 42
def post(path, *args, &b) ; make_request('POST', path, *args, &b) ; end
|
#put(path, *args, &b) ⇒ Object
43
|
# File 'lib/sinatra/test.rb', line 43
def put(path, *args, &b) ; make_request('PUT', path, *args, &b) ; end
|
#respond_to?(symbol, include_private = false) ⇒ Boolean
Also check @response since we delegate there.
63
64
65
|
# File 'lib/sinatra/test.rb', line 63
def respond_to?(symbol, include_private=false)
super || (@response && @response.respond_to?(symbol, include_private))
end
|
#should ⇒ Object
8
9
10
|
# File 'lib/sinatra/test/spec.rb', line 8
def should
@response.should
end
|
#status ⇒ Object
51
|
# File 'lib/sinatra/test.rb', line 51
def status ; @response.status ; end
|