dry-monads 1.8.1 → 1.8.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: 783c06bb3d7f0f2c9ab7e651ff30231495564a525cedd225d86f3c1340d7323b
4
- data.tar.gz: d101ed3414fc9066d850fe7bd47554b2882a7fa719ddabe2476cf31c393d655d
3
+ metadata.gz: 0aa936c14c5b5099ef82374d3fdf1d09ac321089b24ff5928646915c5474c156
4
+ data.tar.gz: 3b0e347df2726f44c3a85d12dfb33e174e034c82d2de2ebd140550ac116e20d2
5
5
  SHA512:
6
- metadata.gz: 6607ce497fc4ca210177ab690bb8190a185206f3f29e9ad91d064a6caa876ca8d2afd1ff2fddd9d8ef014203a6ecdde6a4b230436aa6346b50e2c4a883e4ecce
7
- data.tar.gz: f1f94fc5cb99943aaa1af41a0fa0104531ed0bce2623a606a583b10355b4bb48ef2645e2e481d072739494d17ecceedc837c5fe7a4fffd85481e7e808dffc72c
6
+ metadata.gz: 5c881bc75da61d00e66d06ae79b1ab898cd62c1fd77bba22fe5a67ee89b024f2164d66e277c84f65e83dfa8c54901538b09e1d33a4db7393ccbe26adea7a0d01
7
+ data.tar.gz: b01cb23a977f6bb61f4b5505816562dc28431a53d9e0e2f9e01fa37d2545cd6ebc29e7c22cb76b868f77a82beecfe3f90a04b6de4502eb38af0ca1987429cef1
data/CHANGELOG.md CHANGED
@@ -1,11 +1,21 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.8.2 2025-03-15
4
+
5
+
6
+ ### Fixed
7
+
8
+ - Fix be_* matchers for non-monadic values (@flash-gordon, issue #186)
9
+
10
+
11
+ [Compare v1.8.1...v1.8.2](https://github.com/dry-rb/dry-monads/compare/v1.8.1...v1.8.2)
12
+
3
13
  ## 1.8.1 2025-03-12
4
14
 
5
15
 
6
16
  ### Fixed
7
17
 
8
- - Exclude extensions from the Zeitwerk loader (fix #185) (@flash-gordon)
18
+ - Exclude extensions from the Zeitwerk loader (@flash-gordon, issue #185)
9
19
 
10
20
 
11
21
  [Compare v1.8.0...v1.8.1](https://github.com/dry-rb/dry-monads/compare/v1.8.0...v1.8.1)
@@ -16,7 +16,7 @@ module Dry
16
16
  module Matchers
17
17
  extend ::RSpec::Matchers::DSL
18
18
 
19
- {
19
+ PREDICATES = {
20
20
  failure: {
21
21
  expected_classes: [
22
22
  ::Dry::Monads::Result::Failure,
@@ -34,18 +34,24 @@ module Dry
34
34
  extract_value: :value!.to_proc
35
35
  },
36
36
  some: {
37
- expected_classes: [
38
- ::Dry::Monads::Maybe::Some
39
- ],
37
+ expected_classes: [::Dry::Monads::Maybe::Some],
40
38
  extract_value: :value!.to_proc
41
39
  }
42
- }.each do |name, args|
40
+ }.freeze
41
+
42
+ CONSTRUCTOR_CLASSES = PREDICATES.values.flat_map { |definition|
43
+ definition[:expected_classes]
44
+ }.freeze
45
+
46
+ PREDICATES.each do |name, args|
43
47
  args => { expected_classes:, extract_value: }
44
48
  expected_constructors = expected_classes.map(&:name).map do |c|
45
49
  c.split("::").last
46
50
  end
47
51
 
48
52
  matcher :"be_#{name}" do |expected = Undefined|
53
+ predicate = "#{name}?"
54
+
49
55
  match do |actual|
50
56
  if expected_classes.any? { |klass| actual.is_a?(klass) }
51
57
  exact_match = actual.is_a?(expected_classes[0])
@@ -59,6 +65,8 @@ module Dry
59
65
  else
60
66
  false
61
67
  end
68
+ elsif actual.respond_to?(predicate)
69
+ actual.__send__(predicate)
62
70
  else
63
71
  false
64
72
  end
@@ -66,12 +74,16 @@ module Dry
66
74
 
67
75
  failure_message do |actual|
68
76
  if expected_classes.none? { |klass| actual.is_a?(klass) }
69
- if expected_classes.size > 1
77
+ if actual.respond_to?(predicate)
78
+ "expected #{actual.inspect}.#{predicate} to return truthy value, " \
79
+ "but it returned false or nil"
80
+ elsif expected_classes.size > 1
70
81
  "expected #{actual.inspect} to be one of the following values: " \
71
- "#{expected_constructors.join(", ")}, but it's #{actual.class}"
72
- else
73
- "expected #{actual.inspect} to be a #{expected_constructors[0]} value, " \
82
+ "#{expected_constructors.join(", ")} or respond to #{predicate}, " \
74
83
  "but it's #{actual.class}"
84
+ else
85
+ "expected #{actual.inspect} to be a #{expected_constructors[0]} value " \
86
+ "or respond to #{predicate}, but it's #{actual.class}"
75
87
  end
76
88
  elsif actual.is_a?(expected_classes[0]) && block_arg
77
89
  "expected #{actual.inspect} to have a value satisfying the given block"
@@ -82,7 +94,15 @@ module Dry
82
94
  end
83
95
 
84
96
  failure_message_when_negated do |actual|
85
- if expected_classes.size > 1
97
+ if expected_classes.none? { |klass| actual.is_a?(klass) }
98
+ if actual.respond_to?(predicate)
99
+ "expected #{actual.inspect}.#{predicate} to return falsey value, " \
100
+ "but it returned truthy value"
101
+ else
102
+ "expected #{actual.inspect} to respond to #{predicate}, " \
103
+ "but it doesn't"
104
+ end
105
+ elsif expected_classes.size > 1
86
106
  "expected #{actual.inspect} to not be one of the following values: " \
87
107
  "#{expected_constructors.join(", ")}, but it is"
88
108
  else
@@ -96,9 +116,7 @@ module Dry
96
116
  end
97
117
 
98
118
  matcher :be_none do
99
- match do |actual|
100
- actual.is_a?(::Dry::Monads::Maybe::None)
101
- end
119
+ match { |actual| actual.is_a?(::Dry::Monads::Maybe::None) }
102
120
 
103
121
  failure_message do |actual|
104
122
  "expected #{actual.inspect} to be none"
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  module Monads
5
5
  # Gem version
6
- VERSION = "1.8.1"
6
+ VERSION = "1.8.2"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-monads
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Shilnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-12 00:00:00.000000000 Z
11
+ date: 2025-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby