crashbreak 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/Rakefile +4 -0
  4. data/crashbreak.gemspec +6 -0
  5. data/lib/crashbreak.rb +28 -0
  6. data/lib/crashbreak/config/configurable.rb +12 -0
  7. data/lib/crashbreak/config/configurator.rb +15 -0
  8. data/lib/crashbreak/exception_catcher_middleware.rb +34 -0
  9. data/lib/crashbreak/exception_notifier.rb +25 -0
  10. data/lib/crashbreak/exceptions_repository.rb +27 -0
  11. data/lib/crashbreak/formatters/basic_formatter.rb +18 -0
  12. data/lib/crashbreak/formatters/basic_information_formatter.rb +7 -0
  13. data/lib/crashbreak/formatters/default_summary_formatter.rb +13 -0
  14. data/lib/crashbreak/formatters/environment_variables_formatter.rb +9 -0
  15. data/lib/crashbreak/formatters/hash_formatter.rb +17 -0
  16. data/lib/crashbreak/formatters/summary_formatter.rb +11 -0
  17. data/lib/crashbreak/version.rb +1 -1
  18. data/lib/dumpers/program_name_dumper.rb +16 -0
  19. data/lib/generators/crashbreak/install_generator.rb +12 -0
  20. data/lib/generators/crashbreak/templates/crashbreak.rb +6 -0
  21. data/lib/restorers/program_name_restorer.rb +7 -0
  22. data/lib/tasks/crashbreak.rake +16 -0
  23. data/spec/dumpers/program_name_dumper_spec.rb +12 -0
  24. data/spec/features/sending_error_report_spec.rb +39 -0
  25. data/spec/lib/config/configurable_spec.rb +19 -0
  26. data/spec/lib/config/configurator_spec.rb +11 -0
  27. data/spec/lib/exception_catcher_middleware_spec.rb +43 -0
  28. data/spec/lib/exception_notifier_spec.rb +43 -0
  29. data/spec/lib/exceptions_repository_spec.rb +26 -0
  30. data/spec/lib/formatters/basic_formatter_spec.rb +25 -0
  31. data/spec/lib/formatters/default_summary_formatter_spec.rb +22 -0
  32. data/spec/lib/formatters/group_formatter_spec.rb +15 -0
  33. data/spec/lib/formatters/summary_formatter_spec.rb +13 -0
  34. data/spec/lib/generators/install_generator_spec.rb +16 -0
  35. data/spec/restorers/program_name_restorer_spec.rb +11 -0
  36. data/spec/spec_helper.rb +3 -0
  37. data/spec/support/test_error.rb +3 -0
  38. data/spec/support/test_error_formatter.rb +7 -0
  39. metadata +119 -6
  40. data/spec/lib/version_spec.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f05066aa0476fd9df3398d1994c16258405ec53c
4
- data.tar.gz: 506c480a0d737200e3a20cbf2138affb59ec1952
3
+ metadata.gz: 3419000b580aee39142c18531d6386d2fc7835df
4
+ data.tar.gz: af8c9aa9154afc6bdeda323201ff02770f9dce6d
5
5
  SHA512:
6
- metadata.gz: 11c1ee456e8e9b62b2fd0d19dc39f178820269f6328b3c86838f818a18d5b7f695688f764b2d6d2d5d909a1b7110c554221517d501c0d870921fdb48668652d1
7
- data.tar.gz: 1a1fe2e90464171736af5088ff0bd2daea011b93ef4a4637dd09b4c9ea2d746e297d406d6997a3fbc479d3ccc3d9a8f3d6ef734814d7d4caa38fd6b181da035d
6
+ metadata.gz: 6977054a05204a526704da6109bce67dddd3b6deba56a26575039b58b7c1ab05abd9156326b0d0e32a156f1612b2b3b9d4b083973b6be737f408206952f11467
7
+ data.tar.gz: 5256c559a99c8e87c14b80110579de662f28325bb8865c512fa7195e24c5ca33d0bbe49385be13344e1ed349d4170c51dfe97f2de2484177da94f70b890f59a2
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ group :test do
6
+ gem 'generator_spec', git: 'git@github.com:substantial/generator_spec.git', branch: 'fix-for-rspec-3'
7
+ end
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
2
 
