djk_monads 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6f330ae60b92a91bef13cc75f8bde18a7c899d1fedd5a4b31351b1a514e95f7
4
- data.tar.gz: e6c883dae9cdfea03a68114867529e055257da1927d689ad49e9b01eff153da0
3
+ metadata.gz: b30c229861aed4c358bf22661ceb3d8f205d2a9e8a6c5968f94ad4ffa9293eef
4
+ data.tar.gz: 8cb0f86b3183e0bda40c7ba494851ba3eaa8683405ea81056d6475e03f378165
5
5
  SHA512:
6
- metadata.gz: da8133cfe913bd04cc44d0524adcd6cbdc6d0915532bfa04d221d151e1843b75297aa8484ceeb78c47d543e48268111ec7c5b0a6af04a0df5631b0af8321aa0d
7
- data.tar.gz: e98d7fa303e01433906ef2023a9d220dab309487b1f648979f0b4ea42e55a9cef574f70f0aba99009b33ba32752e631a91d5b5692bfaa662fdf0e9003a0bc9e5
6
+ metadata.gz: 1b1d880512a0d912263eb913dd4dd0a744dc6738367350389ab4dcbb1379c3242c0049f9d4c96f401fb9a0b473362bcee0ad76fe5e3abe874207d7884e9cb84f
7
+ data.tar.gz: bed23a372a2bacdf245a9eb7076a389e11a7eee319935e48887bb3bb050307081d5db28637d665171a8d2b14109f8c05514e1a4f98a04c0824ea7ba3f29f4b71
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2026-10-09
4
+
5
+ - Add opt-in `be_ok_result` and `be_err_result` RSpec matchers, loaded with `require "djk/monads/expectations"`
6
+
3
7
  ## [0.1.0] - 2026-09-25
4
8
 
5
9
  - Initial release
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
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../djk"
4
+ require_relative "expectations/result_matchers"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module DJK
4
4
  module Monads
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Kotowski
@@ -25,6 +25,8 @@ files:
25
25
  - lib/djk.rb
26
26
  - lib/djk/monads.rb
27
27
  - lib/djk/monads/err.rb
28
+ - lib/djk/monads/expectations.rb
29
+ - lib/djk/monads/expectations/result_matchers.rb
28
30
  - lib/djk/monads/ok.rb
29
31
  - lib/djk/monads/option.rb
30
32
  - lib/djk/monads/result.rb