提交 9c91c168 编写于 作者: Y Yves Senn

Merge pull request #16027 from tgxworld/template_assertions

Fixes to ActionController::TemplateAssertions
* Fix `assert_template` not being able to assert that no files were rendered.
*Guo Xiang Tan*
* Extract source code for the entire exception stack trace for
better debugging and diagnosis.
......
......@@ -91,6 +91,13 @@ def reset_template_assertion
# # assert that no partials were rendered
# assert_template partial: false
#
# # assert that a file was rendered
# assert_template file: "README.rdoc"
#
# # assert that no file was rendered
# assert_template file: nil
# assert_template file: false
#
# In a view test case, you can also assert that specific locals are passed
# to partials:
#
......@@ -140,6 +147,8 @@ def assert_template(options = {}, message = nil)
if options[:file]
assert_includes @_files.keys, options[:file]
elsif options.key?(:file)
assert @_files.blank?, "expected no files but #{@_files.keys} was rendered"
end
if expected_partial = options[:partial]
......
......@@ -488,6 +488,11 @@ def test_with_file_failure
assert_raise(ActiveSupport::TestCase::Assertion) do
assert_template :file => 'test/hello_world'
end
get :render_file_absolute_path
assert_raise(ActiveSupport::TestCase::Assertion) do
assert_template file: nil
end
end
def test_with_nil_passes_when_no_template_rendered
......@@ -612,6 +617,24 @@ def test_assert_template_reset_between_requests
get :nothing
assert_template nil
get :partial
assert_template partial: 'test/_partial'
get :nothing
assert_template partial: nil
get :render_with_layout
assert_template layout: 'layouts/standard'
get :nothing
assert_template layout: nil
get :render_file_relative_path
assert_template file: 'README.rdoc'
get :nothing
assert_template file: nil
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册