Skip to content

Commit

Permalink
Adding spec for error raising with raise: true option
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Apr 5, 2014
1 parent b63165e commit 8f38f96
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ By default, when a parameter precondition fails, `Sinatra::Param` will `halt 400
}
```

To change this, you can set `:raise_sinatra_param_exceptions` to `true`, and intercept `Sinatra::Param::InvalidParameterError` with a Sinatra `error do...end` block. (To make this work in development, set `:show_exceptions` to `false`):
To change this, you can set `:raise_sinatra_param_exceptions` to `true`, and intercept `Sinatra::Param::InvalidParameterError` with a Sinatra `error do...end` block. (To make this work in development, set `:show_exceptions` to `false` and `:raise_errors` to `true`):

```ruby
set :raise_sinatra_param_exceptions, true
Expand Down
11 changes: 10 additions & 1 deletion spec/dummy/app.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
require 'sinatra/base'
require 'sinatra/param'
require 'json'
require 'date'
require 'time'
require 'json'

class App < Sinatra::Base
helpers Sinatra::Param

set :show_exceptions, false
set :raise_errors, true

before do
content_type :json
end
Expand Down Expand Up @@ -182,4 +186,9 @@ class App < Sinatra::Base
message: 'OK'
}.to_json
end

get '/raise' do
param :arg, String, required: true, raise: true
params.to_json
end
end
11 changes: 11 additions & 0 deletions spec/parameter_raise_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper'

describe 'Exception' do
describe 'raise' do
it 'should raise error when option is specified' do
expect {
get('/raise')
}.to raise_error
end
end
end

0 comments on commit 8f38f96

Please sign in to comment.