Module Mack::Testing::Helpers
In: lib/mack/testing/helpers.rb

Methods

Public Instance methods

Retrieves an instance variable from the controller from a request.

[Source]

    # File lib/mack/testing/helpers.rb, line 42
42:       def assigns(key)
43:         $mack_app.instance_variable_get("@app").instance_variable_get("@response").instance_variable_get("@controller").instance_variable_get("@#{key}")
44:       end

Clears all the sessions.

[Source]

     # File lib/mack/testing/helpers.rb, line 122
122:       def clear_session
123:         Mack::SessionStore.expire_all
124:       end

Returns a Hash of cookies from the response.

[Source]

     # File lib/mack/testing/helpers.rb, line 127
127:       def cookies
128:         test_cookies
129:       end

Performs a ‘deleterequest for the specified uri.

[Source]

    # File lib/mack/testing/helpers.rb, line 77
77:       def delete(uri, options = {})
78:         build_response(request.delete(uri, build_request_options({:input => options.to_params})))
79:       end

create a wrapper object for file upload testing.

[Source]

    # File lib/mack/testing/helpers.rb, line 47
47:       def file_for_upload(path)
48:         return Mack::Testing::FileWrapper.new(path)
49:       end

Performs a ‘getrequest for the specified uri.

[Source]

    # File lib/mack/testing/helpers.rb, line 52
52:       def get(uri, options = {})
53:         build_response(request.get(uri, build_request_options({:input => options.to_params})))
54:       end

Used to create a ‘session’ around a block of code. This is great of ‘integration’ tests.

[Source]

     # File lib/mack/testing/helpers.rb, line 111
111:       def in_session
112:         @_mack_in_session = true
113:         clear_session
114:         $current_session_id = session.id
115:         yield
116:         $current_session_id = nil
117:         clear_session
118:         @_mack_in_session = false
119:       end

Performs a ‘postrequest for the specified uri.

[Source]

    # File lib/mack/testing/helpers.rb, line 57
57:       def post(uri, options = {})
58:         if options[:multipart]
59:           form_input = build_multipart_data(options)
60:           build_response(request.post(uri, build_request_options({"CONTENT_TYPE" => "multipart/form-data, boundary=Mack-boundary", "CONTENT_LENGTH" => form_input.size, :input => form_input})))
61:         else
62:           build_response(request.post(uri, build_request_options({:input => options.to_params})))
63:         end
64:       end

Performs a ‘putrequest for the specified uri.

[Source]

    # File lib/mack/testing/helpers.rb, line 67
67:       def put(uri, options = {})
68:         if options[:multipart]
69:           form_input = build_multipart_data(options)
70:           build_response(request.put(uri, build_request_options({"CONTENT_TYPE" => "multipart/form-data, boundary=Mack-boundary", "CONTENT_LENGTH" => form_input.size, :input => form_input})))
71:         else
72:           build_response(request.put(uri, build_request_options({:input => options.to_params})))
73:         end
74:       end

Removes a cookie.

[Source]

     # File lib/mack/testing/helpers.rb, line 137
137:       def remove_cookie(name)
138:         test_cookies.delete(name)
139:       end

Returns a Rack::MockRequest. If there isn‘t one, a new one is created.

[Source]

    # File lib/mack/testing/helpers.rb, line 82
82:       def request
83:         @request ||= Rack::MockRequest.new(mack_app)
84:       end

Returns the last Rack::MockResponse that got generated by a call.

[Source]

    # File lib/mack/testing/helpers.rb, line 87
87:       def response
88:         @testing_response
89:       end

Returns all the Rack::MockResponse objects that get generated by a call.

[Source]

    # File lib/mack/testing/helpers.rb, line 92
92:       def responses
93:         @responses
94:       end

Sets a cookie to be used for the next request

[Source]

     # File lib/mack/testing/helpers.rb, line 132
132:       def set_cookie(name, value)
133:         test_cookies[name] = value
134:       end

Temporarily changes the application configuration. Changes are reverted after the yield returns.

[Source]

    # File lib/mack/testing/helpers.rb, line 29
29:       def temp_app_config(options = {})
30:         configatron.temp(options) do
31:           yield
32:         end
33:       end

[Validate]