yogi_berra 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +0 -3
- data/lib/yogi_berra/action_controller_catcher.rb +1 -1
- data/lib/yogi_berra/catcher.rb +1 -1
- data/lib/yogi_berra/data.rb +14 -6
- data/lib/yogi_berra/exception_middleware.rb +2 -2
- data/lib/yogi_berra/version.rb +1 -1
- data/lib/yogi_berra.rb +3 -3
- data/spec/fixtures/rails.rb +3 -3
- data/spec/spec_helper.rb +13 -5
- data/spec/yogi_berra_catcher_spec.rb +40 -0
- data/spec/yogi_berra_data_spec.rb +38 -0
- data/spec/yogi_berra_logger_spec.rb +17 -0
- metadata +1 -19
- data/spec/yogi_berra_spec.rb +0 -85
data/Gemfile.lock
CHANGED
@@ -3,15 +3,12 @@ PATH
|
|
3
3
|
specs:
|
4
4
|
yogi_berra (0.0.3)
|
5
5
|
bson (= 1.8.3)
|
6
|
-
bson_ext (= 1.8.3)
|
7
6
|
mongo (= 1.8.3)
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: https://rubygems.org/
|
11
10
|
specs:
|
12
11
|
bson (1.8.3)
|
13
|
-
bson_ext (1.8.3)
|
14
|
-
bson (~> 1.8.3)
|
15
12
|
builder (3.2.1)
|
16
13
|
diff-lcs (1.2.4)
|
17
14
|
mongo (1.8.3)
|
@@ -37,7 +37,7 @@ module YogiBerra
|
|
37
37
|
:server_address => request.headers['SERVER_ADDR'],
|
38
38
|
:remote_address => request.remote_ip
|
39
39
|
}
|
40
|
-
error_id = YogiBerra.exceptionize(exception, environment
|
40
|
+
error_id = YogiBerra.exceptionize(exception, environment)
|
41
41
|
request.env['yogi_berra.error_id'] = error_id
|
42
42
|
end
|
43
43
|
|
data/lib/yogi_berra/catcher.rb
CHANGED
data/lib/yogi_berra/data.rb
CHANGED
@@ -2,23 +2,24 @@ require 'mongo'
|
|
2
2
|
|
3
3
|
module YogiBerra
|
4
4
|
class Data
|
5
|
-
def self.store!(exception, environment
|
5
|
+
def self.store!(exception, environment = nil)
|
6
6
|
data = parse_exception(exception)
|
7
7
|
if environment
|
8
8
|
session = environment.delete(:session)
|
9
9
|
data[:session] = parse_session(session) if session
|
10
10
|
data.merge!(environment)
|
11
11
|
end
|
12
|
-
|
12
|
+
(YogiBerra::Catcher.connection || YogiBerra::Catcher.quick_connection)["caught_exceptions"].insert(data)
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.parse_exception(notice)
|
16
16
|
data_hash = {
|
17
|
-
:error_class => notice.
|
17
|
+
:error_class => "#{notice.class}",
|
18
18
|
:project => YogiBerra::Catcher.settings["project"],
|
19
|
-
:error_message => notice.error_message
|
19
|
+
:error_message => notice.respond_to?(:error_message) ? notice.error_message : notice.message
|
20
20
|
}
|
21
|
-
|
21
|
+
data_hash[:backtraces] = notice.backtrace
|
22
|
+
if notice.backtrace.respond_to?(:lines) && notice.backtrace.lines.any?
|
22
23
|
data_hash[:backtraces] = notice.backtrace.lines.collect(&:to_s)
|
23
24
|
end
|
24
25
|
data_hash[:created_at] = Time.now.utc
|
@@ -27,7 +28,14 @@ module YogiBerra
|
|
27
28
|
|
28
29
|
def self.parse_session(session)
|
29
30
|
session.inject({}) do |result, element|
|
30
|
-
|
31
|
+
key = element.first
|
32
|
+
value = element.last
|
33
|
+
if value.respond_to?(:as_json)
|
34
|
+
result[key] = value.as_json(:except => ["password"])
|
35
|
+
else
|
36
|
+
value.delete("password")
|
37
|
+
result[key] = value
|
38
|
+
end
|
31
39
|
result
|
32
40
|
end
|
33
41
|
end
|
@@ -20,12 +20,12 @@ module YogiBerra
|
|
20
20
|
:remote_address => env['REMOTE_ADDR']
|
21
21
|
}
|
22
22
|
rescue Exception => raised
|
23
|
-
YogiBerra.exceptionize(raised, environment
|
23
|
+
YogiBerra.exceptionize(raised, environment)
|
24
24
|
raise raised
|
25
25
|
end
|
26
26
|
|
27
27
|
if env['rack.exception']
|
28
|
-
YogiBerra.exceptionize(raised, environment
|
28
|
+
YogiBerra.exceptionize(raised, environment)
|
29
29
|
end
|
30
30
|
response
|
31
31
|
end
|
data/lib/yogi_berra/version.rb
CHANGED
data/lib/yogi_berra.rb
CHANGED
@@ -18,10 +18,10 @@ module YogiBerra
|
|
18
18
|
# @params exception
|
19
19
|
# @params environment
|
20
20
|
# @params database
|
21
|
-
def exceptionize(exception, environment,
|
21
|
+
def exceptionize(exception, environment, opts = {})
|
22
22
|
notice = build_notice_for(exception, opts)
|
23
|
-
if
|
24
|
-
YogiBerra::Data.store!(notice, environment
|
23
|
+
if YogiBerra::Catcher.connection
|
24
|
+
YogiBerra::Data.store!(notice, environment)
|
25
25
|
else
|
26
26
|
YogiBerra::Logger.log("No database connection!", :error)
|
27
27
|
end
|
data/spec/fixtures/rails.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,22 @@
|
|
1
|
-
# Load support files
|
2
1
|
SPEC_FOLDER = File.dirname(__FILE__)
|
3
2
|
require 'yaml'
|
4
3
|
require 'yogi_berra'
|
4
|
+
require 'rspec/mocks'
|
5
5
|
# Helper methods
|
6
|
-
|
7
|
-
|
8
6
|
# Creates RunTimeError
|
9
7
|
def build_exception
|
10
|
-
raise
|
11
|
-
rescue => caught_exception
|
8
|
+
raise Exception
|
9
|
+
rescue Exception => caught_exception
|
12
10
|
caught_exception
|
13
11
|
end
|
14
12
|
|
13
|
+
def build_session
|
14
|
+
{ "access" =>
|
15
|
+
{ "user_id" => 30785,
|
16
|
+
"id" => 605,
|
17
|
+
"password" => "[FILTERED]",
|
18
|
+
"auth_key" => "Baseball is ninety percent mental and the other half is physical."
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe YogiBerra do
|
4
|
+
before(:all) do
|
5
|
+
@test_yaml = "#{SPEC_FOLDER}/fixtures/test.yml"
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
YogiBerra::Logger.stub(:log)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should load a yaml file without rails" do
|
13
|
+
lambda { YogiBerra::Catcher.load_db_settings(@test_yaml) }.should_not raise_error
|
14
|
+
YogiBerra::Catcher.settings.should_not == nil
|
15
|
+
YogiBerra::Catcher.settings["project"].should == "test_yogi_project"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should load a yaml file with rails" do
|
19
|
+
ENV["YOGI_ENV"] = nil
|
20
|
+
load "#{SPEC_FOLDER}/fixtures/rails.rb"
|
21
|
+
lambda { YogiBerra::Catcher.load_db_settings }.should_not raise_error
|
22
|
+
YogiBerra::Catcher.settings.should_not == nil
|
23
|
+
YogiBerra::Catcher.settings["project"].should == "rails_yogi_project"
|
24
|
+
Object.send(:remove_const, :Rails)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should grab a connection using the settings file" do
|
28
|
+
connection = nil
|
29
|
+
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
30
|
+
connection = YogiBerra::Catcher.quick_connection
|
31
|
+
connection.should_not == nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should grab a connection to mongodb" do
|
35
|
+
yaml = nil
|
36
|
+
yaml = YogiBerra::Catcher.load_db_settings(@test_yaml)
|
37
|
+
db_client = YogiBerra::Catcher.db_client(YogiBerra::Catcher.settings["host"], YogiBerra::Catcher.settings["port"])
|
38
|
+
db_client.should_not == nil
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe YogiBerra do
|
4
|
+
before(:each) do
|
5
|
+
YogiBerra::Logger.stub(:log)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should store an exception" do
|
9
|
+
YogiBerra::Catcher.connection = nil
|
10
|
+
exception = build_exception
|
11
|
+
mongo_client = double('mongo client')
|
12
|
+
mongo_connection = double('mongo connection')
|
13
|
+
Mongo::MongoClient.should_receive(:new) { mongo_client }
|
14
|
+
mongo_client.should_receive(:[]) { mongo_connection }
|
15
|
+
mongo_connection.should_receive(:[]) { mongo_connection }
|
16
|
+
mongo_connection.should_receive(:insert)
|
17
|
+
YogiBerra::Data.store!(exception)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should parse an exception" do
|
21
|
+
exception = build_exception
|
22
|
+
parsed_data = YogiBerra::Data.parse_exception(exception)
|
23
|
+
parsed_data[:error_class].should == "Exception"
|
24
|
+
parsed_data[:project].should == "test_yogi_project"
|
25
|
+
parsed_data[:error_message].should == "Exception"
|
26
|
+
parsed_data[:backtraces].size.should == 17
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should parse a session" do
|
30
|
+
session = build_session
|
31
|
+
parsed_session = YogiBerra::Data.parse_session(session)
|
32
|
+
parsed_session["password"].should == nil
|
33
|
+
parsed_session["access"]["password"].should == nil
|
34
|
+
parsed_session["access"]["user_id"].should == 30785
|
35
|
+
parsed_session["access"]["id"].should == 605
|
36
|
+
parsed_session["access"]["auth_key"].should == "Baseball is ninety percent mental and the other half is physical."
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe YogiBerra::Logger do
|
4
|
+
|
5
|
+
it "should call $stderr to log" do
|
6
|
+
$stderr.should_receive(:puts).with("[YogiBerra Info] The future ain't what it used to be.")
|
7
|
+
YogiBerra::Logger.log("The future ain't what it used to be.")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should call Rails::Logger" do
|
11
|
+
load "#{SPEC_FOLDER}/fixtures/rails.rb"
|
12
|
+
logger = double('logger')
|
13
|
+
Rails.stub(:logger) { logger }
|
14
|
+
logger.should_receive(:info).with("[YogiBerra Info] Half the lies they tell about me aren't true.")
|
15
|
+
YogiBerra::Logger.log("Half the lies they tell about me aren't true.")
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yogi_berra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,22 +59,6 @@ dependencies:
|
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.8.3
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: bson_ext
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - '='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 1.8.3
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - '='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 1.8.3
|
78
62
|
- !ruby/object:Gem::Dependency
|
79
63
|
name: mongo
|
80
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,7 +107,6 @@ files:
|
|
123
107
|
- spec/yogi_berra_data_spec.rb
|
124
108
|
- spec/yogi_berra_exception_middleware_spec.rb
|
125
109
|
- spec/yogi_berra_logger_spec.rb
|
126
|
-
- spec/yogi_berra_spec.rb
|
127
110
|
homepage: http://github.com/earlonrails/yogi_berra
|
128
111
|
licenses: []
|
129
112
|
post_install_message:
|
@@ -157,4 +140,3 @@ test_files:
|
|
157
140
|
- spec/yogi_berra_data_spec.rb
|
158
141
|
- spec/yogi_berra_exception_middleware_spec.rb
|
159
142
|
- spec/yogi_berra_logger_spec.rb
|
160
|
-
- spec/yogi_berra_spec.rb
|
data/spec/yogi_berra_spec.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe YogiBerra do
|
4
|
-
before(:all) do
|
5
|
-
@test_yaml = "#{SPEC_FOLDER}/fixtures/test.yml"
|
6
|
-
end
|
7
|
-
|
8
|
-
before(:each) do
|
9
|
-
YogiBerra::Logger.stub(:log)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should call the upstream app with the environment" do
|
13
|
-
environment = { 'key' => 'value' }
|
14
|
-
app = lambda { |env| ['response', {}, env] }
|
15
|
-
stack = YogiBerra::ExceptionMiddleware.new(app)
|
16
|
-
|
17
|
-
response = stack.call(environment)
|
18
|
-
|
19
|
-
response[0].should == 'response'
|
20
|
-
response[1].should == {}
|
21
|
-
response[2].instance_variable_get("@response").should == { 'key' => 'value' }
|
22
|
-
end
|
23
|
-
|
24
|
-
it "deliver an exception raised while calling an upstream app" do
|
25
|
-
exception = build_exception
|
26
|
-
environment = { 'key' => 'value' }
|
27
|
-
app = lambda do |env|
|
28
|
-
raise exception
|
29
|
-
end
|
30
|
-
|
31
|
-
begin
|
32
|
-
stack = YogiBerra::ExceptionMiddleware.new(app)
|
33
|
-
stack.call(environment)
|
34
|
-
rescue Exception => raised
|
35
|
-
raised.should == exception
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should deliver an exception in rack.exception" do
|
40
|
-
exception = build_exception
|
41
|
-
environment = { 'key' => 'value' }
|
42
|
-
|
43
|
-
response = [200, {}, ['okay']]
|
44
|
-
app = lambda do |env|
|
45
|
-
env['rack.exception'] = exception
|
46
|
-
response
|
47
|
-
end
|
48
|
-
stack = YogiBerra::ExceptionMiddleware.new(app)
|
49
|
-
|
50
|
-
actual_response = stack.call(environment)
|
51
|
-
|
52
|
-
actual_response[0].should == 200
|
53
|
-
actual_response[1].should == {}
|
54
|
-
actual_response[2].instance_variable_get("@response").should == ["okay"]
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should load a yaml file without rails" do
|
58
|
-
lambda { YogiBerra::Catcher.load_db_settings(@test_yaml) }.should_not raise_error
|
59
|
-
YogiBerra::Catcher.settings.should_not == nil
|
60
|
-
YogiBerra::Catcher.settings["project"].should == "test_yogi_project"
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should load a yaml file with rails" do
|
64
|
-
ENV["YOGI_ENV"] = nil
|
65
|
-
require 'fixtures/rails'
|
66
|
-
lambda { YogiBerra::Catcher.load_db_settings }.should_not raise_error
|
67
|
-
YogiBerra::Catcher.settings.should_not == nil
|
68
|
-
YogiBerra::Catcher.settings["project"].should == "rails_yogi_project"
|
69
|
-
Object.send(:remove_const, :Rails)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should grab a connection using the settings file" do
|
73
|
-
connection = nil
|
74
|
-
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
75
|
-
connection = YogiBerra::Catcher.quick_connection
|
76
|
-
connection.should_not == nil
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should grab a connection to mongodb" do
|
80
|
-
yaml = nil
|
81
|
-
yaml = YogiBerra::Catcher.load_db_settings(@test_yaml)
|
82
|
-
db_client = YogiBerra::Catcher.db_client(YogiBerra::Catcher.settings["host"], YogiBerra::Catcher.settings["port"])
|
83
|
-
db_client.should_not == nil
|
84
|
-
end
|
85
|
-
end
|