From 3dde7609e7c14ead995a1670d15029f8b1bc36e9 Mon Sep 17 00:00:00 2001 From: daming Date: Fri, 19 May 2023 11:55:14 +0800 Subject: [PATCH] first commit --- .gitignore | 12 ++++++++++++ .rspec | 2 ++ .travis.yml | 23 +++++++++++++++++++++++ Gemfile | 4 ++++ LICENSE.txt | 21 +++++++++++++++++++++ README.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Rakefile | 6 ++++++ bin/console | 14 ++++++++++++++ bin/setup | 8 ++++++++ exception_file_notifier.gemspec | 42 ++++++++++++++++++++++++++++++++++++++++++ gemfiles/Gemfile.rails_5.2 | 6 ++++++ gemfiles/Gemfile.rails_6.0 | 6 ++++++ gemfiles/Gemfile.rails_6.1 | 6 ++++++ lib/exception_file_notifier.rb | 2 ++ lib/exception_notifier/exception_file_notifier/version.rb | 5 +++++ lib/exception_notifier/file_notifier.rb | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/exception_notifier/exception_file_notifier_spec.rb | 7 +++++++ spec/exception_notifier/file_notifier_spec.rb | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/exception_test_helper.rb | 23 +++++++++++++++++++++++ spec/spec_helper.rb | 20 ++++++++++++++++++++ 20 files changed, 616 insertions(+), 0 deletions(-) create mode 100644 .gitignore create mode 100644 .rspec create mode 100644 .travis.yml create mode 100644 Gemfile create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 Rakefile create mode 100755 bin/console create mode 100755 bin/setup create mode 100644 exception_file_notifier.gemspec create mode 100644 gemfiles/Gemfile.rails_5.2 create mode 100644 gemfiles/Gemfile.rails_6.0 create mode 100644 gemfiles/Gemfile.rails_6.1 create mode 100644 lib/exception_file_notifier.rb create mode 100644 lib/exception_notifier/exception_file_notifier/version.rb create mode 100644 lib/exception_notifier/file_notifier.rb create mode 100644 spec/exception_notifier/exception_file_notifier_spec.rb create mode 100644 spec/exception_notifier/file_notifier_spec.rb create mode 100644 spec/exception_test_helper.rb create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8eb3b06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +/.bundle/ +/.yardoc +/Gemfile.lock +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ + +# rspec failure tracking +.rspec_status diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..8c18f1a --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--format documentation +--color diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..208a577 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +language: ruby +cache: bundler + +before_install: gem install bundler + +rvm: + - 3.0.0 + - 2.7.2 + - 2.6.6 + - 2.5.8 + - 2.4.10 +gemfile: + - gemfiles/Gemfile.rails_6.1 + - gemfiles/Gemfile.rails_6.0 + - gemfiles/Gemfile.rails_5.2 +jobs: + exclude: + - rvm: 3.0.0 + gemfile: gemfiles/Gemfile.rails_5.2.4 + - rvm: 2.4.10 + gemfile: gemfiles/Gemfile.rails_6.0 + - rvm: 2.4.10 + gemfile: gemfiles/Gemfile.rails_6.1 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..55f5ea5 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in exception_file_notifier.gemspec +gemspec diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..732f921 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Koji Onishi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d04fc79 --- /dev/null +++ b/README.md @@ -0,0 +1,93 @@ +# Exception File Notifier + +[![Gem Version](https://badge.fury.io/rb/exception_file_notifier.svg)](https://badge.fury.io/rb/exception_file_notifier) +[![Travis](https://api.travis-ci.org/fursich/exception_file_notifier.png)](http://travis-ci.org/fursich/exception_file_notifier) +[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) + +**Exception File Notifier** is a custom notifier for [Exception Notification](https://github.com/smartinez87/exception_notification), that records notifications onto a log file when errors occur in a Rack/Rails application. + +All the error logs are converted into JSON format. This would be useful typically when you wish to monitor an app with monitoring tools - e.g. Kibana + ElasticSearch + Fluentd, or anything alike. + +## Installation + +Add this line to your application's Gemfile: + +```ruby +gem 'exception_file_notifier' +``` + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install exception_file_notifier + +## Usage + +Set proper configs in *config/initializers/exception_notification.rb* + +To get started, use the simplest settings: + +```ruby:config/initializers/exception_notification.rb +ExceptionNotification.configure do |config| + + config.add_notifier :file, { + filename: "#{Rails.root}/log/exceptions.log" + } +``` + +That works in all the environment (including test). + +You could also customize settings like so: + +```ruby:config/initializers/exception_notification.rb +ExceptionNotification.configure do |config| + +# disable all the notifiers in certain environment + config.ignore_if do |exception, options| + Rails.env.test? + end + + config.add_notifier :file, { + filename: "#{Rails.root}/log/exceptions_#{Rails.env}.log", # generate different log files depending on environments + shift_age: 'daily' # use shift_age/shift_size options to rotate log files + } +``` + +You could also pass as many original values as you like, which will be evaluated JSON-ified at the time when an exception occurs. For detailed setting you may wish to consult with the Exception Notification [original readme](https://github.com/smartinez87/exception_notification). + +#### available options: + +- filename: specify the log file (preferablly with its absolute path) + +- shift_age: option for log file rotation: directly passed to Ruby Logger + +- shift_size: option for log file rotation: directly passed to Ruby Logger + +(for the latter options see also: https://docs.ruby-lang.org/ja/latest/method/Logger/s/new.html) + +#### Note + +Due to [a bug](https://bugs.ruby-lang.org/issues/12948) with ruby Logger discovered in ruby 2.2 - 2.3, it might happen that you cannot rotate logs by using shift_age. (for those who come up with any workaround for this, please let us know / PR are welcomed) + +Meanwhile you could cope with either 1) upgrading your ruby version upto 2.4, or 2) rotate logs by size, not date + +## Development + +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. + +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). + +## Contributing + +Bug reports and pull requests are welcome on GitHub at https://github.com/fursich/exception_file_notifier. + +## Special Thanks To + +All the folks who have given supports, especially @motchang and @katsurak for great advises and reviews. + +## License + +The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..b7e9ed5 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +task :default => :spec diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..422d8b3 --- /dev/null +++ b/bin/console @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +require "bundler/setup" +require "exception_file_notifier" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/exception_file_notifier.gemspec b/exception_file_notifier.gemspec new file mode 100644 index 0000000..b372352 --- /dev/null +++ b/exception_file_notifier.gemspec @@ -0,0 +1,42 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'exception_notifier/exception_file_notifier/version' + +Gem::Specification.new do |spec| + spec.name = "exception_file_notifier" + spec.version = ::ExceptionNotifier::ExceptionFileNotifier::VERSION + spec.authors = ["Koji Onishi"] + spec.email = ["fursich0@gmail.com"] + + spec.summary = %q{ A custom notifier for ExceptionNotification that generates exception log files in JSON format. } + spec.description = %q{ Exception File Notifier records exception logs in JSON format, helping you track errors in the production environment. } + spec.homepage = "https://github.com/fursich/exception_file_notifier" + spec.license = "MIT" + + # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' + # to allow pushing to a single host or delete this section to allow pushing to any host. + # if spec.respond_to?(:metadata) + # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' + # else + # raise "RubyGems 2.0 or newer is required to protect against " \ + # "public gem pushes." + # end + + spec.files = `git ls-files -z`.split("\x0").reject do |f| + f.match(%r{^(test|spec|features)/}) + end + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] + + spec.required_ruby_version = '>= 2.3' + spec.required_rubygems_version = '>= 1.8.11' + spec.add_dependency "exception_notification", ">= 4.0" + spec.add_dependency("activesupport", ">= 4.0", "<7") + + spec.add_development_dependency "bundler", ">= 2" + spec.add_development_dependency "rake", ">= 10.0" + spec.add_development_dependency "rspec", ">= 3.10" + spec.add_development_dependency "pry" +end diff --git a/gemfiles/Gemfile.rails_5.2 b/gemfiles/Gemfile.rails_5.2 new file mode 100644 index 0000000..629522e --- /dev/null +++ b/gemfiles/Gemfile.rails_5.2 @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in dumped_railers.gemspec +gem 'activesupport', '5.2.4.4' + +gemspec path: '../' diff --git a/gemfiles/Gemfile.rails_6.0 b/gemfiles/Gemfile.rails_6.0 new file mode 100644 index 0000000..c83bbc0 --- /dev/null +++ b/gemfiles/Gemfile.rails_6.0 @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in dumped_railers.gemspec +gem 'activesupport', '6.0.3.4' + +gemspec path: '../' diff --git a/gemfiles/Gemfile.rails_6.1 b/gemfiles/Gemfile.rails_6.1 new file mode 100644 index 0000000..fb26c3d --- /dev/null +++ b/gemfiles/Gemfile.rails_6.1 @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in dumped_railers.gemspec +gem 'activesupport', '6.1.0' + +gemspec path: '../' diff --git a/lib/exception_file_notifier.rb b/lib/exception_file_notifier.rb new file mode 100644 index 0000000..1fa0e37 --- /dev/null +++ b/lib/exception_file_notifier.rb @@ -0,0 +1,2 @@ +require "exception_notifier/exception_file_notifier/version" +require "exception_notifier/file_notifier" diff --git a/lib/exception_notifier/exception_file_notifier/version.rb b/lib/exception_notifier/exception_file_notifier/version.rb new file mode 100644 index 0000000..e16549d --- /dev/null +++ b/lib/exception_notifier/exception_file_notifier/version.rb @@ -0,0 +1,5 @@ +module ExceptionNotifier + module ExceptionFileNotifier + VERSION = "0.1.0".freeze + end +end diff --git a/lib/exception_notifier/file_notifier.rb b/lib/exception_notifier/file_notifier.rb new file mode 100644 index 0000000..0e6cae2 --- /dev/null +++ b/lib/exception_notifier/file_notifier.rb @@ -0,0 +1,155 @@ +require "exception_notification" +require "action_dispatch" +require "active_support/core_ext/hash" +require "socket" +require 'logger' +require 'json' + +module ExceptionNotifier + class FileNotifier < BaseNotifier + include ExceptionNotifier::BacktraceCleaner + + def initialize(options={}) + filename = options[:filename] || "log/error.log" + shift_age = options[:shift_age] || 0 + shift_size = options[:shift_size] || nil + + @logger_options = [filename, shift_age, shift_size] + @formatter = -> (_, _, _, message) { message + "\n" } + end + + def call(exception=nil, options={}) + append_log exception_message(options[:env], exception, options) + end + + def append_log(message) + log = ::Logger.new(*@logger_options) + log.formatter = @formatter + error_log = generate_json(message) + log.error(error_log) + log.close + end + + def generate_json(message) + ::JSON.generate(deep_encode(message)) + end + + def exception_message(env, exception, options={}) + return error_message(exception) unless exception.is_a?(Exception) + + if env.present? + exception_notification(options[:env], exception, options) + else + background_exception_notification(exception, options) + end + end + + def exception_notification(env, exception, options) + @env = env + @exception = exception + @options = options.reverse_merge(@env['exception_notifier.options'] || {}).symbolize_keys + @kontroller = @env['action_controller.instance'] || MissingController.new + @request = ::ActionDispatch::Request.new(@env) + @backtrace = exception.backtrace ? clean_backtrace(exception) : [] + @timestamp = ::Time.current + @data = (@env['exception_notifier.exception_data'] || {}).merge(options[:data] || {}) + + render_notice + end + + def background_exception_notification(exception, options) + @exception = exception + @options = options.symbolize_keys + @backtrace = exception.backtrace || [] + @timestamp = ::Time.current + @data = options[:data] || {} + @env = @kontroller = nil + + render_notice + end + + def error_message(exception) + { + message: '[FATAL] NO EXCEPTION GIVEN: Please provide Exception as argument', + exception: exception.try(:to_s), + timestamp: ::Time.current, + } + end + + def render_notice + set_data_variables + + exception_details = { + exception: @exception.class, + controller: @kontroller.present? ? @kontroller.controller_name : '[BACKGROUND]', + action: @kontroller.present? ? @kontroller.action_name : '[BACKGROUND]', + exception_message: @exception.message, + + timestamp: @timestamp, + server: ::Socket.gethostname, + rails_root: (defined?(::Rails) && ::Rails.respond_to?(:root) ) ? ::Rails.root : nil, + process: $$, + backtrace: @backtrace, + } + + if @env.present? + exception_details.merge!({ + url: @request.url, + http_method: @request.request_method, + ip_address: @request.remote_ip, + parameters: (@request.filtered_parameters.inspect rescue "[NOT ENCODABLE]"), + session_id: (@request.ssl? ? "[FILTERED]" : @request.session['session_id'] || (@request.env["rack.session.options"] and @request.env["rack.session.options"][:id])), + session_data: @request.session.to_hash, + }) + filtered_env = @request.filtered_env + filtered_env.sort_by { |key, _| key.to_s }.each do |key, value| + exception_details[key] = value + end + end + + exception_details.merge!({ + data: @data, + }) + + exception_details + end + + class MissingController + def controller_name + '[NO CONTROLLER]' + end + def action_name + '[NO CONTROLLER]' + end + def method_missing(*args, &block) + end + end + + def set_data_variables + @data.each do |name, value| + instance_variable_set("@#{name}", value) + end + end + + def deep_encode(obj) + case obj + when Array + obj.map { |o| deep_encode(o) } + when Hash + deep_encode(obj.to_a).to_h + when String + encode_to_utf8(obj) + else + obj.respond_to?(:to_s) ? encode_to_utf8(obj.to_s) : '[NOT ENCODABLE]' + end + end + + def encode_to_utf8(str) + quick_sanitization(str).encode(::Encoding.find('UTF-8'), invalid: :replace, undef: :replace, replace: '?') + end + + def quick_sanitization(str) # stringify any random objects in a safe (and convenient) manner + str.inspect.gsub(/\A\"(.*)\"\z/,'\1') + end + end +end diff --git a/spec/exception_notifier/exception_file_notifier_spec.rb b/spec/exception_notifier/exception_file_notifier_spec.rb new file mode 100644 index 0000000..45f3245 --- /dev/null +++ b/spec/exception_notifier/exception_file_notifier_spec.rb @@ -0,0 +1,7 @@ +require "spec_helper" + +RSpec.describe ExceptionNotifier::ExceptionFileNotifier do + it "has a version number" do + expect(ExceptionNotifier::ExceptionFileNotifier::VERSION).not_to be nil + end +end diff --git a/spec/exception_notifier/file_notifier_spec.rb b/spec/exception_notifier/file_notifier_spec.rb new file mode 100644 index 0000000..8cac6d6 --- /dev/null +++ b/spec/exception_notifier/file_notifier_spec.rb @@ -0,0 +1,161 @@ +require "spec_helper" +require "exception_test_helper" + +RSpec.describe ExceptionNotifier::FileNotifier do + include ExceptionTestHelper + + let(:notifier) { + ExceptionNotifier::FileNotifier.new( + options + ) + } + + let(:options) { + { + filename: filename, + shift_age: shift_age, + shift_size: shift_size, + }.compact + } + + let(:filename) { 'log/exceptions.log' } + let(:shift_age) { 'daily' } + let(:shift_size) { nil } + + describe '#initialize' do + let(:logger_options) { + notifier.instance_eval {@logger_options} + } + it 'constructs the right file name based on given options' do + expect(logger_options).to contain_exactly(filename, shift_age, shift_size) + end + end + + describe '#generate_json' do + context 'in case broken strings are given' do + let (:hash_with_broken_codes) { + { + French: 'La langue française'.force_encoding('ASCII'), + Russian: 'Русский язык'.encode('WINDOWS-31J').force_encoding('UTF-16'), + Japanese: {'日本語'.encode('UTF-8').force_encoding('WINDOWS-31J') => 'にほんご'.force_encoding('ASCII') }, + } + } + + it 'jasonifies the strings properly without causing errors' do + expect( JSON.parse(notifier.generate_json(hash_with_broken_codes)) ).to eq( + { + "French"=>"La langue fran\\xC3\\xA7aise", + "Russian"=>"\\x84\\x51\\x84\\x85\\x84\\x83\\x84\\x83\\x84\\x7B\\x84\\x79\\x84\\x7A\\x20\\x84\\x91\\x84\\x78\\x84\\x8D\\x84\\x7B", + "Japanese" => {"\\x{E697}\\xA5\\x{E69C}\\xAC\\x{E8AA}\\x9E"=>"\\xE3\\x81\\xAB\\xE3\\x81\\xBB\\xE3\\x82\\x93\\xE3\\x81\\x94"}, + } + ) + end + end + end + + describe '#call' do + let (:backtrace) { + [ + %(/test/app/controllers/api/dummy_controller.rb:123:in `build_whatever_params'), + %(/test/app/controllers/api/dummy_controller.rb:321:in `any_random_loop'), + ] + } + + context 'with env options' do + let (:env) { + { "rack.version" => [1, 2], + "action_controller.instance" => ExceptionTestHelper::DummyController.new, + "REQUEST_METHOD" => "GET", + "SERVER_NAME" => "example.org", + "SERVER_PORT" => "80", + "PATH_INFO" => "/category", + "rack.url_scheme" => "http", + "REMOTE_ADDR" => "127.0.0.1", + "HTTP_HOST" => "example.org", + } + } + + it 'indicates the exception' do + expect(notifier).to receive(:append_log).with( + hash_including( + exception: ExceptionTestHelper::DummyException, + exception_message: 'Dummy Exception Message' + ) + ).once + notifier.call(ExceptionTestHelper::DummyException.new(backtrace), env: env) + end + + it 'provides controller and action name' do + expect(notifier).to receive(:append_log).with( + hash_including( + controller: 'DummyController', + action: 'TestAction' + ) + ).once + notifier.call(ExceptionTestHelper::DummyException.new(backtrace), env: env) + end + + it 'provides url' do + expect(notifier).to receive(:append_log).with( + hash_including( + url: "http://example.org/category" + ) + ).once + notifier.call(ExceptionTestHelper::DummyException.new(backtrace), env: env) + end + + it 'provides backtrace' do + expect(notifier).to receive(:append_log).with( + hash_including(backtrace: backtrace) + ).once + notifier.call(ExceptionTestHelper::DummyException.new(backtrace), env: env) + end + end + + context 'without controller' do + let (:env) { + { "rack.version" => [1, 2], + "REQUEST_METHOD" => "GET", + "SERVER_NAME" => "example.org", + "SERVER_PORT" => "80", + "PATH_INFO" => "/category", + "rack.url_scheme" => "http", + "REMOTE_ADDR" => "127.0.0.1", + "HTTP_HOST" => "example.org", + } + } + it 'does not provide controller and action name' do + expect(notifier).to receive(:append_log).with( + hash_including( + controller: '[NO CONTROLLER]', + action: '[NO CONTROLLER]' + ) + ).once + notifier.call(ExceptionTestHelper::DummyException.new(backtrace), env: env) + end + end + + context 'without env options' do + it 'indicates the exception' do + expect(notifier).to receive(:append_log).with( + hash_including( + exception: ExceptionTestHelper::DummyException, + exception_message: 'Dummy Exception Message' + ) + ) + notifier.call(ExceptionTestHelper::DummyException.new) + end + + it 'does not provide controller and action name' do + expect(notifier).to receive(:append_log).with( + hash_including( + controller: '[BACKGROUND]', + action: '[BACKGROUND]' + ) + ) + notifier.call(ExceptionTestHelper::DummyException.new) + end + end + end + +end diff --git a/spec/exception_test_helper.rb b/spec/exception_test_helper.rb new file mode 100644 index 0000000..cde0b63 --- /dev/null +++ b/spec/exception_test_helper.rb @@ -0,0 +1,23 @@ +module ExceptionTestHelper + + class DummyException < Exception + def initialize(backtrace = nil) + super + set_backtrace(backtrace) + end + + def message + 'Dummy Exception Message' + end + end + + class DummyController + def controller_name + 'DummyController' + end + + def action_name + 'TestAction' + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..15eb877 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,20 @@ +require "bundler/setup" +require "exception_file_notifier" +require 'exception_notification' + +if RUBY_VERSION >= '2.7.2' + # NOTE: https://bugs.ruby-lang.org/issues/17000 + # this will keep us informed of deprecation warnings after Ruby 2.7.2 + Warning[:deprecated] = true +end + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end + +# ENV["RAILS_ENV"] = "test" -- libgit2 0.21.0