convenient_service 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dev/.tmuxinator.yml +17 -0
- data/CHANGELOG.md +15 -0
- data/README.md +8 -8
- data/Taskfile.yml +30 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base.rb +245 -0
- data/lib/convenient_service/rspec/matchers/custom/results/be_error.rb +3 -139
- data/lib/convenient_service/rspec/matchers/custom/results/be_failure.rb +3 -106
- data/lib/convenient_service/rspec/matchers/custom/results/be_not_error.rb +20 -0
- data/lib/convenient_service/rspec/matchers/custom/results/be_not_failure.rb +20 -0
- data/lib/convenient_service/rspec/matchers/custom/results/be_not_success.rb +20 -0
- data/lib/convenient_service/rspec/matchers/custom/results/be_success.rb +3 -112
- data/lib/convenient_service/rspec/matchers/custom/results.rb +6 -0
- data/lib/convenient_service/rspec/matchers/results/be_not_error.rb +15 -0
- data/lib/convenient_service/rspec/matchers/results/be_not_failure.rb +15 -0
- data/lib/convenient_service/rspec/matchers/results/be_not_success.rb +15 -0
- data/lib/convenient_service/rspec/matchers/results.rb +8 -0
- data/lib/convenient_service/service/plugins/has_result/constants.rb +1 -4
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +8 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb +1 -4
- data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +8 -2
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_key.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_name.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/define_method_in_container.rb +15 -8
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities.rb +0 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/errors.rb +15 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/concern/instance_methods.rb +10 -0
- data/lib/convenient_service/support/gems/rspec.rb +9 -2
- data/lib/convenient_service/support/raw_value.rb +52 -0
- data/lib/convenient_service/support.rb +1 -0
- data/lib/convenient_service/version.rb +1 -1
- metadata +11 -4
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values/raw.rb +0 -48
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 481cc240efe2b9443d13ea66fc70dc2cd1b477c291be24b1b9e66af9e9e26e65
|
4
|
+
data.tar.gz: 07caed3e04809cd78e96818e69c99f9337a9882f689c05709ff57d38e6c5940f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35b346de371b82d3d8775a68783e1fdce3c42709bfb7aaa5a864f5bbb9c4ba494eb2f6a7f7ead303f5dcde1a079256c1cc881006cff5bc600b3c0e48a6810f6e
|
7
|
+
data.tar.gz: dac03d20c0c10765f4c1e5530d0f9d92a1ee0723f98a94f0a0804d13e2f7e3c8d28d2052a0037c08d6f5b49726038d55069a89bf3143d01b298a58e4a223c32b
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: convenient_service
|
2
|
+
root: .
|
3
|
+
|
4
|
+
on_project_start:
|
5
|
+
- task editor:open
|
6
|
+
- task docker:start
|
7
|
+
- task github:open
|
8
|
+
|
9
|
+
windows:
|
10
|
+
- main:
|
11
|
+
layout: even-vertical
|
12
|
+
root: .
|
13
|
+
panes:
|
14
|
+
- task docker:bash:ruby_2.7
|
15
|
+
- task docker:bash:ruby_3.0
|
16
|
+
- task docker:bash:ruby_3.1
|
17
|
+
- git status
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.4.0](https://github.com/marian13/convenient_service/compare/v0.3.1...v0.4.0) (2023-01-03)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* **has_jsend_status_and_attributes:** introduce data.has_attribute? ([04e4583](https://github.com/marian13/convenient_service/commit/04e45830fcb4aabc7d6473394e7d4b99e31a11d6))
|
9
|
+
* **has_result_steps:** add more contextual error message when step result data has no attribute ([5844d94](https://github.com/marian13/convenient_service/commit/5844d942a9bca4b9d4f65403c6c432e9e2b810ad))
|
10
|
+
* **results_matchers:** introduce be_not_success, be_not_failure, be_not_error ([9bb4454](https://github.com/marian13/convenient_service/commit/9bb4454fa6025bba8200a9280c25ec20cafb4c03))
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* **has_result_steps:** print step actual service, not internal wrapper ([c0761be](https://github.com/marian13/convenient_service/commit/c0761be89b8a6dacb318460ed5c55b15fdd2de0b))
|
16
|
+
* **rspec:** return nil for current example in partially loaded rspec envs ([ea10cc0](https://github.com/marian13/convenient_service/commit/ea10cc0e06dd22022f816f6760af926fb119bdf5))
|
17
|
+
|
3
18
|
## [0.3.1](https://github.com/marian13/convenient_service/compare/v0.3.0...v0.3.1) (2022-12-19)
|
4
19
|
|
5
20
|
|
data/README.md
CHANGED
@@ -38,23 +38,23 @@ This library is under heavy development. Public API may be subject to change. Th
|
|
38
38
|
<!-- features:end -->
|
39
39
|
<!-- warning:end -->
|
40
40
|
|
41
|
-
<!--
|
42
|
-
##
|
41
|
+
<!-- links:start -->
|
42
|
+
## Quick Links
|
43
43
|
|
44
44
|
- Check out [Convenient Service Official User Docs](https://marian13.github.io/convenient_service_docs/) for installation, requirements, and usage guides.
|
45
45
|
|
46
|
-
-
|
46
|
+
- Read [the API docs](https://marian13.github.io/convenient_service) to get familiar with the newest functionality that are not documented yet.
|
47
47
|
|
48
|
-
- [
|
48
|
+
- Create [an issue](https://github.com/marian13/convenient_service/issues) if you are going to report a bug.
|
49
49
|
|
50
|
-
|
50
|
+
- Start [a discussion](https://github.com/marian13/convenient_service/discussions) when you would like to request a new feature.
|
51
51
|
|
52
|
-
|
52
|
+
- Open a PR to [convenient_service_docs](https://github.com/marian13/convenient_service_docs) to add/update user docs.
|
53
53
|
|
54
|
-
<!-- links:start -->
|
55
54
|
- [RubyGems](https://rubygems.org/gems/convenient_service).
|
56
55
|
|
57
|
-
- [
|
56
|
+
- Have a look at [Convenient Service Development Wiki](https://github.com/marian13/convenient_service/wiki) for the contribution tutorials.
|
57
|
+
|
58
58
|
<!-- links:end -->
|
59
59
|
|
60
60
|
---
|
data/Taskfile.yml
CHANGED
@@ -97,6 +97,21 @@ tasks:
|
|
97
97
|
- sh: '[ "${IN_DOCKER_CONTAINER}" != "true" ]'
|
98
98
|
msg: This task can be invoked only from the host operating system (https://www.ibm.com/cloud/learn/containerization)
|
99
99
|
|
100
|
+
##
|
101
|
+
# NOTE: Dev only command.
|
102
|
+
# NOTE: macOS specific command.
|
103
|
+
#
|
104
|
+
docker:start:
|
105
|
+
cmds:
|
106
|
+
- open -a Docker
|
107
|
+
|
108
|
+
##
|
109
|
+
# NOTE: Dev only command.
|
110
|
+
#
|
111
|
+
editor:open:
|
112
|
+
cmds:
|
113
|
+
- code .
|
114
|
+
|
100
115
|
##
|
101
116
|
# NOTE: `sdoc` (wrapper for `rdoc`) is replaced by `yard`, since you have a feeling like every time is a first time with `rdoc`.
|
102
117
|
# - https://kapeli.com/cheat_sheets/Yard.docset/Contents/Resources/Documents/index
|
@@ -149,6 +164,14 @@ tasks:
|
|
149
164
|
cmds:
|
150
165
|
- git diff --cached --name-only --diff-filter=d "spec/**"
|
151
166
|
|
167
|
+
##
|
168
|
+
# NOTE: Dev only command.
|
169
|
+
# NOTE: macOS specific command.
|
170
|
+
#
|
171
|
+
github:open:
|
172
|
+
cmds:
|
173
|
+
- open -na "Google Chrome" --args --new-window --incognito "https://github.com/marian13/convenient_service"
|
174
|
+
|
152
175
|
lint:
|
153
176
|
cmds:
|
154
177
|
- task: rubocop
|
@@ -306,3 +329,10 @@ tasks:
|
|
306
329
|
rubocop:format:
|
307
330
|
cmds:
|
308
331
|
- bundle exec rubocop --config .rubocop.yml -A {{.CLI_ARGS}}
|
332
|
+
|
333
|
+
##
|
334
|
+
# NOTE: Dev only command.
|
335
|
+
#
|
336
|
+
tmuxinator:start:
|
337
|
+
cmds:
|
338
|
+
- tmuxinator start convenient_service --project-config=.dev/.tmuxinator.yml
|
@@ -0,0 +1,245 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
module Results
|
8
|
+
class Base
|
9
|
+
include Support::AbstractMethod
|
10
|
+
|
11
|
+
##
|
12
|
+
# @return [String, Symbol]
|
13
|
+
#
|
14
|
+
abstract_method :statuses
|
15
|
+
|
16
|
+
##
|
17
|
+
# @param result [ConvenientService::Service::Plugins::HasResult::Entities::Result]
|
18
|
+
# @return [Boolean]
|
19
|
+
#
|
20
|
+
def matches?(result)
|
21
|
+
@result = result
|
22
|
+
|
23
|
+
rules = []
|
24
|
+
|
25
|
+
rules << ->(result) { result.class.include?(Service::Plugins::HasResult::Entities::Result::Concern) }
|
26
|
+
rules << ->(result) { result.status.in?(statuses) }
|
27
|
+
rules << ->(result) { result.service.instance_of?(service_class) } if used_of?
|
28
|
+
rules << ->(result) { result.unsafe_data == data } if used_data?
|
29
|
+
rules << ->(result) { result.unsafe_message == message } if used_message?
|
30
|
+
rules << ->(result) { result.unsafe_code == code } if used_code?
|
31
|
+
|
32
|
+
condition = Utils::Proc.conjunct(rules)
|
33
|
+
|
34
|
+
condition.call(result)
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# @return [String]
|
39
|
+
#
|
40
|
+
def description
|
41
|
+
default_text
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# @return [String]
|
46
|
+
#
|
47
|
+
def failure_message
|
48
|
+
"expected that `#{result}` would #{default_text}"
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# @return [String]
|
53
|
+
#
|
54
|
+
# @internal
|
55
|
+
# https://relishapp.com/rspec/rspec-expectations/v/3-11/docs/custom-matchers/define-a-custom-matcher#overriding-the-failure-message-when-negated
|
56
|
+
#
|
57
|
+
def failure_message_when_negated
|
58
|
+
"expected that #{result} would NOT #{default_text}"
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# @param data [Hash]
|
63
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::Results::Base]
|
64
|
+
#
|
65
|
+
def with_data(data)
|
66
|
+
chain[:data] = data
|
67
|
+
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# @param data [Hash]
|
73
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::Results::Base]
|
74
|
+
#
|
75
|
+
def and_data(data)
|
76
|
+
chain[:data] = data
|
77
|
+
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::Results::Base]
|
83
|
+
#
|
84
|
+
def without_data
|
85
|
+
chain[:data] = {}
|
86
|
+
|
87
|
+
self
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# @param message [String]
|
92
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::Results::Base]
|
93
|
+
#
|
94
|
+
def with_message(message)
|
95
|
+
chain[:message] = message
|
96
|
+
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# @param message [String]
|
102
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::Results::Base]
|
103
|
+
#
|
104
|
+
def and_message(message)
|
105
|
+
chain[:message] = message
|
106
|
+
|
107
|
+
self
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# @return [String, Symbol]
|
112
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::Results::Base]
|
113
|
+
#
|
114
|
+
def with_code(code)
|
115
|
+
chain[:code] = code
|
116
|
+
|
117
|
+
self
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# @return [String, Symbol]
|
122
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::Results::Base]
|
123
|
+
#
|
124
|
+
def and_code(code)
|
125
|
+
chain[:code] = code
|
126
|
+
|
127
|
+
self
|
128
|
+
end
|
129
|
+
|
130
|
+
##
|
131
|
+
# @param service_class [Class]
|
132
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::Results::Base]
|
133
|
+
#
|
134
|
+
def of(service_class)
|
135
|
+
chain[:service_class] = service_class
|
136
|
+
|
137
|
+
self
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
##
|
143
|
+
# @!attribute [r] result
|
144
|
+
# @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
|
145
|
+
#
|
146
|
+
attr_reader :result
|
147
|
+
|
148
|
+
##
|
149
|
+
# @return [String]
|
150
|
+
#
|
151
|
+
def default_text
|
152
|
+
parts = []
|
153
|
+
|
154
|
+
parts << "be #{printable_statuses}"
|
155
|
+
parts << "of `#{service_class}`" if used_of?
|
156
|
+
parts << "with data `#{data}`" if used_data?
|
157
|
+
parts << "with message `#{message}`" if used_message?
|
158
|
+
parts << "with code `#{code}`" if used_code?
|
159
|
+
|
160
|
+
parts << "\n\n"
|
161
|
+
|
162
|
+
parts << "got `#{result.status}`"
|
163
|
+
parts << "of `#{result.service.class}`" if used_of?
|
164
|
+
parts << "with data `#{result.data}`" if used_data?
|
165
|
+
parts << "with message `#{result.message}`" if used_message?
|
166
|
+
parts << "with code `#{result.code}`" if used_code?
|
167
|
+
|
168
|
+
parts.join(" ")
|
169
|
+
end
|
170
|
+
|
171
|
+
##
|
172
|
+
# @return [Boolean]
|
173
|
+
#
|
174
|
+
def used_data?
|
175
|
+
chain.key?(:data)
|
176
|
+
end
|
177
|
+
|
178
|
+
##
|
179
|
+
# @return [Boolean]
|
180
|
+
#
|
181
|
+
def used_message?
|
182
|
+
chain.key?(:message)
|
183
|
+
end
|
184
|
+
|
185
|
+
##
|
186
|
+
# @return [Boolean]
|
187
|
+
#
|
188
|
+
def used_code?
|
189
|
+
chain.key?(:code)
|
190
|
+
end
|
191
|
+
|
192
|
+
##
|
193
|
+
# @return [Boolean]
|
194
|
+
#
|
195
|
+
def used_of?
|
196
|
+
chain.key?(:service_class)
|
197
|
+
end
|
198
|
+
|
199
|
+
##
|
200
|
+
# @return [Hash]
|
201
|
+
#
|
202
|
+
def data
|
203
|
+
@data ||= chain[:data] || {}
|
204
|
+
end
|
205
|
+
|
206
|
+
##
|
207
|
+
# @return [String]
|
208
|
+
#
|
209
|
+
def message
|
210
|
+
@message ||= chain[:message] || ""
|
211
|
+
end
|
212
|
+
|
213
|
+
##
|
214
|
+
# @return [String, Symbol]
|
215
|
+
#
|
216
|
+
def code
|
217
|
+
@code ||= chain[:code] || ""
|
218
|
+
end
|
219
|
+
|
220
|
+
##
|
221
|
+
# @return [Class]
|
222
|
+
#
|
223
|
+
def service_class
|
224
|
+
Utils::Object.instance_variable_fetch(self, :@service_class) { chain[:service_class] }
|
225
|
+
end
|
226
|
+
|
227
|
+
##
|
228
|
+
# @return [Hash]
|
229
|
+
#
|
230
|
+
def chain
|
231
|
+
@chain ||= {}
|
232
|
+
end
|
233
|
+
|
234
|
+
##
|
235
|
+
# @return [String]
|
236
|
+
#
|
237
|
+
def printable_statuses
|
238
|
+
statuses.map { |status| "`#{status}`" }.join(" or ")
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
@@ -5,145 +5,9 @@ module ConvenientService
|
|
5
5
|
module Matchers
|
6
6
|
module Custom
|
7
7
|
module Results
|
8
|
-
class BeError
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
rules = []
|
13
|
-
|
14
|
-
rules << ->(result) { result.class.include?(ConvenientService::Service::Plugins::HasResult::Entities::Result::Concern) }
|
15
|
-
rules << ->(result) { result.error? }
|
16
|
-
rules << ->(result) { result.service.instance_of?(service_class) } if used_of?
|
17
|
-
rules << ->(result) { result.message == message } if used_message?
|
18
|
-
rules << ->(result) { result.code == code } if used_code?
|
19
|
-
|
20
|
-
condition = ConvenientService::Utils::Proc.conjunct(rules)
|
21
|
-
|
22
|
-
condition.call(result)
|
23
|
-
end
|
24
|
-
|
25
|
-
def with_message(message)
|
26
|
-
chain[:message] = message
|
27
|
-
|
28
|
-
self
|
29
|
-
end
|
30
|
-
|
31
|
-
def and_message(message)
|
32
|
-
chain[:message] = message
|
33
|
-
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
def with_code(code)
|
38
|
-
chain[:code] = code
|
39
|
-
|
40
|
-
self
|
41
|
-
end
|
42
|
-
|
43
|
-
def and_code(code)
|
44
|
-
chain[:code] = code
|
45
|
-
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
def of(service_class)
|
50
|
-
chain[:service_class] = service_class
|
51
|
-
|
52
|
-
self
|
53
|
-
end
|
54
|
-
|
55
|
-
def description
|
56
|
-
##
|
57
|
-
# TODO: of
|
58
|
-
#
|
59
|
-
parts = []
|
60
|
-
|
61
|
-
parts << "be an `error`"
|
62
|
-
parts << "of `#{service_class}`" if used_of?
|
63
|
-
parts << "with message `#{message}`" if used_message?
|
64
|
-
parts << "with code `#{code}`" if used_code?
|
65
|
-
parts << "\n\n"
|
66
|
-
parts << "got `#{result.status}`"
|
67
|
-
parts << "of `#{result.service.class}`" if used_of?
|
68
|
-
parts << "with message `#{result.message}`" if used_message?
|
69
|
-
parts << "with code `#{result.code}`" if used_code?
|
70
|
-
|
71
|
-
parts.join(" ")
|
72
|
-
end
|
73
|
-
|
74
|
-
def failure_message
|
75
|
-
##
|
76
|
-
# TODO: got text after expect text.
|
77
|
-
#
|
78
|
-
parts = []
|
79
|
-
|
80
|
-
parts << "expected that `#{result}` would be an `error`"
|
81
|
-
parts << "of `#{service_class}`" if used_of?
|
82
|
-
parts << "with message `#{message}`" if used_message?
|
83
|
-
parts << "with code `#{code}`" if used_code?
|
84
|
-
parts << "\n\n"
|
85
|
-
parts << "got `#{result.status}`"
|
86
|
-
parts << "of `#{result.service.class}`" if used_of?
|
87
|
-
parts << "with message `#{result.message}`" if used_message?
|
88
|
-
parts << "with code `#{result.code}`" if used_code?
|
89
|
-
|
90
|
-
parts.join(" ")
|
91
|
-
end
|
92
|
-
|
93
|
-
##
|
94
|
-
# https://relishapp.com/rspec/rspec-expectations/v/3-11/docs/custom-matchers/define-a-custom-matcher#overriding-the-failure-message-when-negated
|
95
|
-
#
|
96
|
-
def failure_message_when_negated
|
97
|
-
##
|
98
|
-
# TODO: got text after expect text.
|
99
|
-
#
|
100
|
-
parts = []
|
101
|
-
|
102
|
-
parts << "expected that #{result} would NOT be an `error`"
|
103
|
-
parts << "of `#{service_class}`" if used_of?
|
104
|
-
parts << "with message `#{message}`" if used_message?
|
105
|
-
parts << "with code `#{code}`" if used_code?
|
106
|
-
parts << "\n\n"
|
107
|
-
parts << "got `#{result.status}`"
|
108
|
-
parts << "of `#{result.service.class}`" if used_of?
|
109
|
-
parts << "with message `#{result.message}`" if used_message?
|
110
|
-
parts << "with code `#{result.code}`" if used_code?
|
111
|
-
|
112
|
-
parts.join(" ")
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
|
117
|
-
attr_reader :result
|
118
|
-
|
119
|
-
def used_message?
|
120
|
-
chain.key?(:message)
|
121
|
-
end
|
122
|
-
|
123
|
-
def used_code?
|
124
|
-
chain.key?(:code)
|
125
|
-
end
|
126
|
-
|
127
|
-
def used_of?
|
128
|
-
chain.key?(:service_class)
|
129
|
-
end
|
130
|
-
|
131
|
-
def chain
|
132
|
-
@chain ||= {}
|
133
|
-
end
|
134
|
-
|
135
|
-
def message
|
136
|
-
@message ||= chain[:message] || ""
|
137
|
-
end
|
138
|
-
|
139
|
-
def code
|
140
|
-
@code ||= chain[:code] || ""
|
141
|
-
end
|
142
|
-
|
143
|
-
def service_class
|
144
|
-
return @service_class if defined? @service_class
|
145
|
-
|
146
|
-
@service_class = chain[:service_class]
|
8
|
+
class BeError < Results::Base
|
9
|
+
def statuses
|
10
|
+
[Service::Plugins::HasResult::Constants::ERROR_STATUS]
|
147
11
|
end
|
148
12
|
end
|
149
13
|
end
|
@@ -5,112 +5,9 @@ module ConvenientService
|
|
5
5
|
module Matchers
|
6
6
|
module Custom
|
7
7
|
module Results
|
8
|
-
class BeFailure
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
rules = []
|
13
|
-
|
14
|
-
rules << ->(result) { result.class.include?(ConvenientService::Service::Plugins::HasResult::Entities::Result::Concern) }
|
15
|
-
rules << ->(result) { result.failure? }
|
16
|
-
rules << ->(result) { result.service.instance_of?(service_class) } if used_of?
|
17
|
-
rules << ->(result) { result.data == data } if used_data?
|
18
|
-
|
19
|
-
condition = ConvenientService::Utils::Proc.conjunct(rules)
|
20
|
-
|
21
|
-
condition.call(result)
|
22
|
-
end
|
23
|
-
|
24
|
-
def with_data(data)
|
25
|
-
chain[:data] = data
|
26
|
-
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
def of(service_class)
|
31
|
-
chain[:service_class] = service_class
|
32
|
-
|
33
|
-
self
|
34
|
-
end
|
35
|
-
|
36
|
-
def description
|
37
|
-
##
|
38
|
-
# TODO: of
|
39
|
-
#
|
40
|
-
parts = []
|
41
|
-
|
42
|
-
parts << "be a `failure`"
|
43
|
-
parts << "of `#{service_class}`" if used_of?
|
44
|
-
parts << "with data `#{data}`" if used_data?
|
45
|
-
parts << "\n\n"
|
46
|
-
parts << "got `#{result.status}`"
|
47
|
-
parts << "of `#{result.service.class}`" if used_of?
|
48
|
-
parts << "with data `#{result.data.to_h}`" if used_data?
|
49
|
-
|
50
|
-
parts.join(" ")
|
51
|
-
end
|
52
|
-
|
53
|
-
def failure_message
|
54
|
-
##
|
55
|
-
# TODO: got text after expect text.
|
56
|
-
#
|
57
|
-
parts = []
|
58
|
-
|
59
|
-
parts << "expected that `#{result}` would be a `failure`"
|
60
|
-
parts << "of `#{service_class}`" if used_of?
|
61
|
-
parts << "with data `#{data}`" if used_data?
|
62
|
-
parts << "\n\n"
|
63
|
-
parts << "got `#{result.status}`"
|
64
|
-
parts << "of `#{result.service.class}`" if used_of?
|
65
|
-
parts << "with data `#{result.data.to_h}`" if used_data?
|
66
|
-
|
67
|
-
parts.join(" ")
|
68
|
-
end
|
69
|
-
|
70
|
-
##
|
71
|
-
# https://relishapp.com/rspec/rspec-expectations/v/3-11/docs/custom-matchers/define-a-custom-matcher#overriding-the-failure-message-when-negated
|
72
|
-
#
|
73
|
-
def failure_message_when_negated
|
74
|
-
##
|
75
|
-
# TODO: got text after expect text.
|
76
|
-
#
|
77
|
-
parts = []
|
78
|
-
|
79
|
-
parts << "expected that #{result} would NOT be a `failure`"
|
80
|
-
parts << "of `#{service_class}`" if used_of?
|
81
|
-
parts << "with data `#{data}`" if used_data?
|
82
|
-
parts << "\n\n"
|
83
|
-
parts << "got `#{result.status}`"
|
84
|
-
parts << "of `#{result.service.class}`" if used_of?
|
85
|
-
parts << "with data `#{result.data.to_h}`" if used_data?
|
86
|
-
|
87
|
-
parts.join(" ")
|
88
|
-
end
|
89
|
-
|
90
|
-
private
|
91
|
-
|
92
|
-
attr_reader :result
|
93
|
-
|
94
|
-
def used_data?
|
95
|
-
chain.key?(:data)
|
96
|
-
end
|
97
|
-
|
98
|
-
def used_of?
|
99
|
-
chain.key?(:service_class)
|
100
|
-
end
|
101
|
-
|
102
|
-
def chain
|
103
|
-
@chain ||= {}
|
104
|
-
end
|
105
|
-
|
106
|
-
def data
|
107
|
-
@data ||= chain[:data] || {}
|
108
|
-
end
|
109
|
-
|
110
|
-
def service_class
|
111
|
-
return @service_class if defined? @service_class
|
112
|
-
|
113
|
-
@service_class = chain[:service_class]
|
8
|
+
class BeFailure < Results::Base
|
9
|
+
def statuses
|
10
|
+
[Service::Plugins::HasResult::Constants::FAILURE_STATUS]
|
114
11
|
end
|
115
12
|
end
|
116
13
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
module Results
|
8
|
+
class BeNotError < Results::Base
|
9
|
+
def statuses
|
10
|
+
[
|
11
|
+
Service::Plugins::HasResult::Constants::FAILURE_STATUS,
|
12
|
+
Service::Plugins::HasResult::Constants::SUCCESS_STATUS
|
13
|
+
]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
module Results
|
8
|
+
class BeNotFailure < Results::Base
|
9
|
+
def statuses
|
10
|
+
[
|
11
|
+
Service::Plugins::HasResult::Constants::ERROR_STATUS,
|
12
|
+
Service::Plugins::HasResult::Constants::SUCCESS_STATUS
|
13
|
+
]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|