How can I test rescue_from is RSpec? I’d like to make sure that if one of the exceptions is raised, that the controller correctly sets the flash and does the redirect. Is there a way to simulate the exception?
rescue_from PageAccessDenied do
flash[:alert] = "You do not have the necessary roles to access this page"
redirect_to root_url
end
rescue_from CanCan::AccessDenied do |exception|
flash[:alert] = exception.message
redirect_to root_url
end
Assuming that you have an
authorize!method that raises the exception, you should be able to do something like this: