Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5375 from nertzy/assert_template_with_regexp

assert_template matches against Regexp
  • Loading branch information...
commit fd22471313864c58cb911101d8c42e1fa46b4e42 2 parents dea486d + b142bd8
@tenderlove tenderlove authored
View
9 actionpack/lib/action_controller/test_case.rb
@@ -56,6 +56,9 @@ def process(*args)
# # assert that the "new" view template was rendered
# assert_template "new"
#
+ # # assert that the exact template "admin/posts/new" was rendered
+ # assert_template %r{\Aadmin/posts/new\Z}
+ #
# # assert that the "_customer" partial was rendered twice
# assert_template :partial => '_customer', :count => 2
#
@@ -74,11 +77,11 @@ def assert_template(options = {}, message = nil)
response.body
case options
- when NilClass, String, Symbol
+ when NilClass, String, Symbol, Regexp
options = options.to_s if Symbol === options
rendered = @templates
msg = message || sprintf("expecting <%s> but rendering with <%s>",
- options, rendered.keys)
+ options.inspect, rendered.keys)
assert_block(msg) do
if options
rendered.any? { |t,num| t.match(options) }
@@ -121,6 +124,8 @@ def assert_template(options = {}, message = nil)
assert @partials.empty?,
"Expected no partials to be rendered"
end
+ else
+ raise ArgumentError, "assert_template only accepts a String, Symbol, Hash, Regexp, or nil"
end
end
end
View
6 actionpack/test/template/test_case_test.rb
@@ -277,6 +277,12 @@ def render_from_helper
end
class RenderTemplateTest < ActionView::TestCase
+ test "supports specifying templates with a Regexp" do
+ controller.controller_path = "fun"
+ render(:template => "fun/games/hello_world")
+ assert_template %r{\Afun/games/hello_world\Z}
+ end
+
test "supports specifying partials" do
controller.controller_path = "test"
render(:template => "test/calling_partial_with_layout")
Please sign in to comment.
Something went wrong with that request. Please try again.