3
+ desc 'Open an irb session preloaded with this library'
4
+ task :console do
5
+ sh 'irb -rubygems -I lib -r crashbreak.rb'
6
+ end
@@ -19,4 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.add_development_dependency 'bundler', '~> 1.6'
20
20
  spec.add_development_dependency 'rake'
21
21
  spec.add_development_dependency 'rspec'
22
+ spec.add_development_dependency 'rails'
23
+ spec.add_development_dependency 'webmock'
24
+ spec.add_development_dependency 'simplecov'
25
+
26
+ spec.add_runtime_dependency 'faraday', '>= 0'
27
+ spec.add_runtime_dependency 'request_store', '>= 0'
22
28
  end
@@ -1,4 +1,32 @@
1
+ require 'rails'
2
+ require 'faraday'
3
+ require 'request_store'
1
4
  require 'crashbreak/version'
5
+ require 'crashbreak/exception_notifier'
6
+ require 'crashbreak/formatters/basic_formatter'
7
+ require 'crashbreak/formatters/summary_formatter'
8
+ require 'crashbreak/formatters/hash_formatter'
9
+ require 'crashbreak/formatters/basic_information_formatter'
10
+ require 'crashbreak/formatters/environment_variables_formatter'
11
+ require 'crashbreak/formatters/default_summary_formatter'
12
+ require 'crashbreak/config/configurator'
13
+ require 'crashbreak/config/configurable'
14
+ require 'crashbreak/exception_catcher_middleware'
15
+ require 'crashbreak/exceptions_repository'
16
+
17
+ require 'dumpers/program_name_dumper'
18
+ require 'restorers/program_name_restorer'
2
19
 
3
20
  module Crashbreak
21
+ extend Configurable
22
+
23
+ class Railtie < ::Rails::Railtie
24
+ initializer 'crashbreak.add_middleware' do
25
+ Rails.application.middleware.use Crashbreak::ExceptionCatcherMiddleware
26
+ end
27
+
28
+ rake_tasks do
29
+ load 'tasks/crashbreak.rake'
30
+ end
31
+ end
4
32
  end
