Module: Mack::TestHelpers
- Defined in:
- lib/test_extensions/test_helpers.rb
Instance Method Summary collapse
-
#assigns(key) ⇒ Object
Retrieves an instance variable from the controller from a request.
-
#clear_session ⇒ Object
Clears all the sessions.
-
#cookies ⇒ Object
Returns a Hash of cookies from the response.
-
#delete(uri, options = {}) ⇒ Object
Performs a ‘delete’ request for the specified uri.
-
#get(uri, options = {}) ⇒ Object
Performs a ‘get’ request for the specified uri.
-
#in_session ⇒ Object
Used to create a ‘session’ around a block of code.
-
#post(uri, options = {}) ⇒ Object
Performs a ‘post’ request for the specified uri.
-
#put(uri, options = {}) ⇒ Object
Performs a ‘put’ request for the specified uri.
- #remote_test ⇒ Object
-
#remove_cookie(name) ⇒ Object
Removes a cookie.
-
#request ⇒ Object
Returns a Rack::MockRequest.
-
#response ⇒ Object
Returns the last Rack::MockResponse that got generated by a call.
-
#responses ⇒ Object
Returns all the Rack::MockResponse objects that get generated by a call.
-
#session ⇒ Object
Returns a Mack::Session from the request.
-
#set_cookie(name, value) ⇒ Object
Sets a cookie to be used for the next request.
- #temp_app_config(options = {}) ⇒ Object
Instance Method Details
#assigns(key) ⇒ Object
Retrieves an instance variable from the controller from a request.
20 21 22 |
# File 'lib/test_extensions/test_helpers.rb', line 20 def assigns(key) $mack_app.instance_variable_get("@app").instance_variable_get("@response").instance_variable_get("@controller").instance_variable_get("@#{key}") end |
#clear_session ⇒ Object
Clears all the sessions.
74 75 76 |
# File 'lib/test_extensions/test_helpers.rb', line 74 def clear_session Cachetastic::Caches::MackSessionCache.expire_all end |
#cookies ⇒ Object
Returns a Hash of cookies from the response.
79 80 81 |
# File 'lib/test_extensions/test_helpers.rb', line 79 def end |
#delete(uri, options = {}) ⇒ Object
Performs a ‘delete’ request for the specified uri.
40 41 42 |
# File 'lib/test_extensions/test_helpers.rb', line 40 def delete(uri, = {}) build_response(request.delete(uri, ())) end |
#get(uri, options = {}) ⇒ Object
Performs a ‘get’ request for the specified uri.
25 26 27 |
# File 'lib/test_extensions/test_helpers.rb', line 25 def get(uri, = {}) build_response(request.get(uri, ())) end |
#in_session ⇒ Object
Used to create a ‘session’ around a block of code. This is great of ‘integration’ tests.
65 66 67 68 69 70 71 |
# File 'lib/test_extensions/test_helpers.rb', line 65 def in_session @in_session = true clear_session yield clear_session @in_session = false end |
#post(uri, options = {}) ⇒ Object
Performs a ‘post’ request for the specified uri.
35 36 37 |
# File 'lib/test_extensions/test_helpers.rb', line 35 def post(uri, = {}) build_response(request.post(uri, ({:input => .to_params}))) end |
#put(uri, options = {}) ⇒ Object
Performs a ‘put’ request for the specified uri.
30 31 32 |
# File 'lib/test_extensions/test_helpers.rb', line 30 def put(uri, = {}) build_response(request.put(uri, ({:input => .to_params}))) end |
#remote_test ⇒ Object
13 14 15 16 17 |
# File 'lib/test_extensions/test_helpers.rb', line 13 def remote_test if (app_config.run_remote_tests) yield end end |
#remove_cookie(name) ⇒ Object
Removes a cookie.
89 90 91 |
# File 'lib/test_extensions/test_helpers.rb', line 89 def (name) .delete(name) end |
#request ⇒ Object
Returns a Rack::MockRequest. If there isn’t one, a new one is created.
45 46 47 |
# File 'lib/test_extensions/test_helpers.rb', line 45 def request @request ||= Rack::MockRequest.new(mack_app) end |
#response ⇒ Object
Returns the last Rack::MockResponse that got generated by a call.
50 51 52 |
# File 'lib/test_extensions/test_helpers.rb', line 50 def response responses.last end |
#responses ⇒ Object
Returns all the Rack::MockResponse objects that get generated by a call.
55 56 57 |
# File 'lib/test_extensions/test_helpers.rb', line 55 def responses @responses end |
#session ⇒ Object
Returns a Mack::Session from the request.
60 61 62 |
# File 'lib/test_extensions/test_helpers.rb', line 60 def session # :nodoc: Cachetastic::Caches::MackSessionCache.get([app_config.mack.session_id]) end |
#set_cookie(name, value) ⇒ Object
Sets a cookie to be used for the next request
84 85 86 |
# File 'lib/test_extensions/test_helpers.rb', line 84 def (name, value) [name] = value end |
#temp_app_config(options = {}) ⇒ Object
7 8 9 10 11 |
# File 'lib/test_extensions/test_helpers.rb', line 7 def temp_app_config( = {}) app_config.load_hash(, String.randomize) yield app_config.revert end |