Adds a wealth of assertions to do functional testing of Action Controllers.

Methods
Public Instance methods
acquire_assertion_target()

get the TestResponse object that these assertions depend upon

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 252
252:       def acquire_assertion_target
253:         target = ActionController::TestResponse.assertion_target
254:         assert_block( "Unable to acquire the TestResponse.assertion_target.  Please set this before calling this assertion." ) { !target.nil? }
255:         target
256:       end
assert_assigned_equal(expected = nil, key = nil, message = nil)

ensures that the object assigned to the template on key is equal to expected object.

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 225
225:       def assert_assigned_equal(expected = nil, key = nil, message = nil)
226:         response = acquire_assertion_target
227:         msg = build_message(message, "<?> expected in assigns['?'] but was <?>", expected, key, response.template.assigns[key.to_s])
228:         assert_block(msg) { expected == response.template.assigns[key.to_s] }
229:       end
assert_cookie_equal(expected = nil, key = nil, message = nil)

— cookie assertions —————————————————

    # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 66
66:       def assert_cookie_equal(expected = nil, key = nil, message = nil)
67:         response = acquire_assertion_target
68:         msg = build_message(message, "<?> expected in cookies['?'] but was <?>", expected, key, response.cookies[key.to_s].first)
69:         assert_block(msg) { expected == response.cookies[key.to_s].first }
70:       end
assert_flash_empty(message=nil)

ensure the flash is empty but existent

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 103
103:       def assert_flash_empty(message=nil)
104:         response = acquire_assertion_target
105:         msg = build_message(message, "the flash is not empty <?>", response.flash)
106:         assert_block(msg) { !response.has_flash_with_contents? }
107:       end
assert_flash_equal(expected = nil, key = nil, message = nil)
     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 116
116:       def assert_flash_equal(expected = nil, key = nil, message = nil)
117:         response = acquire_assertion_target
118:         msg = build_message(message, "<?> expected in flash['?'] but was <?>", expected, key, response.flash[key])
119:         assert_block(msg) { expected == response.flash[key] }
120:       end
assert_flash_exists(message=nil)

ensure the flash exists

    # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 89
89:       def assert_flash_exists(message=nil)
90:         response = acquire_assertion_target
91:         msg = build_message(message, "the flash does not exist <?>", response.session['flash'] )
92:         assert_block(msg) { response.has_flash? }
93:       end
assert_flash_has(key=nil, message=nil)

ensure that the flash has an object with the specified name

    # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 75
75:       def assert_flash_has(key=nil, message=nil)
76:         response = acquire_assertion_target
77:         msg = build_message(message, "<?> is not in the flash <?>", key, response.flash)
78:         assert_block(msg) { response.has_flash_object?(key) }
79:       end
assert_flash_has_no(key=nil, message=nil)

ensure that the flash has no object with the specified name

    # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 82
82:       def assert_flash_has_no(key=nil, message=nil)
83:         response = acquire_assertion_target
84:         msg = build_message(message, "<?> is in the flash <?>", key, response.flash)
85:         assert_block(msg) { !response.has_flash_object?(key) }
86:       end
assert_flash_not_empty(message=nil)

ensure the flash is not empty

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 110
110:       def assert_flash_not_empty(message=nil)
111:         response = acquire_assertion_target
112:         msg = build_message(message, "the flash is empty")
113:         assert_block(msg) { response.has_flash_with_contents? }
114:       end
assert_flash_not_exists(message=nil)

ensure the flash does not exist

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 96
 96:       def assert_flash_not_exists(message=nil)
 97:         response = acquire_assertion_target
 98:         msg = build_message(message, "the flash exists <?>", response.flash)
 99:         assert_block(msg) { !response.has_flash? }
100:       end
assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)

Asserts that the provided options can be used to generate the provided path.

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 182
182:       def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
183:         # Load routes.rb if it hasn't been loaded.
184:         ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty? 
185:         
186:         # Assume given controller
187:         request = ActionController::TestRequest.new({}, {}, nil)
188:         request.path_parameters = (defaults or {}).clone
189:         request.path_parameters[:controller] ||= options[:controller]
190:         
191:         generated_path, found_extras = ActionController::Routing::Routes.generate(options, request)
192:         generated_path = generated_path.join('/')
193:         msg = build_message(message, "found extras <?>, not <?>", found_extras, extras)
194:         assert_block(msg) { found_extras == extras }
195:         
196:         msg = build_message(message, "The generated path <?> did not match <?>", generated_path, 
197:             expected_path)
198:         assert_block(msg) { expected_path == generated_path }
199:       end
assert_invalid_column_on_record(key = nil, columns = "", message = nil)