@@ -0,0 +1,12 @@
1
+ module Crashbreak
2
+ module Configurable
3
+ def configure
4
+ yield configurator if block_given?
5
+ configurator
6
+ end
7
+
8
+ def configurator
9
+ @@configurator ||= Configurator.new
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Crashbreak
2
+ class Configurator
3
+ attr_accessor :api_key
4
+ attr_accessor :exception_notifier
5
+ attr_accessor :error_serializers
6
+
7
+ def exception_notifier
8
+ @exception_notifier || ExceptionNotifier.new
9
+ end
10
+
11
+ def error_serializers
12
+ @error_serializers || []
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ module Crashbreak
2
+ class ExceptionCatcherMiddleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ begin
9
+ @app.call(env)
10
+ rescue ::Exception => exception
11
+ RequestStore.store[:exception] = exception
12
+ store_variables_from_env env
13
+
14
+ exception_notifier.notify
15
+ raise
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def exception_notifier
22
+ Crashbreak.configure.exception_notifier
23
+ end
24
+
25
+ def store_variables_from_env(env)
26
+ RequestStore.store[:request] = request(env)
27
+ RequestStore.store[:controller] = env['action_controller.instance']
28
+ end
29
+
30
+ def request(env)
31
+ Rack::Request.new(env)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ module Crashbreak
2
+ class ExceptionNotifier
3
+ def notify
4
+ exceptions_repository.create serialize_exception
5
+ end
6
+
7
+ private
8
+
9
+ def serialize_exception
10
+ {}.tap do |exception_hash|
11
+ serializers.each do |serializer|
12
+ exception_hash.deep_merge!(serializer.serialize)
13
+ end
14
+ end
15
+ end
16
+
17
+ def serializers
18
+ [BasicInformationFormatter.new] + Crashbreak.configure.error_serializers
19
+ end
20
+
21
+ def exceptions_repository
22
+ @exceptions_repository ||= ExceptionsRepository.new
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ module Crashbreak
2
+ class ExceptionsRepository
3
+ BASE_URL = 'http://crashbreak.herokuapp.com/api'
4
+
5
+ def create(error_report_hash)
6
+ connection.post do |req|
7
+ req.url request_url
8
+ req.body = error_report_hash.to_json
9
+ req.headers['Content-Type'] = 'application/json'
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def connection
16
+ Faraday.new(url: request_url)
17
+ end
18
+
19
+ def request_url
20
+ "#{BASE_URL}/projects/#{project_token}/errors"
21
+ end
22
+
23
+ def project_token
24
+ Crashbreak.configure.api_key
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ module Crashbreak
2
+ class BasicFormatter
3
+
4
+ protected
5
+
6
+ def exception
7
+ RequestStore.store[:exception]
8
+ end
9
+
10
+ def request
11
+ RequestStore.store[:request]
12
+ end
13
+
14
+ def controller
15
+ RequestStore.store[:controller]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module Crashbreak
2
+ class BasicInformationFormatter < BasicFormatter
3
+ def serialize
4
+ { name: exception.class.to_s, message: exception.message, backtrace: exception.backtrace, environment: ENV['RACK_ENV'] }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module Crashbreak
2
+ class DefaultSummaryFormatter < SummaryFormatter
3
+ def summary
4
+ {
5
+ action: request.env['PATH_INFO'],
6
+ controller_name: controller.class.to_s,
7
+ file: exception.backtrace[0],
8
+ url: request.env['REQUEST_URI'],
9
+ user_agent: request.env['HTTP_USER_AGENT']
10
+ }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Crashbreak
2
+ class EnvironmentVariablesFormatter < HashFormatter
3
+ hash_name :environment
4
+
5
+ def hash_value
6
+ ENV.to_hash
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Crashbreak
2
+ class HashFormatter < BasicFormatter
3
+ class << self
4
+ def hash_name(value)
5
+ @hash_name = value
6
+ end
7
+
8
+ def get_hash_name
9
+ @hash_name
10
+ end
11
+ end
12
+
13
+ def serialize
14
+ { additional_data: { self.class.get_hash_name => hash_value } }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Crashbreak
2
+ class SummaryFormatter < BasicFormatter
3
+ def serialize
4
+ { summary: summary }
5
+ end
6
+
7
+ def summary
8
+ {}
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Crashbreak
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,16 @@
1
+ module Crashbreak
2
+ class ProgramNameDumper
3
+ def dump
4
+ dump_file.tap do |file|
5
+ file.puts $PROGRAM_NAME
6
+ file.close
7
+ end
8
+ end
9
+
10
+ private
11
+
12
+ def dump_file
13
+ File.new('program_name.dump', 'w')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Crashbreak
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ argument :token, type: :string
6
+
7
+ def create_initializer_file
8
+ template 'crashbreak.rb', 'config/initializers/crashbreak.rb'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ Crashbreak.configure do |config|
2
+ config.api_key = '<%= token %>'
3
+
4
+ # Specify what will be sent to the server by attaching own formatters.
5
+ config.error_serializers = [Crashbreak::DefaultSummaryFormatter.new, Crashbreak::EnvironmentVariablesFormatter.new]
6
+ end
@@ -0,0 +1,7 @@
1
+ module Crashbreak
2
+ class ProgramNameRestorer
3
+ def restore
4
+ $PROGRAM_NAME = File.readlines('program_name.dump')[0]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ namespace :crashbreak do
2
+ task test: :environment do
3
+ puts 'Testing communication with server...'
4
+
5
+ begin
6
+ raise CrashbreakTestError.new('If you see this message everything works fine!')
7
+ rescue CrashbreakTestError => error
8
+ Crashbreak.configure.exception_notifier.notify error
9
+ end
10
+
11
+ puts 'Done, now check if error exists on crashbreak.com!'
12
+ end
13
+ end
14
+
15
+ class CrashbreakTestError < StandardError
16
+ end
@@ -0,0 +1,12 @@
1
+ describe Crashbreak::ProgramNameDumper do
2
+ subject { described_class.new }
3
+ let(:file_path) { subject.dump.path }
4
+
5
+ it 'file name should be relevant to class' do
6
+ expect(File.basename(file_path)).to eq 'program_name.dump'
7
+ end
8
+
9
+ it 'checks file content' do
10
+ expect(File.read(file_path)).to match $PROGRAM_NAME
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ describe 'Sending error report to server' do
2
+ let(:catching_middleware) { Crashbreak::ExceptionCatcherMiddleware.new crashing_app}
3
+ let(:crashing_app) { double(:crashing_app)}
4
+
5
+ let(:project_token) { 'example_project_token' }
6
+ let(:example_error) { TestError.new }
7
+ let(:example_request) { double(:example_request, env: { 'PATH_INFO' => 'example_action_name', 'REQUEST_URI' => 'url', 'HTTP_USER_AGENT' => 'agent' } )}
8
+ let(:summary_formatter) { Crashbreak::DefaultSummaryFormatter.new }
9
+ let(:example_controller) { double(:example_controller) }
10
+ let(:env) { Hash['action_controller.instance' => example_controller ]}
11
+
12
+ before(:each) do
13
+ Crashbreak.configure.api_key = project_token
14
+ Crashbreak.configure.error_serializers = [summary_formatter, Crashbreak::EnvironmentVariablesFormatter.new, TestErrorFormatter.new]
15
+
16
+ allow(crashing_app).to receive(:call).and_raise(example_error)
17
+ allow(example_error).to receive(:backtrace).and_return(%w(example backtrace))
18
+ allow(summary_formatter).to receive(:request).and_return(example_request)
19
+ end
20
+
21
+ let!(:create_exception_request) do
22
+ stub_request(:post, "#{Crashbreak::ExceptionsRepository::BASE_URL}/projects/#{project_token}/errors").
23
+ with(body: error_report_hash.to_json).to_return(status: 200)
24
+ end
25
+
26
+ let(:error_report_hash) do
27
+ {
28
+ name: example_error.to_s, message: example_error.message, backtrace: example_error.backtrace, environment: 'test',
29
+ summary: { action: example_request.env['PATH_INFO'], controller_name: example_controller.class.to_s,
30
+ file: example_error.backtrace[0], url: example_request.env['REQUEST_URI'], user_agent: example_request.env['HTTP_USER_AGENT'] },
31
+ additional_data: { environment: ENV.to_hash, test: { formatter: true } }
32
+ }
33
+ end
34
+
35
+ it 'sends error report on exception' do
36
+ expect{ catching_middleware.call(env) }.to raise_error(TestError)
37
+ expect(create_exception_request).to have_been_made
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ describe Crashbreak::Configurable do
2
+ subject do
3
+ module TestModule
4
+ extend Crashbreak::Configurable
5
+ end
6
+ end
7
+
8
+ it 'returns configurator object' do
9
+ expect(subject.configure).to be_a_kind_of(Crashbreak::Configurator)
10
+ end
11
+
12
+ it 'pass configurator object to block' do
13
+ expect{|block| subject.configure(&block)}.to yield_with_args(Crashbreak::Configurator)
14
+ end
15
+
16
+ it 'creates only once configurator instance' do
17
+ expect(subject.configure).to eq subject.configure
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ describe Crashbreak::Configurator do
2
+ subject { described_class.new }
3
+
4
+ let(:example_api_key) { 'example_api_key' }
5
+
6
+ it 'sets api key' do
7
+ expect do
8
+ subject.api_key = example_api_key
9
+ end.to change{ subject.api_key }.from(nil).to(example_api_key)
10
+ end
11
+ end
@@ -0,0 +1,43 @@
1
+ describe Crashbreak::ExceptionCatcherMiddleware do
2
+ let(:app_with_crashes) { double(:app_with_crashes)}
3
+ let(:app_without_crashes) { double(:app_without_crashes)}
4
+
5
+ let(:env) { Hash['action_controller.instance' => example_controller ]}
6
+ let(:example_controller) { double(:controller) }
7
+ let(:error) { StandardError.new }
8
+
9
+ before(:each) do
10
+ allow(app_with_crashes).to receive(:call).with(env).and_raise(error)
11
+ allow(app_without_crashes).to receive(:call).with(env).and_return(:ok)
12
+ end
13
+
14
+ context 'app that raises exception' do
15
+ subject { described_class.new app_with_crashes }
16
+
17
+ before(:each) do
18
+ expect_any_instance_of(Crashbreak::ExceptionNotifier).to receive(:notify).and_return(true)
19
+ expect{ subject.call(env) }.to raise_error(StandardError)
20
+ end
21
+
22
+ it 'sets exception in store' do
23
+ expect(RequestStore.store[:exception]).to eq(error)
24
+ end
25
+
26
+ it 'sets request in store' do
27
+ expect(RequestStore.store[:request]).to be_a_kind_of(Rack::Request)
28
+ end
29
+
30
+ it 'sets controller in store' do
31
+ expect(RequestStore.store[:controller]).to eq example_controller
32
+ end
33
+ end
34
+
35
+ context 'app that works without exceptions' do
36
+ subject { described_class.new app_without_crashes }
37
+
38
+ it 'does nothing' do
39
+ expect_any_instance_of(Crashbreak::ExceptionNotifier).to_not receive(:notify).and_return(true)
40
+ expect(subject.call(env)).to eq(:ok)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ describe Crashbreak::ExceptionNotifier do
2
+ subject { described_class.new }
3
+ let(:error) { StandardError.new error_message }
4
+ let(:error_name) { error.class.to_s }
5
+ let(:error_message) { 'example_error_message'}
6
+
7
+ before(:each) do
8
+ allow(error).to receive(:backtrace).and_return(%w(example backtrace))
9
+ RequestStore[:exception] = error
10
+ end
11
+
12
+ let(:exception_basic_hash) do
13
+ { name: error_name, message: error_message, backtrace: error.backtrace, environment: ENV['RACK_ENV'] }
14
+ end
15
+
16
+ context 'without additional serializers' do
17
+ before(:each) { allow_any_instance_of(Crashbreak::Configurator).to receive(:error_serializers).and_return([]) }
18
+ it 'sends pure error' do
19
+ expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:create).with(exception_basic_hash)
20
+ subject.notify
21
+ end
22
+ end
23
+
24
+ context 'with additional serializers' do
25
+ let(:expected_hash) { exception_basic_hash.merge(serializer_hash) }
26
+
27
+ let(:serializer_hash) do
28
+ { additional_key: :example, additional_data: { looks_good: :yes } }
29
+ end
30
+
31
+ let(:serializer) { double(:serializer) }
32
+
33
+ before(:each) do
34
+ allow(serializer).to receive(:serialize).and_return(serializer_hash)
35
+ allow_any_instance_of(Crashbreak::Configurator).to receive(:error_serializers).and_return([serializer])
36
+ end
37
+
38
+ it 'sends formatted error' do
39
+ expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:create).with(expected_hash)
40
+ subject.notify
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ describe Crashbreak::ExceptionsRepository do
2
+ subject { described_class.new }
3
+
4
+ let(:project_token) { 'example_project_token' }
5
+
6
+ before(:each) do
7
+ Crashbreak.configure.api_key = project_token
8
+ end
9
+
10
+ let(:error_report_hash) do
11
+ {
12
+ name: 'Example name', message: 'Example message', backtrace: [%w(example backtrace)],
13
+ additional_data: { additional_hash: { example: :true }, second: { test: 'true' } }
14
+ }
15
+ end
16
+
17
+ let!(:create_exception_request) do
18
+ stub_request(:post, "#{described_class::BASE_URL}/projects/#{project_token}/errors").
19
+ with(body: error_report_hash.to_json).to_return(status: 200)
20
+ end
21
+
22
+ it 'sends request to create exception report' do
23
+ subject.create error_report_hash
24
+ expect(create_exception_request).to have_been_made
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ describe Crashbreak::BasicFormatter do
2
+ subject { described_class.new }
3
+
4
+ let(:example_request) { double(:request) }
5
+ let(:example_exception) { double(:exception) }
6
+ let(:example_controller) { double(:controller) }
7
+
8
+ before(:each) do
9
+ RequestStore.store[:request] = example_request
10
+ RequestStore.store[:exception] = example_exception
11
+ RequestStore.store[:controller] = example_controller
12
+ end
13
+
14
+ it 'returns request' do
15
+ expect(subject.send(:request)).to eq(example_request)
16
+ end
17
+
18
+ it 'returns exception' do
19
+ expect(subject.send(:exception)).to eq(example_exception)
20
+ end
21
+
22
+ it 'returns controller' do
23
+ expect(subject.send(:controller)).to eq(example_controller)
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ describe Crashbreak::DefaultSummaryFormatter do
2
+ subject { described_class.new }
3
+
4
+ let(:example_request) { double(:request, env: request_env) }
5
+ let(:request_env) { Hash['PATH_INFO' => 'example_path', 'REQUEST_URI' => 'example_uri', 'HTTP_USER_AGENT' => 'firefox']}
6
+ let(:example_controller) { double(:controller) }
7
+ let(:example_exception) { double(:exception, backtrace: ['file.rb#12'])}
8
+
9
+ before(:each) do
10
+ RequestStore.store[:request] = example_request
11
+ RequestStore.store[:controller] = example_controller
12
+ RequestStore.store[:exception] = example_exception
13
+ end
14
+
15
+ it 'formats default summary' do
16
+ expect(subject.summary).to eq(action: example_request.env['PATH_INFO'],
17
+ controller_name: example_controller.class.to_s,
18
+ file: example_exception.backtrace[0],
19
+ url: example_request.env['REQUEST_URI'],
20
+ user_agent: example_request.env['HTTP_USER_AGENT'])
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ describe Crashbreak::HashFormatter do
2
+ class TestHashFormatter < Crashbreak::HashFormatter
3
+ hash_name :example_group
4
+
5
+ def hash_value
6
+ { example: 'true' }
7
+ end
8
+ end
9
+
10
+ subject { TestHashFormatter.new }
11
+
12
+ it 'wraps hash in additional_data and group_name key' do
13
+ expect(subject.serialize).to eq(additional_data: { example_group: subject.hash_value })
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ describe Crashbreak::SummaryFormatter do
2
+ class SummaryTestFormatter < Crashbreak::SummaryFormatter
3
+ def summary
4
+ { example: 'true' }
5
+ end
6
+ end
7
+
8
+ subject { SummaryTestFormatter.new }
9
+
10
+ it 'wraps summary hash' do
11
+ expect(subject.serialize).to eq(summary: subject.summary)
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'generator_spec'
2
+ require_relative '../../../lib/generators/crashbreak/install_generator'
3
+
4
+ describe Crashbreak::Generators::InstallGenerator do
5
+ destination File.expand_path('../../../../tmp', __FILE__)
6
+ arguments %w(example_project_token)
7
+
8
+ before(:all) do
9
+ prepare_destination
10
+ run_generator
11
+ end
12
+
13
+ it 'creates an initializer' do
14
+ assert_file 'config/initializers/crashbreak.rb', /example_project_token/
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ describe Crashbreak::ProgramNameRestorer do
2
+ subject { described_class.new }
3
+ let(:program_name) { 'crashbreak' }
4
+
5
+ before(:each) { allow(File).to receive(:readlines).and_return([program_name]) }
6
+
7
+ it 'restore global variable $PROGRAM_NAME from file' do
8
+ subject.restore
9
+ expect($PROGRAM_NAME).to eq program_name
10
+ end
11
+ end
@@ -1,4 +1,7 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+
1
3
  require 'bundler/setup'
