File: errors_spec.rb

package info (click to toggle)
ruby-gaffe 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 204 kB
  • sloc: ruby: 221; makefile: 7
file content (35 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'spec_helper'

describe Gaffe::Errors do
  describe :Actions do
    describe :show do
      let(:request) { test_request }
      let(:env) { request.env.merge 'action_dispatch.exception' => exception }
      let(:status) { response.first }
      let(:body) { response.last.body }

      let(:response) do
        Gaffe.errors_controller_for_request(env).action(:show).call(env)
      end

      context 'with builtin exception' do
        let(:exception) { ActionController::RoutingError.new(:foo) }
        it { expect(status).to eql 404 }
        it { expect(body).to match(/Not Found/) }
      end

      context 'with custom exception and missing view' do
        before { ActionDispatch::ExceptionWrapper.rescue_responses.merge! exception_class.name => 'my_custom_error' }

        let(:exception_class) do
          Object.instance_eval { remove_const :MyCustomError } if Object.const_defined?(:MyCustomError)
          MyCustomError = Class.new(StandardError)
        end

        let(:exception) { exception_class.new }
        it { expect(status).to eql 500 }
        it { expect(body).to match(/Internal Server Error/) }
      end
    end
  end
end