Skip to content

Commit

Permalink
Integration tests for exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Sep 30, 2016
1 parent 40f57c4 commit 130d435
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions spec/integration/handle_exceptions_spec.rb
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

0 comments on commit 130d435

Please sign in to comment.