User `assert_includes`/`refute_includes` minitest helpers

This commit is contained in:
Carlos Antonio da Silva 2020-08-27 18:38:26 -03:00
parent e39b9b9134
commit 15135f7dc6
16 changed files with 34 additions and 34 deletions

View File

@ -16,6 +16,6 @@ class LoadHooksControllerTest < Devise::ControllerTestCase
end end
test 'load hook called when controller is loaded' do test 'load hook called when controller is loaded' do
assert DeviseController.instance_methods.include? :defined_by_load_hook assert_includes DeviseController.instance_methods, :defined_by_load_hook
end end
end end

View File

@ -326,8 +326,8 @@ class FailureTest < ActiveSupport::TestCase
"warden" => stub_everything "warden" => stub_everything
} }
call_failure(env) call_failure(env)
assert @response.third.body.include?('<h2>Log in</h2>') assert_includes @response.third.body, '<h2>Log in</h2>'
assert @response.third.body.include?('Invalid Email or password.') assert_includes @response.third.body, 'Invalid Email or password.'
end end
test 'calls the original controller if not confirmed email' do test 'calls the original controller if not confirmed email' do
@ -337,8 +337,8 @@ class FailureTest < ActiveSupport::TestCase
"warden" => stub_everything "warden" => stub_everything
} }
call_failure(env) call_failure(env)
assert @response.third.body.include?('<h2>Log in</h2>') assert_includes @response.third.body, '<h2>Log in</h2>'
assert @response.third.body.include?('You have to confirm your email address before continuing.') assert_includes @response.third.body, 'You have to confirm your email address before continuing.'
end end
test 'calls the original controller if inactive account' do test 'calls the original controller if inactive account' do
@ -348,8 +348,8 @@ class FailureTest < ActiveSupport::TestCase
"warden" => stub_everything "warden" => stub_everything
} }
call_failure(env) call_failure(env)
assert @response.third.body.include?('<h2>Log in</h2>') assert_includes @response.third.body, '<h2>Log in</h2>'
assert @response.third.body.include?('Your account is not activated yet.') assert_includes @response.third.body, 'Your account is not activated yet.'
end end
if Rails.application.config.respond_to?(:relative_url_root) if Rails.application.config.respond_to?(:relative_url_root)
@ -361,8 +361,8 @@ class FailureTest < ActiveSupport::TestCase
"warden" => stub_everything "warden" => stub_everything
} }
call_failure(env) call_failure(env)
assert @response.third.body.include?('<h2>Log in</h2>') assert_includes @response.third.body, '<h2>Log in</h2>'
assert @response.third.body.include?('Invalid Email or password.') assert_includes @response.third.body, 'Invalid Email or password.'
assert_equal '/sample', @request.env["SCRIPT_NAME"] assert_equal '/sample', @request.env["SCRIPT_NAME"]
assert_equal '/users/sign_in', @request.env["PATH_INFO"] assert_equal '/users/sign_in', @request.env["PATH_INFO"]
end end

View File

@ -496,7 +496,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
create_user create_user
post user_session_path(format: 'xml'), params: { user: {email: "user@test.com", password: '12345678'} } post user_session_path(format: 'xml'), params: { user: {email: "user@test.com", password: '12345678'} }
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end end
test 'sign in with xml format is idempotent' do test 'sign in with xml format is idempotent' do
@ -512,7 +512,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
post user_session_path(format: 'xml'), params: { user: {email: "user@test.com", password: '12345678'} } post user_session_path(format: 'xml'), params: { user: {email: "user@test.com", password: '12345678'} }
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end end
test 'sign out with html redirects' do test 'sign out with html redirects' do

View File

