Module: Sinatra::TestHelpers
- Extended by:
- Forwardable
- Includes:
- Rack::Test::Methods
- Defined in:
- lib/sinatra/test_helpers.rb
Defined Under Namespace
Classes: Session
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #app ⇒ Object
- #app=(base) ⇒ Object (also: #set_app)
-
#build_rack_test_session(name) ⇒ Object
:nodoc:.
- #last_env ⇒ Object
- #last_request? ⇒ Boolean
- #mock_app(base = Sinatra::Base, &block) ⇒ Object
- #options(uri, params = {}, env = {}, &block) ⇒ Object
- #patch(uri, params = {}, env = {}, &block) ⇒ Object
- #session ⇒ Object
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
24 25 26 |
# File 'lib/sinatra/test_helpers.rb', line 24 def settings @settings end |
Instance Method Details
#app ⇒ Object
47 48 49 50 |
# File 'lib/sinatra/test_helpers.rb', line 47 def app @app ||= Class.new Sinatra::Base Rack::Lint.new @app end |
#app=(base) ⇒ Object Also known as: set_app
41 42 43 |
# File 'lib/sinatra/test_helpers.rb', line 41 def app=(base) @app = base end |
#build_rack_test_session(name) ⇒ Object
:nodoc:
83 84 85 |
# File 'lib/sinatra/test_helpers.rb', line 83 def build_rack_test_session(name) # :nodoc: Session.new rack_mock_session(name) end |
#last_env ⇒ Object
79 80 81 |
# File 'lib/sinatra/test_helpers.rb', line 79 def last_env last_request.env end |
#last_request? ⇒ Boolean
66 67 68 69 70 71 |
# File 'lib/sinatra/test_helpers.rb', line 66 def last_request? last_request true rescue Rack::Test::Error false end |
#mock_app(base = Sinatra::Base, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/sinatra/test_helpers.rb', line 31 def mock_app(base = Sinatra::Base, &block) inner = nil @app = Sinatra.new(base) do inner = self class_eval(&block) end @settings = inner app end |
#options(uri, params = {}, env = {}, &block) ⇒ Object
53 54 55 56 |
# File 'lib/sinatra/test_helpers.rb', line 53 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) ⇒ Object
60 61 62 63 |
# File 'lib/sinatra/test_helpers.rb', line 60 def patch(uri, params = {}, env = {}, &block) env = env_for(uri, env.merge(:method => "PATCH", :params => params)) current_session.send(:process_request, uri, env, &block) end |
#session ⇒ Object
73 74 75 76 77 |
# File 'lib/sinatra/test_helpers.rb', line 73 def session return {} unless last_request? raise Rack::Test:Error, "session not enabled for app" unless last_env["rack.session"] or app.session? last_request.session end |