4
+ require 'webmock/rspec'
2
5
  Bundler.require :default, :development
3
6
 
4
7
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file }
@@ -0,0 +1,3 @@
1
+ class TestError < StandardError
2
+
3
+ end
@@ -0,0 +1,7 @@
1
+ class TestErrorFormatter < Crashbreak::HashFormatter
2
+ hash_name :test
3
+
4
+ def hash_value
5
+ { formatter: true }
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crashbreak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Janeczek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-21 00:00:00.000000000 Z
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,76 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: request_store
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
55
125
  description: Maybe later... :)
56
126
  email:
57
127
  - michal.janeczek@ymail.com
@@ -68,10 +138,40 @@ files:
68
138
  - Rakefile
69
139
  - crashbreak.gemspec
70
140
  - lib/crashbreak.rb
141
+ - lib/crashbreak/config/configurable.rb
142
+ - lib/crashbreak/config/configurator.rb
143
+ - lib/crashbreak/exception_catcher_middleware.rb
144
+ - lib/crashbreak/exception_notifier.rb
145
+ - lib/crashbreak/exceptions_repository.rb
146
+ - lib/crashbreak/formatters/basic_formatter.rb
147
+ - lib/crashbreak/formatters/basic_information_formatter.rb
148
+ - lib/crashbreak/formatters/default_summary_formatter.rb
149
+ - lib/crashbreak/formatters/environment_variables_formatter.rb
150
+ - lib/crashbreak/formatters/hash_formatter.rb
151
+ - lib/crashbreak/formatters/summary_formatter.rb
71
152
  - lib/crashbreak/version.rb