Assert the template object with the given name is an Active Record descendant and the specified column(s) are invalid.

    # File vendor/rails/actionpack/lib/action_controller/assertions/active_record_assertions.rb, line 34
34:       def assert_invalid_column_on_record(key = nil, columns = "", message = nil)
35:         record = find_record_in_template(key)
36:         record.send(:validate)
37: 
38:         cols = glue_columns(columns)
39:         cols.delete_if { |col| record.errors.invalid?(col) }
40:         msg = build_message(message, "Active Record has valid columns <?>)", cols.join(",") )
41:         assert_block(msg) { cols.empty? }
42:       end
assert_invalid_record(key = nil, message = nil)

Assert the template object with the given name is an Active Record descendant and is invalid.

    # File vendor/rails/actionpack/lib/action_controller/assertions/active_record_assertions.rb, line 16
16:       def assert_invalid_record(key = nil, message = nil)
17:         record = find_record_in_template(key)
18:         msg = build_message(message, "Active Record is valid)")
19:         assert_block(msg) { !record.valid? }
20:       end
assert_recognizes(expected_options, path, extras={}, message=nil)

Asserts that the routing of the given path is handled correctly and that the parsed options match.

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 164
164:       def assert_recognizes(expected_options, path, extras={}, message=nil)
165:         # Load routes.rb if it hasn't been loaded.
166:         ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty? 
167:         
168:         # Assume given controller
169:         request = ActionController::TestRequest.new({}, {}, nil)
170:         request.path = path
171:         ActionController::Routing::Routes.recognize!(request)
172:         
173:         expected_options = expected_options.clone
174:         extras.each_key { |key| expected_options.delete key } unless extras.nil?
175:         
176:         msg = build_message(message, "The recognized options <?> did not match <?>", 
177:             request.path_parameters, expected_options)
178:         assert_block(msg) { request.path_parameters == expected_options }
179:       end
assert_redirect(message=nil)

ensure we have be redirected

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 125
125:       def assert_redirect(message=nil)
126:         response = acquire_assertion_target
127:         msg = build_message(message, "response is not a redirection (response code is <?>)", response.response_code)
128:         assert_block(msg) { response.redirect? }
129:       end
assert_redirect_url(url=nil, message=nil)

ensure our redirection url is an exact match

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 146
146:       def assert_redirect_url(url=nil, message=nil)
147:         assert_redirect(message)
148:         response = acquire_assertion_target
149:         msg = build_message(message, "<?> is not the redirected location <?>", url, response.redirect_url)
150:         assert_block(msg) { response.redirect_url == url }
151:       end
assert_redirect_url_match(pattern=nil, message=nil)

ensure our redirection url matches a pattern

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 154
154:       def assert_redirect_url_match(pattern=nil, message=nil)
155:         assert_redirect(message)
156:         response = acquire_assertion_target
157:         msg = build_message(message, "<?> was not found in the location: <?>", pattern, response.redirect_url)
158:         assert_block(msg) { response.redirect_url_match?(pattern) }
159:       end
assert_redirected_to(options = {}, message=nil)
     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 131
131:       def assert_redirected_to(options = {}, message=nil)
132:         assert_redirect(message)
133:         response = acquire_assertion_target
134: 
135:         msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>)", response.redirected_to)
136:         assert_block(msg) do
137:           if options.is_a?(Symbol)
138:             response.redirected_to == options
139:           else
140:             options.keys.all? { |k| options[k] == ( response.redirected_to[k].respond_to?(:to_param) ? response.redirected_to[k].to_param : response.redirected_to[k] if response.redirected_to[k] ) }
141:           end
142:         end
143:       end
assert_rendered_file(expected=nil, message=nil)

ensure the request was rendered with the appropriate template file

    # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 29
29:       def assert_rendered_file(expected=nil, message=nil)
30:         response = acquire_assertion_target
31:         rendered = expected ? response.rendered_file(!expected.include?('/')) : response.rendered_file
32:         msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered)
33:         assert_block(msg) do
34:           if expected.nil?
35:             response.rendered_with_file?
36:           else
37:             expected == rendered
38:           end
39:         end
40:       end
assert_routing(path, options, defaults={}, extras={}, message=nil)

