Last active
December 16, 2015 14:29
-
-
Save chuckg/5448992 to your computer and use it in GitHub Desktop.
Testing exceptions with Rack. Couldn't get it to work in conjunction with :driver => :selenium level tests, but it runs fine when run individually. Not 100% sure the tests are necessary given the tests around routes/controllers.
This file contains hidden or 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 'request_spec_helper' | |
describe "Errors" do | |
context "test", driver: :rack_test do | |
include Rack::Test::Methods | |
def app | |
app = Rack::Builder.new do | |
run Rewarder::Application | |
end.to_app | |
# We need these specifically for these tests, but I do not think that they | |
# are being applied correctly. | |
app.config.consider_all_requests_local = false | |
app.config.action_dispatch.show_exceptions = true | |
app | |
end | |
describe "for an invalid path error" do | |
describe "for text/html requests" do | |
before do | |
get '/invalid/path' | |
end | |
it "shows the not_found page to the user" do | |
expect(last_response.status).to eq(404) | |
expect(last_response.body).to match /Oops! There are no Rewards to be found here\./m | |
end | |
end | |
describe "for */* requests" do | |
before do | |
header('Accept', '*/*') | |
get '/invalid_image.png' | |
end | |
it "show an empty page to the user" do | |
expect(last_response.status).to eq(404) | |
expect(last_response.body.strip).to be_empty | |
end | |
end | |
end | |
describe "when an error occurs within ErrorsController" do | |
before do | |
ApplicationController.any_instance.stub(:set_cache_header).and_raise(StandardError.new('An error occured...')) | |
get '/' | |
end | |
it "shows the user our fall back error page" do | |
expect(last_response.status).to eq(500) | |
expect(last_response.body).to match /We're sorry, but something went terribly wrong/m | |
end | |
end | |
describe "for a conflict error" do | |
it "shows the internal_server_error page to the user" | |
end | |
describe "for an unprocessable entity error" do | |
it "shows the internal_server_error page to the user" | |
end | |
describe "for an internal server error" do | |
it "shows the internal_server_error page to the user" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment