mprelude 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19538ca2618de1e9e66da6b29c8e173ba3d1ce1e967ccaa7f87c71685f7c1e13
4
- data.tar.gz: 83f2a0ae363a6227f7da56dc6e399e330a15a4eb74ca4acb6c0c1ec971db07d2
3
+ metadata.gz: 3aacb84586c1ad9f9fc2c511b8d1c9b86fe19ae748963dcf2f0d591783664d0f
4
+ data.tar.gz: e029a25a9f97c2130a962a75c9485c5a0ca67df4b7c45f04083dcfadcc15ed2a
5
5
  SHA512:
6
- metadata.gz: d166a903c908906e55f62e50d4fc7a3863bed413ddd15c55b923330009069b5080d9d459b14981ca5a70ead7a34e7567d81d33cc6f000b4d8e2c2b74770fe1a1
7
- data.tar.gz: b11d18eac0aad4eb2a14b6d5c22c8e201b27b41769df771cd9b71ad155ad57ff4dbb14f35cc946b8724b520c9f34f0a2f4ecadd1e64dbb4b99dcff525c3171e9
6
+ metadata.gz: d94ba246bb06c53482847f1836c23f209f47327b4af22579b0cd253cc5b574b5fd00d7bbf57dee83792db187c41c6db7ecddd8b0b0f3ffe81d3152a4a29ff58e
7
+ data.tar.gz: 5dc0fe7dc51a9a6de24c325ed8bef71c079a677e4e7b7dc93f49b631ab954cb553fd84f4ab6e2bc06b25a7046711fa0050c56c0f2f0389334489bd360cb1b506
data/lib/mprelude.rb CHANGED
@@ -80,13 +80,13 @@ module MPrelude
80
80
 
81
81
  # Execute block and wrap error in left
82
82
  #
83
- # @param [Class:Exception] error
83
+ # @param [Class<Exception>] exception
84
84
  #
85
85
  # @return [Either<Exception, Object>]
86
- def self.wrap_error(error)
86
+ def self.wrap_error(*exceptions)
87
87
  Right.new(yield)
88
- rescue error => exception
89
- Left.new(exception)
88
+ rescue *exceptions => error
89
+ Left.new(error)
90
90
  end
91
91
 
92
92
  class Left < self
data/mprelude.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'mprelude'
5
- gem.version = '0.0.1'
5
+ gem.version = '0.0.2'
6
6
  gem.authors = ['Markus Schirp']
7
7
  gem.email = ['mbj@schirp-dso.com']
8
8
  gem.description = 'Minimal prelude alike classes'
@@ -2,15 +2,16 @@
2
2
 
3
3
  RSpec.describe MPrelude::Either do
4
4
  describe '.wrap_error' do
5
- def apply
6
- described_class.wrap_error(error, &block)
7
- end
8
-
9
- let(:error) { TestError }
5
+ let(:block) { -> { fail error } }
6
+ let(:error) { exception.new }
7
+ let(:exception) { TestError }
8
+ let(:other_exception) { OtherTestError }
10
9
 
11
10
  class TestError < RuntimeError; end
12
11
 
13
- context 'when block returns' do
12
+ class OtherTestError < RuntimeError; end
13
+
14
+ shared_examples 'block returns' do
14
15
  let(:value) { instance_double(Object, 'value') }
15
16
  let(:block) { -> { value } }
16
17
 
@@ -19,21 +20,67 @@ RSpec.describe MPrelude::Either do
19
20
  end
20
21
  end
21
22
 
22
- context 'when block raises' do
23
- let(:exception) { error.new }
24
- let(:block) { -> { fail exception } }
23
+ shared_examples 'covered exception' do
24
+ it 'returns left wrapping exception' do
25
+ expect(apply).to eql(described_class::Left.new(error))
26
+ end
27
+ end
28
+
29
+ shared_examples 'uncovered exception' do
30
+ let(:unexpected_exception) { StandardError }
31
+
32
+ let(:block) { -> { fail unexpected_exception } }
33
+
34
+ it 'returns raises error' do
35
+ expect { apply }.to raise_error(unexpected_exception)
36
+ end
37
+ end
38
+
39
+ context 'on single exception argument' do
40
+ def apply
41
+ described_class.wrap_error(exception, &block)
42
+ end
43
+
44
+ context 'when block returns' do
45
+ include_examples 'block returns'
46
+ end
47
+
48
+ context 'when block raises' do
49
+ context 'with covered exception' do
50
+ include_examples 'covered exception'
51
+ end
25
52
 
26
- context 'with covered exception' do
27
- it 'returns left wrapping exception' do
28
- expect(apply).to eql(described_class::Left.new(exception))
53
+ context 'with uncovered exception' do
54
+ include_examples 'uncovered exception'
29
55
  end
30
56
  end
57
+ end
58
+
59
+ context 'on multiple exception arguments' do
60
+ def apply
61
+ described_class.wrap_error(exception, other_exception, &block)
62
+ end
63
+
64
+ context 'when block returns' do
65
+ include_examples 'block returns'
66
+ end
67
+
68
+ context 'when block raises' do
69
+ context 'with covered exception' do
70
+ include_examples 'covered exception'
71
+ end
72
+
73
+ context 'with uncovered exception' do
74
+ include_examples 'uncovered exception'
75
+ end
31
76
 
32
- context 'with uncovered exception' do
33
- let(:exception) { StandardError.new }
77
+ context 'with other covered exception' do
78
+ let(:block) { -> { fail other_error } }
79
+ let(:other_error) { other_exception.new }
34
80
 
35
- it 'returns raises error' do
36
- expect { apply }.to raise_error(StandardError)
81
+ it 'returns left wrapping exception' do
82
+ expect(apply).to eql(described_class::Left.new(other_error))
83
+ end
37
84
  end
38
85
  end
39
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mprelude
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
  - Markus Schirp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-27 00:00:00.000000000 Z
11
+ date: 2019-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abstract_type
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  requirements: []
134
- rubygems_version: 3.0.4
134
+ rubygems_version: 3.0.6
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Mostly an either type