@ -225,21 +225,21 @@ class ConfirmationTest < Devise::IntegrationTest
create_user(confirm: false) create_user(confirm: false)
post user_confirmation_path(format: 'xml'), params: { user: { email: 'invalid.test@test.com' } } post user_confirmation_path(format: 'xml'), params: { user: { email: 'invalid.test@test.com' } }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
test 'confirm account with valid confirmation token in XML format should return valid response' do test 'confirm account with valid confirmation token in XML format should return valid response' do
user = create_user(confirm: false) user = create_user(confirm: false)
get user_confirmation_path(confirmation_token: user.raw_confirmation_token, format: 'xml') get user_confirmation_path(confirmation_token: user.raw_confirmation_token, format: 'xml')
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end end
test 'confirm account with invalid confirmation token in XML format should return invalid response' do test 'confirm account with invalid confirmation token in XML format should return invalid response' do
create_user(confirm: false) create_user(confirm: false)
get user_confirmation_path(confirmation_token: 'invalid_confirmation', format: 'xml') get user_confirmation_path(confirmation_token: 'invalid_confirmation', format: 'xml')
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
test 'request an account confirmation account with JSON, should return an empty JSON' do test 'request an account confirmation account with JSON, should return an empty JSON' do

View File

@ -146,7 +146,7 @@ class LockTest < Devise::IntegrationTest
post user_unlock_path(format: 'xml'), params: { user: {email: user.email} } post user_unlock_path(format: 'xml'), params: { user: {email: user.email} }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_equal 0, ActionMailer::Base.deliveries.size assert_equal 0, ActionMailer::Base.deliveries.size
end end
@ -156,13 +156,13 @@ class LockTest < Devise::IntegrationTest
assert user.access_locked? assert user.access_locked?
get user_unlock_path(format: 'xml', unlock_token: raw) get user_unlock_path(format: 'xml', unlock_token: raw)
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end end
test 'user with invalid unlock token should not be able to unlock the account via XML request' do test 'user with invalid unlock token should not be able to unlock the account via XML request' do
get user_unlock_path(format: 'xml', unlock_token: 'invalid_token') get user_unlock_path(format: 'xml', unlock_token: 'invalid_token')
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
test "when using json to ask a unlock request, should not return the user" do test "when using json to ask a unlock request, should not return the user" do

View File

@ -272,7 +272,7 @@ class PasswordTest < Devise::IntegrationTest
create_user create_user
post user_password_path(format: 'xml'), params: { user: {email: "invalid.test@test.com"} } post user_password_path(format: 'xml'), params: { user: {email: "invalid.test@test.com"} }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
test 'reset password request with invalid E-Mail in XML format should return empty and valid response' do test 'reset password request with invalid E-Mail in XML format should return empty and valid response' do
@ -300,7 +300,7 @@ class PasswordTest < Devise::IntegrationTest
request_forgot_password request_forgot_password
put user_password_path(format: 'xml'), params: { user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'} } put user_password_path(format: 'xml'), params: { user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'} }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
test 'change password with invalid new password in XML format should return invalid response' do test 'change password with invalid new password in XML format should return invalid response' do
@ -308,7 +308,7 @@ class PasswordTest < Devise::IntegrationTest
request_forgot_password request_forgot_password
put user_password_path(format: 'xml'), params: { user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'} } put user_password_path(format: 'xml'), params: { user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'} }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
test "when using json requests to ask a confirmable request, should not return the object" do test "when using json requests to ask a confirmable request, should not return the object" do

View File

@ -300,7 +300,7 @@ class RegistrationTest < Devise::IntegrationTest
test 'an admin sign up with valid information in XML format should return valid response' do test 'an admin sign up with valid information in XML format should return valid response' do
post admin_registration_path(format: 'xml'), params: { admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } } post admin_registration_path(format: 'xml'), params: { admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
admin = Admin.to_adapter.find_first(order: [:id, :desc]) admin = Admin.to_adapter.find_first(order: [:id, :desc])
assert_equal 'new_user@test.com', admin.email assert_equal 'new_user@test.com', admin.email
@ -309,7 +309,7 @@ class RegistrationTest < Devise::IntegrationTest
test 'a user sign up with valid information in XML format should return valid response' do test 'a user sign up with valid information in XML format should return valid response' do
post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } } post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
user = User.to_adapter.find_first(order: [:id, :desc]) user = User.to_adapter.find_first(order: [:id, :desc])
assert_equal 'new_user@test.com', user.email assert_equal 'new_user@test.com', user.email
@ -318,7 +318,7 @@ class RegistrationTest < Devise::IntegrationTest
test 'a user sign up with invalid information in XML format should return invalid response' do test 'a user sign up with invalid information in XML format should return invalid response' do
post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' } } post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' } }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
test 'a user update information with valid data in XML format should return valid response' do test 'a user update information with valid data in XML format should return valid response' do