72
- - spec/lib/version_spec.rb
153
+ - lib/dumpers/program_name_dumper.rb
154
+ - lib/generators/crashbreak/install_generator.rb
155
+ - lib/generators/crashbreak/templates/crashbreak.rb
156
+ - lib/restorers/program_name_restorer.rb
157
+ - lib/tasks/crashbreak.rake
158
+ - spec/dumpers/program_name_dumper_spec.rb
159
+ - spec/features/sending_error_report_spec.rb
160
+ - spec/lib/config/configurable_spec.rb
161
+ - spec/lib/config/configurator_spec.rb
162
+ - spec/lib/exception_catcher_middleware_spec.rb
163
+ - spec/lib/exception_notifier_spec.rb
164
+ - spec/lib/exceptions_repository_spec.rb
165
+ - spec/lib/formatters/basic_formatter_spec.rb
166
+ - spec/lib/formatters/default_summary_formatter_spec.rb
167
+ - spec/lib/formatters/group_formatter_spec.rb
168
+ - spec/lib/formatters/summary_formatter_spec.rb
169
+ - spec/lib/generators/install_generator_spec.rb
170
+ - spec/restorers/program_name_restorer_spec.rb
73
171
  - spec/spec_helper.rb
74
172
  - spec/support/rspec_config.rb
