Module: Sinatra::TestHelpers
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Instance Chain:
self,
Rack::Test::Methods
|
|
Defined in: | sinatra-contrib/lib/sinatra/test_helpers.rb |
Overview
Instance Methods delegated to last_response
-
#body ⇒ String
Body of last_response.
-
#errors ⇒ Array
Errors of last_response.
-
#headers ⇒ Hash
Headers of last_response.
-
#status ⇒ Integer
HTTP status of last_response.
Class Methods delegated to app
-
.configure(*envs) {|_self| ... }) {|_self| ... }
Set configuration options for
::Sinatra
and/or the app. -
.disable(*opts)
Same as calling
set <code>:option</code>, false
for each of the given options. -
.enable(*opts)
Same as calling
set <code>:option</code>, true
for each of the given options. -
.helpers(*extensions, &block)
Makes the methods defined in the block and in the Modules given in
extensions
available to the handlers and templates. -
.register(*extensions, &block)
Register an extension.
-
.set(option, value = (not_set, ignore_setter = false, &block)
Sets an option to the given value.
-
.use(middleware, *args, &block)
Use the specified
::Rack
middleware.
Instance Methods delegated to current_session
-
#env_for(uri = "", opts = {}) ⇒ Hash
Return the
::Rack
environment used for a request touri
.
Instance Methods delegated to rack_mock_session
Instance Attribute Summary
-
#app ⇒ Sinatra::Base
rw
Returns a Rack::Lint-wrapped
::Sinatra
app. -
#app=(base)
(also: #set_app)
rw
Replaces the configured app.
- #last_request? ⇒ Boolean readonly
- #settings rw
Instance Method Summary
- #last_env ⇒ Object
-
#mock_app(base = Sinatra::Base, &block) ⇒ Sinatra
Instantiate and configure a mock
::Sinatra
app. -
#options(uri, params = {}, env = {}, &block)
Processes an OPTIONS request in the context of the current session.
-
#patch(uri, params = {}, env = {}, &block)
Processes a PATCH request in the context of the current session.
- #session ⇒ Hash
Class Method Details
.configure(*envs) {|_self| ... }) {|_self| ... }
Set configuration options for ::Sinatra
and/or the app. Allows scoping of
settings for certain environments.
.disable(*opts)
Same as calling set <code>:option</code>, false
for each of the given options.
.enable(*opts)
Same as calling set <code>:option</code>, true
for each of the given options.
.helpers(*extensions, &block)
Makes the methods defined in the block and in the Modules given in
extensions
available to the handlers and templates.
.register(*extensions, &block)
Register an extension. Alternatively take a block from which an extension will be created and registered on the fly.
.set(option, value = (not_set, ignore_setter = false, &block)
Sets an option to the given value. If the value is a proc, the proc will be called every time the option is accessed.
.use(middleware, *args, &block)
Use the specified ::Rack
middleware
Instance Attribute Details
#app ⇒ Sinatra::Base (rw)
#app=(base) (rw) Also known as: #set_app
Replaces the configured app.
# File 'sinatra-contrib/lib/sinatra/test_helpers.rb', line 136
def app=(base) @app = base end
#last_request? ⇒ Boolean
(readonly)
[ GitHub ]
#settings (rw)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/test_helpers.rb', line 20
attr_accessor :settings
Instance Method Details
#body ⇒ String
Body of last_response
#cookie_jar ⇒ Rack::Test::CookieJar
Returns a Rack::Test::CookieJar.
# File 'sinatra-contrib/lib/sinatra/test_helpers.rb', line 110
def_delegators :rack_mock_session, :
#env_for(uri = "", opts = {}) ⇒ Hash
Return the ::Rack
environment used for a request to uri
.
# File 'sinatra-contrib/lib/sinatra/test_helpers.rb', line 101
def_delegators :current_session, :env_for
#errors ⇒ Array
Errors of last_response
#headers ⇒ Hash
Headers of last_response
#last_env ⇒ Object
# File 'sinatra-contrib/lib/sinatra/test_helpers.rb', line 198
def last_env last_request.env end
#mock_app(base = Sinatra::Base, &block) ⇒ Sinatra
#options(uri, params = {}, env = {}, &block)
Processes an OPTIONS request in the context of the current session.
# File 'sinatra-contrib/lib/sinatra/test_helpers.rb', line 162
def (uri, params = {}, env = {}, &block) env = env_for(uri, env.merge(method: 'OPTIONS', params: params)) current_session.send(:process_request, uri, env, &block) end
#patch(uri, params = {}, env = {}, &block)
Processes a PATCH request in the context of the current session.
#session ⇒ Hash
# File 'sinatra-contrib/lib/sinatra/test_helpers.rb', line 190
def session return {} unless last_request? raise Rack::Test::Error, 'session not enabled for app' unless last_env['rack.session'] || app.session? last_request.session end
#status ⇒ Integer
HTTP status of last_response