cuprum 0.9.0 → 0.9.1

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: efcbe5a6b4ca1b381c726a91e07ddd2bb8dac8c07194ce9f6b9690e86cfdf2d6
4
- data.tar.gz: adb0d828d01b2f451b7328e06d660cc69c418cfe9ae42e7187aac8b1ae465c02
3
+ metadata.gz: f867011719a69bd7080c77d450fedfee736ef6df5be2b8a2d11fe3b1006a3890
4
+ data.tar.gz: 48109c5460f817fedb8c6a46b84649a87d9c21e2d2dbadba31b31e32bdf20977
5
5
  SHA512:
6
- metadata.gz: 5fa4192edc22b4f18089aae7195b623b36e81db3fb8d0d4cf3b76d5849023362f55cad5036ea18ac9f972483b4fe5663149075597cd77ab196420d0045ffae74
7
- data.tar.gz: 9758bf698c95c686d296e815cd0283da4cbb7d8b4982f1c27f9f2e0114d2e97548fe38ee265ba7fac4a8cff86305918f6d4b830c31488efb78d62dc8fcfc61d6
6
+ metadata.gz: b272e3d32edf7449a83a8513be56f8e68e2474872621d055f5947b6605ec5c29ecbd4acc7e7155d1efd5ee122689dc564eaab312b499ff129d996c6e6599ff90
7
+ data.tar.gz: 7ad63c437101991668b8a060fa355633f46b269ad55d609fad81bf5e993b998974f43ae61bc96d2c781a10e29d83178a7b2770ec2540a121f54bf6261530fcce
@@ -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
- ## Operations
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
- ## Results
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
- ## Utilities
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
- ## Built In Functions
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
- ## Functions
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
- ## Operations
153
+ ### Operations
139
154
 
140
155
  Calling `#call` on an operation now returns the operation instance.
141
156
 
142
- ## Results
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
- ## Functions
167
+ ### Functions
153
168
 
154
169
  Now support chaining via the `#chain`, `#then`, and `#else` methods.
155
170
 
156
- ## Results
171
+ ### Results
157
172
 
158
173
  Can pass a value and/or an errors object to the constructor.
159
174
 
@@ -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
- - :clear_errors => true option on #chain
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
- #### Hooks
89
+ #### Dependency Injection
90
+
91
+ - shorthand for referencing a sequence of operations
@@ -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.
@@ -9,7 +9,7 @@ module RSpec
9
9
  end
10
10
 
11
11
  def be_a_passing_result
12
- be_a_result.with_status(:success)
12
+ be_a_result.with_status(:success).and_error(nil)
13
13
  end
14
14
 
15
15
  def be_a_result
@@ -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? || expected_status? || expected_value?
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 expected.respond_to?(:description)
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
- def properties_description # rubocop:disable Metrics/AbcSize
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
 
@@ -10,7 +10,7 @@ module Cuprum
10
10
  # Minor version.
11
11
  MINOR = 9
12
12
  # Patch version.
13
- PATCH = 0
13
+ PATCH = 1
14
14
  # Prerelease version.
15
15
  PRERELEASE = nil
16
16
  # Build metadata.
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.0
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-10-15 00:00:00.000000000 Z
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