View File

@ -31,7 +31,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
end end
test 'content type should be set to html' do test 'content type should be set to html' do
assert mail.content_type.include?('text/html') assert_includes mail.content_type, 'text/html'
end end
test 'send confirmation instructions to the user email' do test 'send confirmation instructions to the user email' do

View File

@ -35,7 +35,7 @@ class EmailChangedTest < ActionMailer::TestCase
end end
test 'content type should be set to html' do test 'content type should be set to html' do
assert mail.content_type.include?('text/html') assert_includes mail.content_type, 'text/html'
end end
test 'send email changed to the original user email' do test 'send email changed to the original user email' do

View File

@ -34,7 +34,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
end end
test 'content type should be set to html' do test 'content type should be set to html' do
assert mail.content_type.include?('text/html') assert_includes mail.content_type, 'text/html'
end end
test 'send confirmation instructions to the user email' do test 'send confirmation instructions to the user email' do

View File

@ -35,7 +35,7 @@ class UnlockInstructionsTest < ActionMailer::TestCase
end end
test 'content type should be set to html' do test 'content type should be set to html' do
assert mail.content_type.include?('text/html') assert_includes mail.content_type, 'text/html'
end end
test 'send unlock instructions to the user email' do test 'send unlock instructions to the user email' do

View File

@ -28,7 +28,7 @@ class ConfirmableTest < ActiveSupport::TestCase
confirmation_tokens = [] confirmation_tokens = []
3.times do 3.times do
token = create_user.confirmation_token token = create_user.confirmation_token
assert !confirmation_tokens.include?(token) refute_includes confirmation_tokens, token
confirmation_tokens << token confirmation_tokens << token
end end
end end

View File

@ -121,7 +121,7 @@ class LockableTest < ActiveSupport::TestCase
user = create_user user = create_user
user.lock_access! user.lock_access!
token = user.unlock_token token = user.unlock_token
assert !unlock_tokens.include?(token) refute_includes unlock_tokens, token
unlock_tokens << token unlock_tokens << token
end end
end end

View File

@ -18,7 +18,7 @@ class RecoverableTest < ActiveSupport::TestCase
user = create_user user = create_user
user.send_reset_password_instructions user.send_reset_password_instructions
token = user.reset_password_token token = user.reset_password_token
assert !reset_password_tokens.include?(token) refute_includes reset_password_tokens, token
reset_password_tokens << token reset_password_tokens << token
end end
end end

View File

@ -61,7 +61,7 @@ class ActionDispatch::IntegrationTest
# account Middleware redirects. # account Middleware redirects.
# #
def assert_redirected_to(url) def assert_redirected_to(url)
assert [301, 302].include?(@integration_session.status), assert_includes [301, 302], @integration_session.status,
"Expected status to be 301 or 302, got #{@integration_session.status}" "Expected status to be 301 or 302, got #{@integration_session.status}"
assert_url url, @integration_session.headers["Location"] assert_url url, @integration_session.headers["Location"]

View File

@ -104,9 +104,9 @@ class TestControllerHelpersTest < Devise::ControllerTestCase
get :index, params: { format: :xml } get :index, params: { format: :xml }
if Devise::Test.rails6? if Devise::Test.rails6?
assert response.media_type.include?('application/xml') assert_includes response.media_type, 'application/xml'
else else
assert response.content_type.include?('application/xml') assert_includes response.content_type, 'application/xml'
end end
end end