finishing_moves 0.12 → 0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9348af415342a03d683aade50c3e3121fae98c6
4
- data.tar.gz: 902a8a29ba2517248098f40696ce50429ab11afd
3
+ metadata.gz: 2e83beb44f31e133f35900b3e4b2dd3c6a0bb1b7
4
+ data.tar.gz: 3f1d6578baff446873c089be7103a72cc9c66d5a
5
5
  SHA512:
6
- metadata.gz: c7b0813906c9c82d9d5f2989ecff98c55aa56c619bd829039891abc39a053ec59c1f056660e8e27196cac31f94e59b52859cbd20f3be8607e28d339d70e69a2a
7
- data.tar.gz: 74888d990597d97f8ef92259b98445afebe33cca738e717c6351a2e7c8d87a0f459d7b008ebc71e5d08cea85c532e220051454eef1af09b443f4219468b7b17a
6
+ metadata.gz: 36212ac6505a5705703b4855e50ed524e820df417d9e082b1696eb7c2b4be4860b76c5e4d18197fd115a49bafc884964cbf22cf4c4373347a1ad0d3fad369080
7
+ data.tar.gz: 2eb008c733f17451d67cb91f5433ce864ffe29c4e53f00a5aa385ef630979b6f2d03722fa4a8f04f6d4ec442b35625c5db33437ce247a037abdb7f531a1e9226
@@ -32,4 +32,14 @@ module Kernel
32
32
  end
33
33
  end
34
34
 
35
+ def silently(ret_val = nil, &block)
36
+ begin
37
+ result = yield
38
+ return ret_val if result.nil?
39
+ result
40
+ rescue
41
+ return ret_val
42
+ end
43
+ end
44
+
35
45
  end
@@ -1,3 +1,3 @@
1
1
  module FinishingMoves
2
- VERSION = "0.12"
2
+ VERSION = "0.13"
3
3
  end
@@ -59,6 +59,47 @@ describe Kernel do
59
59
  expect(test_cascade('foobar')).to eq 4
60
60
  end
61
61
 
62
+ it "#silently" do
63
+ # lots of overlap with nil_chain, so...
64
+ expect(silently{bogus_variable}).to eq nil
65
+ expect(silently{bogus_hash[:foo]}).to eq nil
66
+ params = { :foo => 'bar' }
67
+ expect(silently{ params[:bogus_key] }).to eq nil
68
+ expect(silently{ params[:foo] }).to eq 'bar'
69
+ var = 'a simple string'
70
+ expect(silently{ var.transmogrify }).to eq nil
71
+
72
+ c = C.new
73
+ b = B.new c
74
+ a = A.new b
75
+ expect(a.b.c.hello).to eq "Hello, world!"
76
+ b.c = nil
77
+ expect(silently{a.b.c.hello}).to eq nil
78
+ a = nil
79
+ expect(silently{a.b.c.hello}).to eq nil
80
+
81
+ expect( silently(true) { bogus_variable } ).to equal true
82
+ expect( silently(false) { bogus_variable } ).to equal false
83
+ expect( silently('gotcha!') { bogus_variable } ).to eq 'gotcha!'
84
+ expect( silently('gotcha!') { params[:bogus_key] } ).to eq 'gotcha!'
85
+ expect( silently('gotcha!') { params[:foo] } ).to eq 'bar'
86
+
87
+ # and here's the new sauce
88
+ expect(silently{raise}).to eq nil
89
+ expect(silently{raise "oops"}).to eq nil
90
+ expect(silently{raise StandardError}).to eq nil
91
+ expect(silently{raise ArgumentError}).to eq nil
92
+ expect(silently{raise RuntimeError}).to eq nil
93
+ expect(silently{raise NoMethodError}).to eq nil
94
+ expect(silently{raise NameError}).to eq nil
95
+
96
+ # leave system-level stuff alone
97
+ expect{ silently{raise Exception} }.to raise_error(Exception)
98
+ expect{ silently{raise SystemExit} }.to raise_error(SystemExit)
99
+ expect{ silently{raise NoMemoryError} }.to raise_error(NoMemoryError)
100
+ expect{ silently{raise SignalException.new(0)} }.to raise_error(SignalException)
101
+ end
102
+
62
103
  end
63
104
 
64
105
  # some small test fixtures
@@ -115,3 +156,13 @@ module SomeModule
115
156
  end
116
157
  end
117
158
 
159
+ class TestExceptionLibrary
160
+ class Error < RuntimeError
161
+ end
162
+
163
+ class WidgetError < Error
164
+ end
165
+
166
+ class FrobError < Error
167
+ end
168
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finishing_moves
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.12'
4
+ version: '0.13'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Koehl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-31 00:00:00.000000000 Z
12
+ date: 2016-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb-readline