convenient_service 0.2.0 → 0.3.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +6 -6
  3. data/CHANGELOG.md +16 -0
  4. data/ROADMAP.md +5 -0
  5. data/Taskfile.yml +3 -3
  6. data/env.rb +4 -0
  7. data/lib/convenient_service/configs/standard.rb +16 -0
  8. data/lib/convenient_service/dependencies/built_in.rb +8 -0
  9. data/lib/convenient_service/dependencies.rb +37 -0
  10. data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +3 -1
  11. data/lib/convenient_service/examples/dry/gemfile/services/assert_file_exists.rb +1 -1
  12. data/lib/convenient_service/examples/dry/gemfile/services/assert_file_not_empty.rb +1 -1
  13. data/lib/convenient_service/examples/dry/gemfile/services/assert_npm_package_available.rb +1 -1
  14. data/lib/convenient_service/examples/dry/gemfile/services/parse_content.rb +1 -1
  15. data/lib/convenient_service/examples/dry/gemfile/services/print_shell_command.rb +1 -1
  16. data/lib/convenient_service/examples/dry/gemfile/services/read_file_content.rb +1 -1
  17. data/lib/convenient_service/examples/dry/gemfile/services/run_shell.rb +1 -1
  18. data/lib/convenient_service/examples/dry/gemfile/services/strip_comments.rb +1 -1
  19. data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +3 -1
  20. data/lib/convenient_service/examples/rails/gemfile/services/assert_file_exists.rb +1 -1
  21. data/lib/convenient_service/examples/rails/gemfile/services/assert_file_not_empty.rb +1 -1
  22. data/lib/convenient_service/examples/rails/gemfile/services/assert_npm_package_available.rb +1 -1
  23. data/lib/convenient_service/examples/rails/gemfile/services/parse_content.rb +1 -1
  24. data/lib/convenient_service/examples/rails/gemfile/services/print_shell_command.rb +1 -1
  25. data/lib/convenient_service/examples/rails/gemfile/services/read_file_content.rb +1 -1
  26. data/lib/convenient_service/examples/rails/gemfile/services/run_shell.rb +1 -1
  27. data/lib/convenient_service/examples/rails/gemfile/services/strip_comments.rb +1 -1
  28. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/result_spec.rb +17 -1
  29. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/stubbed_service.rb +47 -53
  30. data/lib/convenient_service/rspec/matchers/custom/cache_its_value.rb +7 -7
  31. data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +50 -12
  32. data/lib/convenient_service/service/plugins/can_have_stubbed_result/concern.rb +32 -0
  33. data/lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb +36 -0
  34. data/lib/convenient_service/service/plugins/can_have_stubbed_result.rb +4 -0
  35. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb +29 -17
  36. data/lib/convenient_service/service/plugins/has_result_params_validations/using_dry_validation/middleware.rb +19 -9
  37. data/lib/convenient_service/service/plugins/has_result_steps/middleware.rb +1 -1
  38. data/lib/convenient_service/service/plugins.rb +1 -0
  39. data/lib/convenient_service/support/cache.rb +26 -0
  40. data/lib/convenient_service/support/gems/active_model.rb +36 -0
  41. data/lib/convenient_service/support/gems/rspec.rb +36 -0
  42. data/lib/convenient_service/support/gems.rb +4 -0
  43. data/lib/convenient_service/support/ruby.rb +22 -0
  44. data/lib/convenient_service/support/version/null_version.rb +78 -0
  45. data/lib/convenient_service/support/version.rb +65 -0
  46. data/lib/convenient_service/support.rb +3 -0
  47. data/lib/convenient_service/utils/object/instance_variable_fetch.rb +53 -0
  48. data/lib/convenient_service/utils/object.rb +9 -0
  49. data/lib/convenient_service/version.rb +1 -1
  50. metadata +12 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03335557e59a7d6c469fe20e478efb1d7f9563d7651b5e0761e61d820e7515e6
