cuprum 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -9
- data/DEVELOPMENT.md +28 -22
- data/lib/cuprum/operation.rb +6 -0
- data/lib/cuprum/rspec/be_a_result.rb +1 -1
- data/lib/cuprum/rspec/be_a_result_matcher.rb +19 -4
- data/lib/cuprum/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f867011719a69bd7080c77d450fedfee736ef6df5be2b8a2d11fe3b1006a3890
|
4
|
+
data.tar.gz: 48109c5460f817fedb8c6a46b84649a87d9c21e2d2dbadba31b31e32bdf20977
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b272e3d32edf7449a83a8513be56f8e68e2474872621d055f5947b6605ec5c29ecbd4acc7e7155d1efd5ee122689dc564eaab312b499ff129d996c6e6599ff90
|
7
|
+
data.tar.gz: 7ad63c437101991668b8a060fa355633f46b269ad55d609fad81bf5e993b998974f43ae61bc96d2c781a10e29d83178a7b2770ec2540a121f54bf6261530fcce
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.9.1
|
4
|
+
|
5
|
+
### Operations
|
6
|
+
|
7
|
+
Delegate Operation#status to the most recent result.
|
8
|
+
|
9
|
+
### RSpec
|
10
|
+
|
11
|
+
The #be_a_passing_result macro now automatically adds a `with_error(nil)` expectation.
|
12
|
+
|
13
|
+
- This causes the error (if any) to be displayed when matching a failing result.
|
14
|
+
- This may break some cases when expecting a passing result that still has an error; in these cases, add an error expectation to the call, e.g. `expect().to be_a_passing_result.with_error(some_error)`.
|
15
|
+
|
16
|
+
Improve failure message of BeAResultMatcher under some circumstances.
|
17
|
+
|
3
18
|
## 0.9.0
|
4
19
|
|
5
20
|
The "'Tis Not Too Late To Seek A Newer World" Update
|
@@ -101,21 +116,21 @@ The "Name Not Found For NullFunction" Update.
|
|
101
116
|
|
102
117
|
Added the `Cuprum::warn` helper, which prints a warning message. By default, `::warn` delegates to `Kernel#warn`, but can be configured (e.g. to call a Logger) by setting `Cuprum::warning_proc=` with a Proc that accepts one argument (the message to display).
|
103
118
|
|
104
|
-
|
119
|
+
### Operations
|
105
120
|
|
106
121
|
The implementation of `Cuprum::Operation` has been extracted to a module at `Cuprum::Operation::Mixin`, allowing users to easily convert an existing function class or instance to an operation.
|
107
122
|
|
108
|
-
|
123
|
+
### Results
|
109
124
|
|
110
125
|
Implemented `Cuprum::Result#==` as a fuzzy comparison, allowing a result to be equal to any object with the same value and status.
|
111
126
|
|
112
127
|
Implemented `Cuprum::Result#empty?`, which returns true for a new result and false for a result with a value, with non-empty errors, a result with set status, or a halted result.
|
113
128
|
|
114
|
-
|
129
|
+
### Utilities
|
115
130
|
|
116
131
|
Added the `Cuprum::Utils::InstanceSpy` module to empower testing of code that calls a function without providing a reference, such as some chained functions.
|
117
132
|
|
118
|
-
|
133
|
+
### Built In Functions
|
119
134
|
|
120
135
|
Added the `NullFunction` and `NullOperation` predefined classes, which do nothing when called and return a result with no errors and a value of nil.
|
121
136
|
|
@@ -125,7 +140,7 @@ Added the `IdentityFunction` and `IdentityOperation` predefined classes, which r
|
|
125
140
|
|
126
141
|
The "Halt And Catch Fire" Update.
|
127
142
|
|
128
|
-
|
143
|
+
### Functions
|
129
144
|
|
130
145
|
Can now call `#success!` or `#failure!` in a function block or `#process` method to override the default, error-based status for the result. This allows for a passing result that still has errors, or a failing result that does not have explicit errors.
|
131
146
|
|
@@ -135,11 +150,11 @@ Can now generate results with custom error objects by overriding the `#build_err
|
|
135
150
|
|
136
151
|
Fixed an inconsistency issue when a function block or `#process` method returned an instance of `Cuprum::Result`.
|
137
152
|
|
138
|
-
|
153
|
+
### Operations
|
139
154
|
|
140
155
|
Calling `#call` on an operation now returns the operation instance.
|
141
156
|
|
142
|
-
|
157
|
+
### Results
|
143
158
|
|
144
159
|
Can now call `#success!` or `#failure!` to override the default, error-based status.
|
145
160
|
|
@@ -149,11 +164,11 @@ Can now call `#halt!` and check the `#halted?` status. A halted result will prev
|
|
149
164
|
|
150
165
|
The "Nothing To Lose But Your Chains" Update.
|
151
166
|
|
152
|
-
|
167
|
+
### Functions
|
153
168
|
|
154
169
|
Now support chaining via the `#chain`, `#then`, and `#else` methods.
|
155
170
|
|
156
|
-
|
171
|
+
### Results
|
157
172
|
|
158
173
|
Can pass a value and/or an errors object to the constructor.
|
159
174
|
|
data/DEVELOPMENT.md
CHANGED
@@ -17,12 +17,36 @@ The "One Small Step" Update
|
|
17
17
|
- Called with command (block? method?) that returns a Result.
|
18
18
|
- Raise (and catch) exception on non-success Result (test custom status?)
|
19
19
|
- Otherwise return Result#value.
|
20
|
+
- Deprecate #chain and its related methods
|
21
|
+
|
22
|
+
### Documentation
|
23
|
+
|
24
|
+
Steps Case Study: |
|
25
|
+
|
26
|
+
CMS application - creating a new post.
|
27
|
+
Directory has many Posts
|
28
|
+
Post has a Content
|
29
|
+
Content has many ContentVersions
|
30
|
+
Post has many Tags
|
31
|
+
|
32
|
+
Find Directory
|
33
|
+
Create Post
|
34
|
+
Create Content
|
35
|
+
Create ContentVersion
|
36
|
+
Tags.each { FindOrCreate Tag }
|
20
37
|
|
21
38
|
### Matcher
|
22
39
|
|
23
40
|
- Handle success(), failure(), failure(SomeError) cases.
|
24
41
|
- Custom matcher to handle additional cases - halted, pending, etc?
|
25
42
|
|
43
|
+
### RSpec
|
44
|
+
|
45
|
+
- be_callable matcher - delegates to respond_to(), but check arguments of
|
46
|
+
private #process method
|
47
|
+
- call_command_step matcher
|
48
|
+
- (optionally) alias be_a_result family as have_result for operations
|
49
|
+
|
26
50
|
## Version 1.0.0
|
27
51
|
|
28
52
|
'The "Look On My Works, Ye Mighty, and Despair" Update'
|
@@ -34,7 +58,7 @@ The "One Small Step" Update
|
|
34
58
|
### Commands
|
35
59
|
|
36
60
|
- Command#to_proc
|
37
|
-
-
|
61
|
+
- Remove #chain and its related methods
|
38
62
|
|
39
63
|
### Commands - Built In
|
40
64
|
|
@@ -42,22 +66,6 @@ The "One Small Step" Update
|
|
42
66
|
as array
|
43
67
|
- RetryCommand
|
44
68
|
|
45
|
-
### Documentation
|
46
|
-
|
47
|
-
Chaining Case Study: |
|
48
|
-
|
49
|
-
CMS application - creating a new post.
|
50
|
-
Directory has many Posts
|
51
|
-
Post has a Content
|
52
|
-
Content has many ContentVersions
|
53
|
-
Post has many Tags
|
54
|
-
|
55
|
-
Find Directory
|
56
|
-
Create Post
|
57
|
-
Create Content
|
58
|
-
Create ContentVersion
|
59
|
-
Tags.each { FindOrCreate Tag }
|
60
|
-
|
61
69
|
## Future Versions
|
62
70
|
|
63
71
|
### Commands
|
@@ -68,10 +76,6 @@ Chaining Case Study: |
|
|
68
76
|
|
69
77
|
- ::process - shortcut for defining #process
|
70
78
|
- ::rescue - `rescue StandardError do ... end`, rescues matched errors in #process
|
71
|
-
- chaining methods:
|
72
|
-
- ::chain (::success, ::failure):
|
73
|
-
on #initialize, chains the given command. Can be given a command class
|
74
|
-
(if ::new takes no arguments) or a block that returns a command.
|
75
79
|
- constructor methods:
|
76
80
|
- Programmatically generate a constructor method. Raises an error if
|
77
81
|
#initialize is defined. Automatically sets instance variables on initialize,
|
@@ -82,4 +86,6 @@ Chaining Case Study: |
|
|
82
86
|
optional arguments and their default values.
|
83
87
|
- ::keywords - sets keyword arguments; same arguments as ::arguments.
|
84
88
|
|
85
|
-
####
|
89
|
+
#### Dependency Injection
|
90
|
+
|
91
|
+
- shorthand for referencing a sequence of operations
|
data/lib/cuprum/operation.rb
CHANGED
@@ -101,6 +101,12 @@ module Cuprum
|
|
101
101
|
@result = nil
|
102
102
|
end # method reset
|
103
103
|
|
104
|
+
# @return [Symbol, nil] the status of the most recent result, or nil if
|
105
|
+
# the operation has not been called.
|
106
|
+
def status
|
107
|
+
called? ? result.status : nil
|
108
|
+
end
|
109
|
+
|
104
110
|
# @return [Boolean] true if the most recent result had no error, or false
|
105
111
|
# if the most recent result had an error or if the operation has not
|
106
112
|
# been called.
|
@@ -10,6 +10,9 @@ module Cuprum::RSpec
|
|
10
10
|
DEFAULT_VALUE = Object.new.freeze
|
11
11
|
private_constant :DEFAULT_VALUE
|
12
12
|
|
13
|
+
RSPEC_MATCHER_METHODS = %i[description failure_message matches?].freeze
|
14
|
+
private_constant :RSPEC_MATCHER_METHODS
|
15
|
+
|
13
16
|
def initialize
|
14
17
|
@expected_error = DEFAULT_VALUE
|
15
18
|
@expected_value = DEFAULT_VALUE
|
@@ -151,7 +154,9 @@ module Cuprum::RSpec
|
|
151
154
|
end
|
152
155
|
|
153
156
|
def expected_properties?
|
154
|
-
expected_error?
|
157
|
+
(expected_error? && !expected_error.nil?) ||
|
158
|
+
expected_status? ||
|
159
|
+
expected_value?
|
155
160
|
end
|
156
161
|
|
157
162
|
def expected_error?
|
@@ -167,7 +172,7 @@ module Cuprum::RSpec
|
|
167
172
|
end
|
168
173
|
|
169
174
|
def inspect_expected(expected)
|
170
|
-
return expected.description if
|
175
|
+
return expected.description if rspec_matcher?(expected)
|
171
176
|
|
172
177
|
expected.inspect
|
173
178
|
end
|
@@ -177,11 +182,13 @@ module Cuprum::RSpec
|
|
177
182
|
' positives, since any other result will match.'
|
178
183
|
end
|
179
184
|
|
180
|
-
|
185
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
186
|
+
# rubocop:disable Metrics/AbcSize
|
187
|
+
def properties_description
|
181
188
|
msg = ''
|
182
189
|
ary = []
|
183
190
|
ary << 'value' if expected_value?
|
184
|
-
ary << 'error' if expected_error?
|
191
|
+
ary << 'error' if expected_error? && !expected_error.nil?
|
185
192
|
|
186
193
|
unless ary.empty?
|
187
194
|
msg = "with the expected #{tools.array.humanize_list(ary)}"
|
@@ -193,6 +200,8 @@ module Cuprum::RSpec
|
|
193
200
|
|
194
201
|
msg + " and status: #{expected_status.inspect}"
|
195
202
|
end
|
203
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
204
|
+
# rubocop:enable Metrics/AbcSize
|
196
205
|
|
197
206
|
def properties_failure_message
|
198
207
|
properties_short_message +
|
@@ -234,6 +243,12 @@ module Cuprum::RSpec
|
|
234
243
|
@result ||= actual.to_cuprum_result
|
235
244
|
end
|
236
245
|
|
246
|
+
def rspec_matcher?(value)
|
247
|
+
RSPEC_MATCHER_METHODS.all? do |method_name|
|
248
|
+
value.respond_to?(method_name)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
237
252
|
def status_failure_message
|
238
253
|
return '' if status_matches?
|
239
254
|
|
data/lib/cuprum/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuprum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob "Merlin" Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sleeping_king_studios-tools
|