spec/integration/sinatra_spec.rb in loga-2.1.1 vs spec/integration/sinatra_spec.rb in loga-2.1.2

- old
+ new

@@ -1,7 +1,28 @@ require 'spec_helper' +class MySinatraApp < Sinatra::Base + set :logging, :false + + get '/ok' do + 'Hello Sinatra' + end + + get '/error' do + nil.name + end + + post '/users' do + content_type :json + params.to_json + end + + get '/new' do + redirect '/ok' + end +end + RSpec.describe 'Structured logging with Sinatra', timecop: true do let(:io) { StringIO.new } let(:format) {} before do Loga.reset @@ -12,44 +33,20 @@ service_name: 'hello_world_app', service_version: '1.0', tags: [:uuid, 'TEST_TAG'], ) end + let(:last_log_entry) do io.rewind JSON.parse(io.read) end let(:app) do - Class.new(Sinatra::Base) do - # Disable show_exceptions and rely on user defined exception handlers - # (e.i. the error blocks) - set :show_exceptions, false - + Rack::Builder.new do use Loga::Rack::RequestId use Loga::Rack::Logger - - error do - status 500 - body 'Ooops' - end - - get '/ok' do - 'Hello Sinatra' - end - - get '/error' do - nil.name - end - - post '/users' do - content_type :json - params.to_json - end - - get '/new' do - redirect '/ok' - end + run MySinatraApp end end context 'when RACK_ENV is production', if: ENV['RACK_ENV'].eql?('production') do let(:format) { :gelf }