diff options
| author | Stormwind <stormwind@stormwinds-page.de> | 2023-05-09 11:03:34 +0200 | 
|---|---|---|
| committer | Stormwind <stormwind@stormwinds-page.de> | 2023-05-09 12:37:15 +0200 | 
| commit | b582ca5d8aafdf9bfaccbe67c74aa532cbfc4f1a (patch) | |
| tree | fa5bd206af0191e5a002a6498d83bb50c8b61890 /spec | |
| parent | 8cb48215bfdc7352ea39ee2c7241bd4d87636198 (diff) | |
Add error handeling pages (primarily for 404)
Now you can add special error pages for http error codes.
Currently it works only for 404 errors. If a route is called, which
isn't defined, the framwork gave our a generic 404 error page.
Now you can redirect this error to a controller, which allowes you to
create a special error handling for that case yourself.
you just need to add a route "404 => MyErrorController" to your routing
list. If it's not defined, noting will change and the old error message
will be returned as beforehand.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/unit/zero/router/call_spec.rb | 14 | 
1 files changed, 13 insertions, 1 deletions
| diff --git a/spec/unit/zero/router/call_spec.rb b/spec/unit/zero/router/call_spec.rb index 835d51d..dabf664 100644 --- a/spec/unit/zero/router/call_spec.rb +++ b/spec/unit/zero/router/call_spec.rb @@ -9,6 +9,10 @@ describe Zero::Router, '#call' do    let(:wrong_app) do      lambda {|env| [200, {'Content-Type' => 'text/html'}, 'Wrong'] }    end + +  let(:not_found_app) do +    lambda {|env| [404, {'Content-Type' => 'text/html'}, ['Wrong way!']] } +  end    let(:app) { SpecApp }    shared_examples_for 'a sample app' do @@ -39,7 +43,7 @@ describe Zero::Router, '#call' do    end    context 'with nested routes' do -    let(:routes) {{ '/' => wrong_app, '/foo' => app, '/foo/bar' => wrong_app }} +    let(:routes) {{ '/foo/bar' => wrong_app, '/foo' => app, '/' => wrong_app }}      let(:env) { EnvGenerator.get('/foo') }      it_behaves_like "a sample app"    end @@ -76,6 +80,14 @@ describe Zero::Router, '#call' do      it_behaves_like "a sample app"    end +  context 'with a route not found, but 404 error route set' do +    let(:routes) {{ '/foo/bar/baz' => app, 404 => not_found_app }} +    let(:env) { EnvGenerator.get('/foo/bar') } +    let(:result) { ['Wrong way!'] } +    let(:status_code) { 404 } +    it_behaves_like "a sample app" +  end +    context 'with parameters' do      let(:routes) {{ '/foo/:id' => app }}      let(:env) { EnvGenerator.get('/foo/bar') } | 