asserts that path and options match both ways, in other words, the URL generated from options is same as path, and also that the options recognized from path are same as options

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 203
203:       def assert_routing(path, options, defaults={}, extras={}, message=nil)
204:         assert_recognizes(options, path, extras, message)
205:         assert_generates(path, options, defaults, extras, message)
206:       end
assert_session_equal(expected = nil, key = nil, message = nil)
    # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 58
58:       def assert_session_equal(expected = nil, key = nil, message = nil)
59:         response = acquire_assertion_target
60:         msg = build_message(message, "<?> expected in session['?'] but was <?>", expected, key, response.session[key])
61:         assert_block(msg) { expected == response.session[key] }
62:       end
assert_session_has(key=nil, message=nil)

ensure that the session has an object with the specified name

    # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 45
45:       def assert_session_has(key=nil, message=nil)
46:         response = acquire_assertion_target
47:         msg = build_message(message, "<?> is not in the session <?>", key, response.session)
48:         assert_block(msg) { response.has_session_object?(key) }
49:       end
assert_session_has_no(key=nil, message=nil)

ensure that the session has no object with the specified name

    # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 52
52:       def assert_session_has_no(key=nil, message=nil)
53:         response = acquire_assertion_target
54:         msg = build_message(message, "<?> is in the session <?>", key, response.session)
55:         assert_block(msg) { !response.has_session_object?(key) }
56:       end
assert_success(message=nil)

ensure that the web request has been serviced correctly

    # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 12
12:       def assert_success(message=nil)
13:         response = acquire_assertion_target
14:         if response.success?
15:           # to count the assertion
16:           assert_block("") { true }
17:         else
18:           if response.redirect?
19:             msg = build_message(message, "Response unexpectedly redirect to <?>", response.redirect_url)
20:           else
21:             msg = build_message(message, "unsuccessful request (response code = <?>)", 
22:                 response.response_code)
23:           end
24:           assert_block(msg) { false }
25:         end
26:       end
assert_template_has(key=nil, message=nil)

ensure that a template object with the given name exists

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 211
211:       def assert_template_has(key=nil, message=nil)
212:         response = acquire_assertion_target
213:         msg = build_message(message, "<?> is not a template object", key )
214:         assert_block(msg) { response.has_template_object?(key) }
215:       end
assert_template_has_no(key=nil,message=nil)

ensure that a template object with the given name does not exist

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 218
218:       def assert_template_has_no(key=nil,message=nil)
219:         response = acquire_assertion_target
220:         msg = build_message(message, "<?> is a template object <?>", key, response.template_objects[key])
221:         assert_block(msg) { !response.has_template_object?(key) }
222:       end
assert_template_xpath_match(expression=nil, expected=nil, message=nil)

Asserts that the template returns the expected string or array based on the XPath expression. This will only work if the template rendered a valid XML document.

     # File vendor/rails/actionpack/lib/action_controller/assertions/action_pack_assertions.rb, line 233
233:       def assert_template_xpath_match(expression=nil, expected=nil, message=nil)
234:         response = acquire_assertion_target
235:         xml, matches = REXML::Document.new(response.body), []
236:         xml.elements.each(expression) { |e| matches << e.text }
237:         if matches.empty? then
238:           msg = build_message(message, "<?> not found in document", expression)
239:           flunk(msg)
240:           return
241:         elsif matches.length < 2 then
242:           matches = matches.first
243:         end
244: 
245:         msg = build_message(message, "<?> found <?>, not <?>", expression, matches, expected)
246:         assert_block(msg) { matches == expected }
247:       end
assert_valid_column_on_record(key = nil, columns = "", message = nil)

Assert the template object with the given name is an Active Record descendant and the specified column(s) are valid.

    # File vendor/rails/actionpack/lib/action_controller/assertions/active_record_assertions.rb, line 23
23:       def assert_valid_column_on_record(key = nil, columns = "", message = nil)
24:         record = find_record_in_template(key)
25:         record.send(:validate)
26: 
27:         cols = glue_columns(columns)
28:         cols.delete_if { |col| !record.errors.invalid?(col) }
29:         msg = build_message(message, "Active Record has invalid columns <?>)", cols.join(",") )
30:         assert_block(msg) { cols.empty? }
31:       end
assert_valid_record(key = nil, message = nil)

Assert the template object with the given name is an Active Record descendant and is valid.

    # File vendor/rails/actionpack/lib/action_controller/assertions/active_record_assertions.rb, line 9
 9:       def assert_valid_record(key = nil, message = nil)
10:         record = find_record_in_template(key)
11:         msg = build_message(message, "Active Record is invalid <?>)", record.errors.full_messages)
12:         assert_block(msg) { record.valid? }
13:       end