4
- data.tar.gz: 055c3cfaa2b176689bf8cc105d649a40779788279c89bd1f5a6bdfde8d7994c1
3
+ metadata.gz: b6eab7876ae6995ff2a0f2f4322a972ad05aae9b4ef3beea93daee900779dc39
4
+ data.tar.gz: 11d7e604831dda483449dc2b2513c0fc5817fd6172740836e5e3929b7d6fbcd4
5
5
  SHA512:
6
- metadata.gz: f9f55f6baab2736bcbb8661a55bb494bdfb1f7e000a87b3c7c78f326b417e44bcd69cccb992b54435ec10ce919afc2e3a7cd73695858025fa241aff609b9882c
7
- data.tar.gz: 72778dcdb0df0003b3c9b13a266af24a9c8de4150ed7d048887bd5007b223c88ce34c9494c186c5ac49ba0102ca5bd31858e37d55698fe1cfb49fe22dd6ed6e7
6
+ metadata.gz: b422032aa3b32d20579fdcc7e540a5d48e6dd18b3b69182b4b7bc456bbd8a381dd1cdab5654662e1074e095a124d15751aa001d15a36c21518dba0a1683f7130
7
+ data.tar.gz: bc8142c8d9df3971efb3476131608aae89477a46ecbe2efe42e31555f52e2425930c122ff93f8d941f4b44aa1c81b291079b5e11ea0249cfea0d0dd47a0846b7
@@ -128,14 +128,14 @@ jobs:
128
128
  run: task rspec:standard
129
129
  - name: Install dependencies for appraisals
130
130
  run: task deps:install
131
- - name: Run RSpec with Rails 5.2
132
- run: task rspec:rails_5.2
133
- - name: Run RSpec with Rails 6.0
134
- run: task rspec:rails_6.0
135
- - name: Run RSpec with Rails 6.1
136
- run: task rspec:rails_6.1
137
131
  - name: Run RSpec with Rails 7.0
138
132
  run: task rspec:rails_7.0
133
+ - name: Run RSpec with Rails 6.1
134
+ run: task rspec:rails_6.1
135
+ - name: Run RSpec with Rails 6.0
136
+ run: task rspec:rails_6.0
137
+ - name: Run RSpec with Rails 5.2
138
+ run: task rspec:rails_5.2
139
139
  - name: Run RSpec with Dry
140
140
  run: task rspec:dry
