-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration tests for exception handling
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
RSpec.describe "handle exceptions", type: :cli do | ||
it "doesn't handle exceptions in development mode" do | ||
with_project do | ||
generate_action | ||
|
||
server do | ||
get '/books/1' | ||
|
||
expect(last_response.status).to eq(500) | ||
end | ||
end | ||
end | ||
|
||
it "doesn't handle exceptions in test mode" do | ||
with_project do | ||
generate_action | ||
|
||
RSpec::Support::Env['HANAMI_ENV'] = 'test' | ||
|
||
server do | ||
get '/books/1' | ||
|
||
expect(last_response.status).to eq(500) | ||
end | ||
end | ||
end | ||
|
||
it "handles exceptions in production mode" do | ||
with_project do | ||
generate_action | ||
|
||
RSpec::Support::Env['HANAMI_ENV'] = 'production' | ||
RSpec::Support::Env['DATABASE_URL'] = "file://#{Pathname.new('db').join('bookshelf')}" | ||
|
||
server do | ||
get '/books/1' | ||
|
||
expect(last_response.status).to eq(400) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def generate_action # rubocop:disable Metrics/MethodLength | ||
generate "action web books#show --url=/books/:id" | ||
|
||
rewrite "apps/web/controllers/books/show.rb", <<-EOF | ||
module Web::Controllers::Books | ||
class Show | ||
include Web::Action | ||
handle_exception ArgumentError => 400 | ||
def call(params) | ||
raise ArgumentError.new("oh nooooo") | ||
end | ||
end | ||
end | ||
EOF | ||
end | ||
end |