robustly 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/robustly.rb +3 -2
- data/lib/robustly/version.rb +1 -1
- data/test/robustly_test.rb +25 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e02c3021e070fa4899fa7f53aefcd64bffe6fe82
|
4
|
+
data.tar.gz: 2aad8ec66ed86f10cb2614ddf3bf27d026755a45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c1b7cab85c2cb0fbe9f673018e6a2316df077e79854e854ab10ff5d71a9fdc63efe3799cda541a93a2719de281a4ad8c1d91797e995453447a3c1999dff45ff
|
7
|
+
data.tar.gz: 888840c69445f1546f126369db68250502031feb38824a5344e4ea897aa2b47c1cab8f3d6d400609199cc74bf569f6dcacbde10f7cea0559a7833243f438b5b8
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Don’t let small errors bring down the system
|
4
4
|
|
5
5
|
```ruby
|
6
|
-
|
6
|
+
safely do
|
7
7
|
# keep going if this code fails
|
8
8
|
end
|
9
9
|
```
|
@@ -29,7 +29,7 @@ Robustly.report_exception_method = proc {|e| Rollbar.report_exception(e) }
|
|
29
29
|
And throttle reporting with:
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
|
32
|
+
safely throttle: 1000 do
|
33
33
|
# reports ~ 1/1000 errors
|
34
34
|
end
|
35
35
|
```
|
@@ -37,7 +37,7 @@ end
|
|
37
37
|
Specify a default value to return on errors:
|
38
38
|
|
39
39
|
```ruby
|
40
|
-
|
40
|
+
safely default: 30 do
|
41
41
|
# big bucks, no whammy
|
42
42
|
end
|
43
43
|
```
|
@@ -45,7 +45,7 @@ end
|
|
45
45
|
Catch specific errors
|
46
46
|
|
47
47
|
```ruby
|
48
|
-
|
48
|
+
safely only: ActiveRecord::RecordNotUnique do
|
49
49
|
# all other exceptions will be raised
|
50
50
|
end
|
51
51
|
```
|
data/lib/robustly.rb
CHANGED
@@ -17,7 +17,7 @@ module Robustly
|
|
17
17
|
|
18
18
|
module Methods
|
19
19
|
|
20
|
-
def
|
20
|
+
def safely(options = {}, &block)
|
21
21
|
class_names = Array(options[:only] || StandardError)
|
22
22
|
begin
|
23
23
|
yield
|
@@ -29,7 +29,8 @@ module Robustly
|
|
29
29
|
options[:default]
|
30
30
|
end
|
31
31
|
end
|
32
|
-
alias_method :yolo, :
|
32
|
+
alias_method :yolo, :safely
|
33
|
+
alias_method :robustly, :safely # legacy
|
33
34
|
|
34
35
|
end
|
35
36
|
|
data/lib/robustly/version.rb
CHANGED
data/test/robustly_test.rb
CHANGED
@@ -7,30 +7,30 @@ class TestRobustly < Minitest::Test
|
|
7
7
|
Robustly.report_exception_method = proc {|e| Errbase.report(e) }
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def test_safely_development_environment
|
11
11
|
Robustly.env = "development"
|
12
12
|
assert_raises(Robustly::TestError) do
|
13
|
-
|
13
|
+
safely do
|
14
14
|
raise Robustly::TestError
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def test_safely_test_environment
|
20
20
|
Robustly.env = "test"
|
21
21
|
assert_raises(Robustly::TestError) do
|
22
|
-
|
22
|
+
safely do
|
23
23
|
raise Robustly::TestError
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def test_safely_production_environment
|
29
29
|
exception = Robustly::TestError.new
|
30
30
|
mock = MiniTest::Mock.new
|
31
31
|
mock.expect :report_exception, nil, [exception]
|
32
32
|
Robustly.report_exception_method = proc {|e| mock.report_exception(e) }
|
33
|
-
|
33
|
+
safely do
|
34
34
|
raise exception
|
35
35
|
end
|
36
36
|
assert mock.verify
|
@@ -47,24 +47,35 @@ class TestRobustly < Minitest::Test
|
|
47
47
|
assert mock.verify
|
48
48
|
end
|
49
49
|
|
50
|
+
def test_robustly
|
51
|
+
exception = Robustly::TestError.new
|
52
|
+
mock = MiniTest::Mock.new
|
53
|
+
mock.expect :report_exception, nil, [exception]
|
54
|
+
Robustly.report_exception_method = proc {|e| mock.report_exception(e) }
|
55
|
+
robustly do
|
56
|
+
raise exception
|
57
|
+
end
|
58
|
+
assert mock.verify
|
59
|
+
end
|
60
|
+
|
50
61
|
def test_return_value
|
51
|
-
assert_equal 1,
|
52
|
-
assert_equal nil,
|
62
|
+
assert_equal 1, safely { 1 }
|
63
|
+
assert_equal nil, safely { raise Robustly::TestError }
|
53
64
|
end
|
54
65
|
|
55
66
|
def test_default
|
56
|
-
assert_equal 1,
|
57
|
-
assert_equal 2,
|
67
|
+
assert_equal 1, safely(default: 2) { 1 }
|
68
|
+
assert_equal 2, safely(default: 2) { raise Robustly::TestError }
|
58
69
|
end
|
59
70
|
|
60
71
|
def test_only
|
61
|
-
assert_equal nil,
|
62
|
-
assert_raises(RuntimeError, "Boom") {
|
72
|
+
assert_equal nil, safely(only: Robustly::TestError) { raise Robustly::TestError }
|
73
|
+
assert_raises(RuntimeError, "Boom") { safely(only: Robustly::TestError) { raise RuntimeError.new("Boom") } }
|
63
74
|
end
|
64
75
|
|
65
76
|
def test_only_array
|
66
|
-
assert_equal nil,
|
67
|
-
assert_raises(RuntimeError, "Boom") {
|
77
|
+
assert_equal nil, safely(only: [Robustly::TestError]) { raise Robustly::TestError }
|
78
|
+
assert_raises(RuntimeError, "Boom") { safely(only: [Robustly::TestError]) { raise RuntimeError.new("Boom") } }
|
68
79
|
end
|
69
80
|
|
70
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robustly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: errbase
|