141
141
  ##
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.0](https://github.com/marian13/convenient_service/compare/v0.2.1...v0.3.0) (2022-12-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * **stub_service:** stub_service supports stubbing with different arguments ([766eb5a](https://github.com/marian13/convenient_service/commit/766eb5a25cfbd49b699ca5c0c0ffa5524dc46548))
9
+
10
+ ## [0.2.1](https://github.com/marian13/convenient_service/compare/v0.2.0...v0.2.1) (2022-12-14)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **has_result_steps:** return step copy to have fresh state ([55cc368](https://github.com/marian13/convenient_service/commit/55cc368484641040c0c76ecb38872cc9a268397c), [fc7cebb](https://github.com/marian13/convenient_service/commit/fc7cebb4e159af7b35eac3cf8c25c7009e14c9d1))
16
+ * **standard:** place UsingActiveModelValidations before HasResultSteps ([4c43205](https://github.com/marian13/convenient_service/commit/4c43205382da2e7ae395fea6639c2bcc43d1eec2))
17
+ * **standard:** place UsingDryValidation before HasResultSteps ([63c31c0](https://github.com/marian13/convenient_service/commit/63c31c04ac7c2581defd3557aad13db3188806ba))
18
+
3
19
  ## [0.2.0](https://github.com/marian13/convenient_service/compare/v0.1.0...v0.2.0) (2022-11-26)
4
20
 
5
21
 
data/ROADMAP.md CHANGED
@@ -48,5 +48,10 @@
48
48
  | Low | 🚧 | [Receive Counts](https://relishapp.com/rspec/rspec-mocks/docs/setting-constraints/receive-counts) for `delegate_to` | |
49
49
  | Low | 🚧 | Prefer versioning instead of modification plugin | |
50
50
  | Low | 🚧 | Consider to move `__steps__` and `__callbacks__` to `internals_class` | Benefit? |
51
+ | Medium | 🚧 | User friendly `raise` that removes lib backtrace from caller | Should have a `debug` mode. Should work well with examples. Check RSpec `CallerFilter.first_non_rspec_line` |
52
+ | High | 🚧 | A plugin that catches `StandardError` and returns `failure` | Should be the lowest in the stack |
53
+ | High | 🚧 | `Support::Command` alias | Should be visible to the end user |
54
+ | Low | 🚧 | Parallel steps | A killer feature |
55
+ | Medium | 🚧 | Add Ruby 3.2 support to Docker and CI | |
51
56
 
52
57
  Search for `TODO`s in the codebase for more tasks.
data/Taskfile.yml CHANGED
@@ -201,10 +201,10 @@ tasks:
201
201
  rspec:
202
202
  cmds:
203
203
  - task: rspec:standard
204
- - task: rspec:rails_5.2
205
- - task: rspec:rails_6.0
206
- - task: rspec:rails_6.1
207
204
  - task: rspec:rails_7.0
205
+ - task: rspec:rails_6.1
206
+ - task: rspec:rails_6.0
207
+ - task: rspec:rails_5.2
208
208
  - task: rspec:dry
209
209
 
210
210
  ##
data/env.rb CHANGED
@@ -12,8 +12,12 @@
12
12
  #
13
13
  ENV["APPRAISAL_NAME"] ||= ENV["BUNDLE_GEMFILE"].to_s.then(&File.method(:basename)).then { |name| name.end_with?(".gemfile") ? name.delete_suffix(".gemfile") : "" }
14
14
 
15
+ puts "ENV[\"APPRAISAL_NAME\"] -> `#{ENV["APPRAISAL_NAME"]}`"
16
+
15
17
  ##
16
18
  # NOTE: Ruby version may be set by docker.
17
19
  # https://github.com/docker-library/ruby/blob/master/3.1/alpine3.16/Dockerfile#L30
18
20
  #
19
21
  ENV["RUBY_VERSION"] ||= ::RUBY_VERSION
22
+
23
+ puts "ENV[\"RUBY_VERSION\"] -> `#{ENV["RUBY_VERSION"]}`"
@@ -81,6 +81,10 @@ module ConvenientService
81
81
  use Plugins::Service::HasResultShortSyntax::Error::Middleware
82
82
  end
83
83
 
84
+ middlewares :result, scope: :class do
85
+ use Plugins::Common::NormalizesEnv::Middleware
86
+ end
87
+
84
88
  middlewares :step, scope: :class do
85
89
  use Plugins::Common::NormalizesEnv::Middleware
86
90
 
@@ -202,6 +206,18 @@ module ConvenientService
202
206
  end
203
207
  end
204
208
  end
209
+
210
+ if Dependencies.rspec.loaded?
211
+ concerns do
212
+ insert_before 0, Plugins::Service::CanHaveStubbedResult::Concern
213
+ end
214
+
215
+ middlewares :result, scope: :class do
216
+ insert_after \
217
+ Plugins::Common::NormalizesEnv::Middleware,
218
+ Plugins::Service::CanHaveStubbedResult::Middleware
219
+ end
220
+ end
205
221
  end
206
222
  # rubocop:enable Lint/ConstantDefinitionInBlock
207
223
  end
@@ -28,6 +28,14 @@ require "logger"
28
28
  #
29
29
  require "ostruct"
30
30
 
31
+ ##
32
+ # @internal
33
+ # - https://ruby-doc.org/stdlib-2.7.0/libdoc/rubygems/rdoc/Gem/Version.html
34
+ # - https://github.com/rubygems/rubygems
35
+ # - https://github.com/rubygems/rubygems/blob/master/lib/rubygems/version.rb
36
+ #
37
+ require "rubygems"
38
+
31
39
  ##
32
40
  # @internal
33
41
  # - https://ruby-doc.org/stdlib-2.7.0/libdoc/singleton/rdoc/Singleton.html
@@ -42,10 +42,23 @@ module ConvenientService
42
42
  require_relative "common/plugins/has_attributes/using_active_model_attributes"
43
43
  end
44
44
 
45
+ ##
46
+ # @return [Boolean]
47
+ # @api private
48
+ #
49
+ def support_has_result_params_validations_using_active_model_validations?
50
+ return false unless active_model.loaded?
51
+ return false if ruby.version >= 3.0 && active_model.version < 6.0
52
+
53
+ true
54
+ end
55
+
45
56
  ##
46
57
  # @return [Boolean]
47
58
  # @note Expected to be called from app entry points like `initializers` in Rails.
48
59
  #
60
+ # @see https://marian13.github.io/convenient_service_docs/troubleshooting/i18n_translate_wrong_number_of_arguments
61
+ #
49
62
  def require_has_result_params_validations_using_active_model_validations
50
63
  require "active_model"
51
64
 
@@ -129,6 +142,30 @@ module ConvenientService
129
142
 
130
143
  require_relative "examples/dry/gemfile"
131
144
  end
145
+
146
+ ##
147
+ # @return [ConvenientService::Support::Ruby]
148
+ # @api private
149
+ #
150
+ def ruby
151
+ Support::Ruby
152
+ end
153
+
154
+ ##
155
+ # @return [ConvenientService::Support::RSpec]
156
+ # @api private
157
+ #
158
+ def rspec
159
+ Support::Gems::RSpec
160
+ end
161
+
162
+ ##
163
+ # @return [ConvenientService::Support::Gems::ActiveModel]
164
+ # @api private
165
+ #
166
+ def active_model
167
+ Support::Gems::ActiveModel
168
+ end
132
169
  end
133
170
  end
134
171
  end
@@ -31,7 +31,9 @@ module ConvenientService
31
31
  end
32
32
 
33
33
  middlewares :result do
34
- use Plugins::Service::HasResultParamsValidations::UsingDryValidation::Middleware
34
+ insert_before \
35
+ Plugins::Service::HasResultSteps::Middleware,
36
+ Plugins::Service::HasResultParamsValidations::UsingDryValidation::Middleware
35
37
  end
36
38
  end
37
39
  end
@@ -12,7 +12,7 @@ module ConvenientService
12
12
 
13
13
  contract do
14
14
  schema do
15
- required(:path).value(:string)
15
+ required(:path).filled(:string)
16
16
  end
17
17
  end
18
18
 
@@ -12,7 +12,7 @@ module ConvenientService
12
12
 
13
13
  contract do
14
14
  schema do
15
- required(:path).value(:string)
15
+ required(:path).filled(:string)
16
16
  end
17
17
  end
18
18
 
@@ -17,7 +17,7 @@ module ConvenientService
17
17
 
18
18
  contract do
19
19
  schema do
20
- required(:name).value(:string)
20
+ required(:name).filled(:string)
21
21
  end
22
22
  end
23
23
 
@@ -44,7 +44,7 @@ module ConvenientService
44
44
 
45
45
  contract do
46
46
  schema do
47
- required(:content).value(:string)
47
+ required(:content).filled(:string)
48
48
  end
49
49
  end
50
50
 
@@ -18,7 +18,7 @@ module ConvenientService
18
18
 
19
19
  contract do
20
20
  schema do
21
- required(:text).value(:string)
21
+ required(:text).filled(:string)
22
22
  end
23
23
  end
24
24
 
@@ -12,7 +12,7 @@ module ConvenientService
12
12
 
13
13
  contract do
14
14
  schema do
15
- required(:path).value(:string)
15
+ required(:path).filled(:string)
16
16
  end
17
17
  end
18
18
 
@@ -13,7 +13,7 @@ module ConvenientService
13
13
 
14
14
  contract do
15
15
  schema do
16
- required(:command).value(:string)
16
+ required(:command).filled(:string)
17
17
  optional(:debug).value(:bool)
18
18
  end
19
19
  end
@@ -17,7 +17,7 @@ module ConvenientService
17
17
 
18
18
  contract do
19
19
  schema do
20
- required(:content).value(:string)
20
+ required(:content).filled(:string)
21
21
  end
22
22
  end
23
23
 
@@ -42,7 +42,9 @@ module ConvenientService
42
42
  end
43
43
 
44
44
  middlewares :result do
45
- use Plugins::Service::HasResultParamsValidations::UsingActiveModelValidations::Middleware
45
+ insert_before \
46
+ Plugins::Service::HasResultSteps::Middleware,
47
+ Plugins::Service::HasResultParamsValidations::UsingActiveModelValidations::Middleware
46
48
  end
47
49
  end
48
50
  end
@@ -10,7 +10,7 @@ module ConvenientService
10
10
 
11
11
  attribute :path, :string
12
12
 
13
- validates :path, presence: true
13
+ validates :path, presence: true if ConvenientService::Dependencies.support_has_result_params_validations_using_active_model_validations?
14
14
 
15
15
  def result
16
16
  return error("File with path `#{path}` does NOT exist") unless ::File.exist?(path)
@@ -10,7 +10,7 @@ module ConvenientService
10
10
 
11
11
  attribute :path, :string
12
12
 
13
- validates :path, presence: true
13
+ validates :path, presence: true if ConvenientService::Dependencies.support_has_result_params_validations_using_active_model_validations?
14
14
 
15
15
  def result
16
16
  return error(message: "File with path `#{path}` is empty") if ::File.zero?(path)
@@ -15,7 +15,7 @@ module ConvenientService
15
15
 
16
16
  attribute :name, :string
17
17
 
18
- validates :name, presence: true
18
+ validates :name, presence: true if ConvenientService::Dependencies.support_has_result_params_validations_using_active_model_validations?
19
19
 
20
20
  step Services::AssertNodeAvailable
21
21
 
@@ -42,7 +42,7 @@ module ConvenientService
42
42
 
43
43
  attribute :content, :string
44
44
 
45
- validates :content, presence: true
45
+ validates :content, presence: true if ConvenientService::Dependencies.support_has_result_params_validations_using_active_model_validations?
46
46
 
47
47
  step Services::AssertValidRubySyntax, in: :content
48
48
  step :result, in: :content, out: :parsed_content
@@ -16,7 +16,7 @@ module ConvenientService
16
16
  attribute :text, :string
17
17
  attribute :out, default: $stdout
18
18
 
19
- validates :text, presence: true
19
+ validates :text, presence: true if ConvenientService::Dependencies.support_has_result_params_validations_using_active_model_validations?
20
20
 
21
21
  def result
22
22
  out.puts
@@ -10,7 +10,7 @@ module ConvenientService
10
10
 
11
11
  attribute :path, :string
12
12
 
13
- validates :path, presence: true
13
+ validates :path, presence: true if ConvenientService::Dependencies.support_has_result_params_validations_using_active_model_validations?
14
14
 
15
15
  step Services::AssertFileExists, in: :path
16
16
  step Services::AssertFileNotEmpty, in: :path
@@ -11,7 +11,7 @@ module ConvenientService
11
11
  attribute :command, :string
12
12
  attribute :debug, :boolean, default: false
13
13
 
14
- validates :command, presence: true
14
+ validates :command, presence: true if ConvenientService::Dependencies.support_has_result_params_validations_using_active_model_validations?
15
15
 
16
16
  def result
17
17
  Services::PrintShellCommand.result(text: command) if debug
@@ -15,7 +15,7 @@ module ConvenientService
15
15
 
16
16
  attribute :content, :string
17
17
 
18
- validates :content, presence: true
18
+ validates :content, presence: true if ConvenientService::Dependencies.support_has_result_params_validations_using_active_model_validations?
19
19
 
20
20
  alias_method :content_with_comments, :content
21
21
 
@@ -109,7 +109,21 @@ module ConvenientService
109
109
  service_class.__send__(status, **kwargs)
110
110
  end
111
111
 
112
- private
112
+ ##
113
+ # @param other [Object] Can be any type.
114
+ # @return [Boolean, nil]
115
+ #
116
+ def ==(other)
117
+ return unless other.instance_of?(self.class)
118
+
119
+ return false if status != other.status
120
+ return false if service_class != other.service_class
121
+ return false if chain != other.chain
122
+
123
+ true
124
+ end
125
+
126
+ protected
113
127
 
114
128
  ##
115
129
  # @!attribute [r] status
@@ -129,6 +143,8 @@ module ConvenientService
129
143
  #
130
144
  attr_reader :chain
131
145
 
146
+ private
147
+
132
148
  ##
133
149
  # @return [Hash]
134
150
  #
@@ -6,90 +6,84 @@ module ConvenientService
6
6
  module Custom
7
7
  class StubService < Support::Command
8
8
  module Entities
9
- ##
10
- # TODO: Specs.
11
- #
12
9
  class StubbedService < Support::Command
13
10
  ##
14
- # NOTE: `include ::RSpec::Matchers`.
15
- # - https://github.com/rspec/rspec-expectations/blob/v3.11.0/lib/rspec/matchers.rb
16
- # - https://github.com/rspec/rspec-expectations/blob/main/lib/rspec/matchers.rb
11
+ # @param service_class [Class]
12
+ # @return [void]
17
13
  #
18
- include ::RSpec::Matchers
14
+ def initialize(service_class:)
15
+ @service_class = service_class
16
+ @arguments = {args: [], kwargs: {}, block: nil}
17
+ end
19
18
 
20
19
  ##
21
- # NOTE: `include ::RSpec::Mocks::ExampleMethods`.
22
- # - https://github.com/rspec/rspec-mocks/blob/v3.11.1/lib/rspec/mocks/example_methods.rb
23
- # - https://github.com/rspec/rspec-mocks/blob/main/lib/rspec/mocks/example_methods.rb
20
+ # @param args [Array]
21
+ # @param kwargs [Hash]
22
+ # @param block [Block]
23
+ # @return [ConvenientService::RSpec::Helpers::Custom::StubService::Entities::StubService]
24
24
  #
25
- include ::RSpec::Mocks::ExampleMethods
25
+ def with_arguments(*args, **kwargs, &block)
26
+ @arguments = {args: args, kwargs: kwargs, block: block}
26
27
 
27
- def initialize(service_class:)
28
- @service_class = service_class
28
+ self
29
29
  end
30
30
 
31
- def with_arguments(*args, **kwargs, &block)
32
- chain[:with_arguments] = {args: args, kwargs: kwargs, block: block}
31
+ ##
32
+ # @return [ConvenientService::RSpec::Helpers::Custom::StubService::Entities::StubService]
33
+ #
34
+ def without_arguments
35
+ @arguments = {args: [], kwargs: {}, block: nil}
33
36
 
34
37
  self
35
38
  end
36
39
 
40
+ ##
41
+ # @param result_spec [ConvenientService::RSpec::Helpers::Custom::StubService::Entities::ResultSpec]
42
+ # @return [ConvenientService::RSpec::Helpers::Custom::StubService::Entities::StubService]
43
+ #
37
44
  def to(result_spec)
38
45
  @result_spec = result_spec
39
46
 
40
47
  service_class.commit_config!
41
48
 
42
- if used_with_arguments?
43
- allow(service_class).to receive(:result).and_wrap_original do |original, *actual_args, **actual_kwargs, &actual_block|
44
- expect(actual_args).to eq(expected_args)
45
- expect(actual_kwargs).to eq(expected_kwargs)
46
- expect(actual_block).to eq(expected_block)
49
+ service_class.stubbed_results[key] = result_value
47
50
 
48
- result_value
49
- end
50
- else
51
- allow(service_class).to receive(:result).and_return(result_value)
52
- end
51
+ self
53
52
  end
54
53
 
55
54
  private
56
55
 
57
- attr_reader :service_class, :result_spec
58
-
59
- def result_value
60
- @result_value ||= result_spec.for(service_class).calculate_value
61
- end
62
-
63
- def used_with_arguments?
64
- chain.key?(:with_arguments)
65
- end
66
-
67
- def chain
68
- @chain ||= {}
69
- end
56
+ ##
57
+ # @!attribute [r] service_class
58
+ # @return [Class]
59
+ #
60
+ attr_reader :service_class
70
61
 
71
- def args
72
- @args ||= chain.dig(:with_arguments, :args) || []
73
- end
62
+ ##
63
+ # @!attribute [r] arguments
64
+ # @return [Hash]
65
+ #
66
+ attr_reader :arguments
74
67
 
75
- alias_method :expected_args, :args
68
+ ##
69
+ # @!attribute [r] result_spec
70
+ # @return [ConvenientService::RSpec::Helpers::Custom::StubService::Entities::ResultSpec]
71
+ #
72
+ attr_reader :result_spec
76
73
 
77
- def kwargs
78
- @kwargs ||= chain.dig(:with_arguments, :kwargs) || {}
74
+ ##
75
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
76
+ #
77
+ def result_value
78
+ @result_value ||= result_spec.for(service_class).calculate_value
79
79
  end
80
80
 
81
- alias_method :expected_kwargs, :kwargs
82
-
83
81
  ##
84
- # NOTE: `if defined?` is used in order to cache `nil` if needed.
82
+ # @return [ConvenientService::Support::Cache::Key]
85
83
  #
86
- def block
87
- return @block if defined? @block
88
-
89
- @block = chain.dig(:with_arguments, :block)
84
+ def key
85
+ @key ||= service_class.stubbed_results.keygen(*arguments[:args], **arguments[:kwargs], &arguments[:block])
90
86
  end
91
-
92
- alias_method :expected_block, :block
93
87
  end
94
88
  end
95
89
  end
@@ -23,26 +23,26 @@ module ConvenientService
23
23
  end
24
24
 
25
25
  def failure_message
26
- "expected #{printable_block} to cache its value"
26
+ "expected #{printable_block_expectation} to cache its value"
27
27
  end
28
28
 
29
29
  def failure_message_when_negated
30
- "expected #{printable_block} NOT to cache its value"
30
+ "expected #{printable_block_expectation} NOT to cache its value"
31
31
  end
32
32
 
33
33
  ##
34
34
  # NOTE: An example of how RSpec extracts block source, but they marked it as private.
35
35
  # https://github.com/rspec/rspec-expectations/blob/311aaf245f2c5493572bf683b8c441cb5f7e44c8/lib/rspec/matchers/built_in/change.rb#L437
36
36
  #
37
- # TODO: `printable_block` when `method_source` is available.
37
+ # TODO: `printable_block_expectation` when `method_source` is available.
38
38
  # https://github.com/banister/method_source
39
39
  #
40
- # def printable_block
41
- # @printable_block ||= block_expectation.source
40
+ # def printable_block_expectation
41
+ # @printable_block_expectation ||= block_expectation.source
42
42
  # end
43
43
  #
44
- def printable_block
45
- @printable_block ||= "{ ... }"
44
+ def printable_block_expectation
45
+ @printable_block_expectation ||= "{ ... }"
46
46
  end
47
47
 
48
48
  private