Created
January 6, 2014 13:47
-
-
Save pixeltrix/8283082 to your computer and use it in GitHub Desktop.
Test handling of exceptions in integration tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'action_controller/railtie' | |
require 'minitest/autorun' | |
class TestApplication < Rails::Application | |
config.eager_load = false | |
config.root = File.dirname(__FILE__) | |
config.session_store :cookie_store, key: 'cookie_store_key' | |
config.secret_token = 'secret_token' | |
config.secret_key_base = 'secret_key_base' | |
end | |
Rails.logger = Logger.new(StringIO.new) | |
TestApplication.initialize! | |
TestApplication.routes.draw do | |
root to: 'pages#index' | |
end | |
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
end | |
class PagesController < ApplicationController | |
def index | |
raise ActionController::BadRequest | |
end | |
end | |
class ExceptionsTest < ActionDispatch::IntegrationTest | |
def test_application_handles_exceptions | |
get '/' | |
assert_response :bad_request | |
end | |
def test_exceptions_bubble_up | |
assert_raises(ActionController::BadRequest){ get '/' } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment