First assertion tests that both layout "layouts/application" and partial "_auth" were rendered.
Second only checks for "_auth".
Replace it with :partial since it would better communicate what "_auth" is.
You can refer to documentation
Rails 4: Syntax for testing partials
-
22-09-2022 - |
Question
I'm trying to figure out Rails syntax for testing views & partials.
What is the difference between these two tests? Both succeed using my partial in app/views/layouts/_auth.html.erb.
assert_template layout: "layouts/application", partial: "_auth"
and this:
assert_template layout: "layouts/_auth"
Also here are the tests I have written out for this controller. All assertions pass, but I think I'm missing some conventions. If you see any please let me know.
class UsersControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_template :index
assert_template layout: "layouts/application"
assert_template layout: "layouts/application", partial: "_auth"
assert_template partial: "sessions/_sign_in_form" # Can the below partials be rewritten?
assert_template partial: "shared/_user_error_messages"
assert_template partial: "users/_user_form"
assert_template partial: "layouts/_log_in_modal"
end
end
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow