`assert_template` always succeeds when passed locals in an ActionController::TestCase
opsidao opened this issue · 0 comments
opsidao commented
As can be seen in the code, when you mistakenly pass the locals
parameter to assert_template
the assertion will simply write a message to the terminal, not even labeled as a warning in any way, but the assertion will the proceed to succeed regardless of what you pass to it.
A small test case follows:
# config/routes.rb
Rails.application.routes.draw do
get 'failling' => 'failling#index'
end
# app/controllers/failling_controller.rb
class FaillingController < ActionController::Base
def index
head :ok
end
end
# test/controllers/failling_controller_test.rb
require 'test_helper'
class FaillingControllerTest < ActionController::TestCase
tests FaillingController
test 'unexpected success' do
get :index
assert_response 200
assert_template partial: 'totally made up partial',
locals: { if_this_is_here: "then it doesn't matter" }
end
end
Executing this test I would expect a failure, but it succeeds just writing the message to the console:
Started with run options --seed 41249
# Running tests with run options --seed 41249:
FaillingControllerTest
the :locals option to #assert_template is only supported in a ActionView::TestCase
test_unexpected_success PASS (0.08s)
.
Finished in 0.08816s
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
Finished tests in 0.088958s, 11.2413 tests/s, 11.2413 assertions/s.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
I think that in this case, the correct behaviour would be for the assertion to fail.