djk_monads 0.1.0 → 0.2.0
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 +4 -4
- data/.gem_release.yml +4 -0
- data/CHANGELOG.md +4 -0
- data/README.md +16 -0
- data/lib/djk/monads/expectations/result_matchers.rb +33 -0
- data/lib/djk/monads/expectations.rb +4 -0
- data/lib/djk/monads/version.rb +1 -1
- data/lib/djk_monads.rb +3 -0
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b30c229861aed4c358bf22661ceb3d8f205d2a9e8a6c5968f94ad4ffa9293eef
|
|
4
|
+
data.tar.gz: 8cb0f86b3183e0bda40c7ba494851ba3eaa8683405ea81056d6475e03f378165
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1b1d880512a0d912263eb913dd4dd0a744dc6738367350389ab4dcbb1379c3242c0049f9d4c96f401fb9a0b473362bcee0ad76fe5e3abe874207d7884e9cb84f
|
|
7
|
+
data.tar.gz: bed23a372a2bacdf245a9eb7076a389e11a7eee319935e48887bb3bb050307081d5db28637d665171a8d2b14109f8c05514e1a4f98a04c0824ea7ba3f29f4b71
|
data/.gem_release.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -140,6 +140,22 @@ Option.none.expect(KeyError.new("no key"))
|
|
|
140
140
|
|
|
141
141
|
Other methods: `some?`, `none?`, `unwrap_or_else { }` and `to_a` (`[value]` for a Some, `[]` for None).
|
|
142
142
|
|
|
143
|
+
### RSpec matchers
|
|
144
|
+
|
|
145
|
+
The gem ships `be_ok_result` and `be_err_result` matchers. They aren't loaded by `require "djk_monads"`; require them in your `spec_helper.rb`:
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
require "djk/monads/expectations"
|
|
149
|
+
|
|
150
|
+
expect(Result.ok(1)).to be_ok_result
|
|
151
|
+
expect(Result.err("boom")).to be_err_result
|
|
152
|
+
|
|
153
|
+
# Pass a class to also check the wrapped error's type
|
|
154
|
+
expect(Result.err(KeyError.new("no key"))).to be_err_result(KeyError)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The matchers need `rspec-expectations`, which this gem doesn't depend on. Your app must have RSpec in its Gemfile, or requiring them raises a `LoadError`.
|
|
158
|
+
|
|
143
159
|
## Development
|
|
144
160
|
|
|
145
161
|
After checking out the repo, run `bin/setup` to install dependencies. Then run `bundle exec rake` to run the specs and RuboCop. CI also checks formatting with `bin/stree check`. `bin/console` opens an interactive prompt with the gem loaded.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rspec/expectations"
|
|
4
|
+
|
|
5
|
+
RSpec::Matchers.define :be_ok_result do
|
|
6
|
+
match { |actual| actual.is_a?(DJK::Monads::Ok) }
|
|
7
|
+
|
|
8
|
+
failure_message { |actual| "expected #{actual.inspect} to be an Ok result" }
|
|
9
|
+
|
|
10
|
+
failure_message_when_negated { |actual| "expected #{actual.inspect} not to be an Ok result" }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
RSpec::Matchers.define :be_err_result do |expected_class = nil|
|
|
14
|
+
match { |actual| actual.is_a?(DJK::Monads::Err) && (expected_class.nil? || actual.unwrap_err!.is_a?(expected_class)) }
|
|
15
|
+
|
|
16
|
+
failure_message do |actual|
|
|
17
|
+
if expected_class.nil?
|
|
18
|
+
"expected #{actual.inspect} to be an Err result"
|
|
19
|
+
elsif actual.is_a?(DJK::Monads::Err)
|
|
20
|
+
"expected #{actual.inspect} to be an Err result of type #{expected_class}, but got #{actual.unwrap_err!.class}"
|
|
21
|
+
else
|
|
22
|
+
"expected #{actual.inspect} to be an Err result of type #{expected_class}"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
failure_message_when_negated do |actual|
|
|
27
|
+
if expected_class
|
|
28
|
+
"expected #{actual.inspect} not to be an Err result of type #{expected_class}"
|
|
29
|
+
else
|
|
30
|
+
"expected #{actual.inspect} not to be an Err result"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/djk/monads/version.rb
CHANGED
data/lib/djk_monads.rb
ADDED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: djk_monads
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dan Kotowski
|
|
@@ -17,6 +17,7 @@ executables: []
|
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
|
+
- ".gem_release.yml"
|
|
20
21
|
- CHANGELOG.md
|
|
21
22
|
- CODE_OF_CONDUCT.md
|
|
22
23
|
- LICENSE.txt
|
|
@@ -24,11 +25,14 @@ files:
|
|
|
24
25
|
- lib/djk.rb
|
|
25
26
|
- lib/djk/monads.rb
|
|
26
27
|
- lib/djk/monads/err.rb
|
|
28
|
+
- lib/djk/monads/expectations.rb
|
|
29
|
+
- lib/djk/monads/expectations/result_matchers.rb
|
|
27
30
|
- lib/djk/monads/ok.rb
|
|
28
31
|
- lib/djk/monads/option.rb
|
|
29
32
|
- lib/djk/monads/result.rb
|
|
30
33
|
- lib/djk/monads/return_error.rb
|
|
31
34
|
- lib/djk/monads/version.rb
|
|
35
|
+
- lib/djk_monads.rb
|
|
32
36
|
homepage: https://github.com/djkotowski/djk_monads
|
|
33
37
|
licenses:
|
|
34
38
|
- MIT
|