Module: Rack::Test::Methods
- Extended by:
- Forwardable
- Defined in:
- lib/rack/test/methods.rb
Overview
This module serves as the primary integration point for using Rack::Test in a testing environment. It depends on an app method being defined in the same context, and provides the Rack::Test API methods (see Rack::Test::Session for their documentation).
Example:
class HomepageTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
MyApp.new
end
end
Constant Summary collapse
- METHODS =
%i[ request get post put patch delete options head custom_request follow_redirect! header env set_cookie clear_cookies authorize basic_authorize digest_authorize last_response last_request ].freeze
Instance Method Summary collapse
-
#_current_session_names ⇒ Object
:nodoc:.
-
#build_rack_mock_session ⇒ Object
:nodoc:.
-
#build_rack_test_session(name) ⇒ Object
:nodoc:.
-
#current_session ⇒ Object
:nodoc:.
-
#rack_mock_session(name = :default) ⇒ Object
:nodoc:.
-
#rack_test_session(name = :default) ⇒ Object
:nodoc:.
-
#with_session(name) {|rack_test_session(name)| ... } ⇒ Object
:nodoc:.
Instance Method Details
#_current_session_names ⇒ Object
:nodoc:
54 55 56 |
# File 'lib/rack/test/methods.rb', line 54 def _current_session_names # :nodoc: @_current_session_names ||= [:default] end |
#build_rack_mock_session ⇒ Object
:nodoc:
29 30 31 |
# File 'lib/rack/test/methods.rb', line 29 def build_rack_mock_session # :nodoc: Rack::MockSession.new(app) end |
#build_rack_test_session(name) ⇒ Object
:nodoc:
40 41 42 |
# File 'lib/rack/test/methods.rb', line 40 def build_rack_test_session(name) # :nodoc: Rack::Test::Session.new(rack_mock_session(name)) end |
#current_session ⇒ Object
:nodoc:
44 45 46 |
# File 'lib/rack/test/methods.rb', line 44 def current_session # :nodoc: rack_test_session(_current_session_names.last) end |
#rack_mock_session(name = :default) ⇒ Object
:nodoc:
22 23 24 25 26 27 |
# File 'lib/rack/test/methods.rb', line 22 def rack_mock_session(name = :default) # :nodoc: return build_rack_mock_session unless name @_rack_mock_sessions ||= {} @_rack_mock_sessions[name] ||= build_rack_mock_session end |
#rack_test_session(name = :default) ⇒ Object
:nodoc:
33 34 35 36 37 38 |
# File 'lib/rack/test/methods.rb', line 33 def rack_test_session(name = :default) # :nodoc: return build_rack_test_session(name) unless name @_rack_test_sessions ||= {} @_rack_test_sessions[name] ||= build_rack_test_session(name) end |
#with_session(name) {|rack_test_session(name)| ... } ⇒ Object
:nodoc:
48 49 50 51 52 |
# File 'lib/rack/test/methods.rb', line 48 def with_session(name) # :nodoc: _current_session_names.push(name) yield rack_test_session(name) _current_session_names.pop end |