173
+ - spec/support/test_error.rb
174
+ - spec/support/test_error_formatter.rb
75
175
  homepage: http://crashbreak.com
76
176
  licenses:
77
177
  - MIT
@@ -92,12 +192,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
192
  version: '0'
93
193
  requirements: []
94
194
  rubyforge_project:
95
- rubygems_version: 2.3.0
195
+ rubygems_version: 2.2.2
96
196
  signing_key:
97
197
  specification_version: 4
98
198
  summary: Take a break from crashes!
99
199
  test_files:
100
- - spec/lib/version_spec.rb
200
+ - spec/dumpers/program_name_dumper_spec.rb
201
+ - spec/features/sending_error_report_spec.rb
202
+ - spec/lib/config/configurable_spec.rb
203
+ - spec/lib/config/configurator_spec.rb
204
+ - spec/lib/exception_catcher_middleware_spec.rb
205
+ - spec/lib/exception_notifier_spec.rb
206
+ - spec/lib/exceptions_repository_spec.rb
207
+ - spec/lib/formatters/basic_formatter_spec.rb
208
+ - spec/lib/formatters/default_summary_formatter_spec.rb
209
+ - spec/lib/formatters/group_formatter_spec.rb
210
+ - spec/lib/formatters/summary_formatter_spec.rb
211
+ - spec/lib/generators/install_generator_spec.rb
212
+ - spec/restorers/program_name_restorer_spec.rb
101
213
  - spec/spec_helper.rb
102
214
  - spec/support/rspec_config.rb
103
- has_rdoc:
215
+ - spec/support/test_error.rb
216
+ - spec/support/test_error_formatter.rb
@@ -1,5 +0,0 @@
1
- describe 'example test' do
2
- it 'works' do
3
- expect(Crashbreak::VERSION).to eq '0.0.1'
4
- end
5
- end