convenient_service 0.20.0 → 0.21.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.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/lib/convenient_service/aliases.rb +113 -1
- data/lib/convenient_service/common/plugins/aliases.rb +69 -0
- data/lib/convenient_service/common/plugins/can_have_callbacks/entities/type_collection.rb +2 -2
- data/lib/convenient_service/common/plugins/has_instance_proxy/entities/instance_proxy.rb +8 -8
- data/lib/convenient_service/common.rb +14 -0
- data/lib/convenient_service/config.rb +8 -0
- data/lib/convenient_service/core/aliases.rb +84 -0
- data/lib/convenient_service/dependencies/built_in.rb +15 -1
- data/lib/convenient_service/dependencies/only_queries.rb +0 -6
- data/lib/convenient_service/dependencies/queries/gems/minitest.rb +55 -0
- data/lib/convenient_service/dependencies/queries/gems/rspec.rb +1 -1
- data/lib/convenient_service/dependencies/queries/gems.rb +2 -0
- data/lib/convenient_service/dependencies/queries/ruby.rb +2 -2
- data/lib/convenient_service/dependencies/queries.rb +67 -16
- data/lib/convenient_service/dependencies.rb +6 -6
- data/lib/convenient_service/extras/alias.rb +4 -1
- data/lib/convenient_service/feature/configs/standard.rb +34 -13
- data/lib/convenient_service/feature/core.rb +41 -0
- data/lib/convenient_service/feature/plugins/aliases.rb +29 -0
- data/lib/convenient_service/feature/plugins/can_have_rspec_stubbed_entries/concern.rb +34 -0
- data/lib/convenient_service/{rspec/helpers/classes/stub_entry/entities.rb → feature/plugins/can_have_rspec_stubbed_entries.rb} +1 -2
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands/delete_feature_stubbed_entry.rb +71 -0
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands/fetch_all_features_stubbed_entries_cache.rb +16 -2
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands/fetch_feature_stubbed_entries_cache.rb +1 -1
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands.rb +2 -0
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/concern.rb +23 -0
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/feature_stub.rb +123 -0
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/feature_unstub.rb +122 -0
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/value_mock.rb +118 -0
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/value_unmock.rb +88 -0
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities.rb +12 -0
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries.rb +1 -14
- data/lib/convenient_service/feature/plugins/has_amazing_print_inspect/concern.rb +34 -0
- data/lib/convenient_service/feature/{configs/standard/commands.rb → plugins/has_amazing_print_inspect.rb} +1 -2
- data/lib/convenient_service/feature/plugins/has_awesome_print_inspect/concern.rb +34 -0
- data/lib/convenient_service/{rspec/helpers/classes/stub_service/entities.rb → feature/plugins/has_awesome_print_inspect.rb} +1 -2
- data/lib/convenient_service/feature/plugins/has_inspect/concern.rb +27 -0
- data/lib/convenient_service/{service/configs/standard/commands.rb → feature/plugins/has_inspect.rb} +1 -2
- data/lib/convenient_service/feature/plugins.rb +1 -0
- data/lib/convenient_service/feature.rb +16 -0
- data/lib/convenient_service/logger.rb +11 -12
- data/lib/convenient_service/rspec/helpers/classes.rb +0 -2
- data/lib/convenient_service/rspec/helpers/stub_entry.rb +23 -5
- data/lib/convenient_service/rspec/helpers/stub_service.rb +79 -11
- data/lib/convenient_service/rspec/matchers/classes/cache_its_value.rb +2 -1
- data/lib/convenient_service/rspec/matchers/classes/delegate_to.rb +3 -5
- data/lib/convenient_service/rspec/matchers/classes/include_config.rb +4 -0
- data/lib/convenient_service/service/configs/aliases.rb +42 -0
- data/lib/convenient_service/service/configs/standard/aliases.rb +24 -0
- data/lib/convenient_service/service/configs/standard/v1.rb +17 -0
- data/lib/convenient_service/service/configs/standard.rb +50 -25
- data/lib/convenient_service/service/core.rb +39 -0
- data/lib/convenient_service/service/plugins/aliases.rb +48 -0
- data/lib/convenient_service/service/plugins/can_have_rollbacks/middleware.rb +33 -2
- data/lib/convenient_service/service/plugins/can_have_rspec_stubbed_results/concern.rb +34 -0
- data/lib/convenient_service/service/plugins/can_have_rspec_stubbed_results.rb +8 -0
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/delete_service_stubbed_result.rb +63 -0
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/fetch_all_services_stubbed_results_cache.rb +15 -10
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/fetch_service_stubbed_results_cache.rb +3 -3
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands.rb +2 -0
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/concern.rb +25 -0
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/result_mock.rb +254 -0
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/result_unmock.rb +82 -0
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/service_stub.rb +135 -0
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/service_unstub.rb +113 -0
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities.rb +12 -0
- data/lib/convenient_service/service/plugins/can_have_stubbed_results.rb +1 -14
- data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/exceptions.rb +84 -0
- data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/middleware.rb +84 -32
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/concern.rb +42 -2
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_called/exceptions.rb +3 -2
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern/instance_methods.rb +5 -0
- data/lib/convenient_service/service.rb +16 -0
- data/lib/convenient_service/specification.rb +42 -12
- data/lib/convenient_service/support/backtrace_cleaner.rb +6 -7
- data/lib/convenient_service/support/middleware/stack_builder/entities/builders/custom.rb +4 -0
- data/lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb +4 -0
- data/lib/convenient_service/support/unique_value.rb +4 -1
- data/lib/convenient_service/support.rb +13 -0
- data/lib/convenient_service/utils/array/find_last.rb +18 -9
- data/lib/convenient_service/utils/class/display_name.rb +9 -9
- data/lib/convenient_service/utils/enumerable/find_last.rb +48 -0
- data/lib/convenient_service/utils/enumerable.rb +20 -0
- data/lib/convenient_service/utils/hash/assert_valid_keys.rb +4 -4
- data/lib/convenient_service/utils/hash/except.rb +5 -4
- data/lib/convenient_service/utils/hash/triple_equality_compare.rb +8 -8
- data/lib/convenient_service/utils/kernel/silence_warnings.rb +4 -4
- data/lib/convenient_service/utils/module/fetch_own_const.rb +36 -31
- data/lib/convenient_service/utils/module/get_namespace.rb +26 -21
- data/lib/convenient_service/utils/module/get_own_const.rb +21 -16
- data/lib/convenient_service/utils/object/clamp_class.rb +50 -47
- data/lib/convenient_service/utils/object/duck_class.rb +84 -81
- data/lib/convenient_service/utils/object/get_own_method.rb +1 -1
- data/lib/convenient_service/utils/object/instance_variable_delete.rb +0 -3
- data/lib/convenient_service/utils/object/instance_variable_fetch.rb +0 -3
- data/lib/convenient_service/utils/object/memoize_including_falsy_values.rb +0 -3
- data/lib/convenient_service/utils/object/resolve_type.rb +13 -11
- data/lib/convenient_service/utils/object/safe_send.rb +2 -0
- data/lib/convenient_service/utils/string/enclose.rb +11 -11
- data/lib/convenient_service/utils/string/tab.rb +60 -0
- data/lib/convenient_service/utils/string.rb +5 -0
- data/lib/convenient_service/utils.rb +9 -0
- data/lib/convenient_service/version.rb +8 -1
- data/lib/convenient_service.rb +232 -14
- metadata +37 -754
- data/lib/convenient_service/feature/configs/standard/commands/is_feature.rb +0 -39
- data/lib/convenient_service/feature/configs/standard/commands/is_feature_class.rb +0 -41
- data/lib/convenient_service/rspec/helpers/classes/stub_entry/constants.rb +0 -25
- data/lib/convenient_service/rspec/helpers/classes/stub_entry/entities/stubbed_feature.rb +0 -128
- data/lib/convenient_service/rspec/helpers/classes/stub_entry/entities/value_spec.rb +0 -79
- data/lib/convenient_service/rspec/helpers/classes/stub_entry.rb +0 -48
- data/lib/convenient_service/rspec/helpers/classes/stub_service/constants.rb +0 -25
- data/lib/convenient_service/rspec/helpers/classes/stub_service/entities/result_spec.rb +0 -211
- data/lib/convenient_service/rspec/helpers/classes/stub_service/entities/stubbed_service.rb +0 -119
- data/lib/convenient_service/rspec/helpers/classes/stub_service.rb +0 -43
- data/lib/convenient_service/service/configs/standard/commands/is_service.rb +0 -39
- data/lib/convenient_service/service/configs/standard/commands/is_service_class.rb +0 -41
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @author Marian Kostyk <mariankostyk13895@gmail.com>
|
|
5
|
+
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
module ConvenientService
|
|
9
|
+
module Service
|
|
10
|
+
module Plugins
|
|
11
|
+
module CanHaveStubbedResults
|
|
12
|
+
module Commands
|
|
13
|
+
class DeleteServiceStubbedResult < Support::Command
|
|
14
|
+
##
|
|
15
|
+
# @!attribute [r] service
|
|
16
|
+
# @return [ConvenientService::Service]
|
|
17
|
+
#
|
|
18
|
+
attr_reader :service
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# @!attribute [r] arguments
|
|
22
|
+
# @return [ConvenientService::Support::Arguments]
|
|
23
|
+
#
|
|
24
|
+
attr_reader :arguments
|
|
25
|
+
|
|
26
|
+
##
|
|
27
|
+
# @param service [ConvenientService::Service]
|
|
28
|
+
# @param arguments [ConvenientService::Support::Arguments]
|
|
29
|
+
# @return [void]
|
|
30
|
+
#
|
|
31
|
+
def initialize(service:, arguments:)
|
|
32
|
+
@service = service
|
|
33
|
+
@arguments = arguments
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
##
|
|
37
|
+
# @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
|
|
38
|
+
#
|
|
39
|
+
# @internal
|
|
40
|
+
# NOTE: `arguments.nil?` means "match any arguments".
|
|
41
|
+
#
|
|
42
|
+
def call
|
|
43
|
+
if arguments.nil?
|
|
44
|
+
cache.default = nil
|
|
45
|
+
else
|
|
46
|
+
cache.delete(cache.keygen(*arguments.args, **arguments.kwargs, &arguments.block))
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
##
|
|
53
|
+
# @return [ConvenientService::Support::Cache]
|
|
54
|
+
#
|
|
55
|
+
def cache
|
|
56
|
+
@cache ||= Commands::FetchServiceStubbedResultsCache.call(service: service)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -12,20 +12,25 @@ module ConvenientService
|
|
|
12
12
|
module Commands
|
|
13
13
|
class FetchAllServicesStubbedResultsCache < Support::Command
|
|
14
14
|
##
|
|
15
|
-
#
|
|
15
|
+
# @!attribute [r] service
|
|
16
|
+
# @return [Class<ConvenientService::Service>]
|
|
16
17
|
#
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
# - https://relishapp.com/rspec/rspec-core/docs/metadata/current-example
|
|
18
|
+
attr_reader :service
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# @param service [Class<ConvenientService::Service>]
|
|
22
|
+
# @return [void]
|
|
23
23
|
#
|
|
24
|
-
|
|
24
|
+
def initialize(service:)
|
|
25
|
+
@service = service
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# @return [ConvenientService::Support::Cache]
|
|
25
30
|
#
|
|
26
31
|
def call
|
|
27
|
-
if
|
|
28
|
-
Utils::Object.memoize_including_falsy_values(
|
|
32
|
+
if service.stubbed_results_store
|
|
33
|
+
Utils::Object.memoize_including_falsy_values(service.stubbed_results_store, :@__convenient_service_stubbed_results__) { Support::Cache.backed_by(:thread_safe_hash).new }
|
|
29
34
|
else
|
|
30
35
|
Support::Cache.backed_by(:thread_safe_hash).new
|
|
31
36
|
end
|
|
@@ -13,12 +13,12 @@ module ConvenientService
|
|
|
13
13
|
class FetchServiceStubbedResultsCache < Support::Command
|
|
14
14
|
##
|
|
15
15
|
# @!attribute [r] service
|
|
16
|
-
# @return [ConvenientService::Service]
|
|
16
|
+
# @return [Class<ConvenientService::Service>]
|
|
17
17
|
#
|
|
18
18
|
attr_reader :service
|
|
19
19
|
|
|
20
20
|
##
|
|
21
|
-
# @param service [ConvenientService::Service]
|
|
21
|
+
# @param service [Class<ConvenientService::Service>]
|
|
22
22
|
# @return [void]
|
|
23
23
|
#
|
|
24
24
|
def initialize(service:)
|
|
@@ -38,7 +38,7 @@ module ConvenientService
|
|
|
38
38
|
# @return [ConvenientService::Support::Cache]
|
|
39
39
|
#
|
|
40
40
|
def cache
|
|
41
|
-
@cache ||= Commands::FetchAllServicesStubbedResultsCache.call
|
|
41
|
+
@cache ||= Commands::FetchAllServicesStubbedResultsCache.call(service: service)
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
end
|
|
@@ -26,6 +26,17 @@ module ConvenientService
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
class_methods do
|
|
29
|
+
##
|
|
30
|
+
# @return [Thread]
|
|
31
|
+
#
|
|
32
|
+
# @internal
|
|
33
|
+
# NOTE: Why not `Fiber.current`? Fibers created in one thread are concurrently executed in that one thread.
|
|
34
|
+
# NOTE: Why not `Ractor.current`? Each ractor has its own thread.
|
|
35
|
+
#
|
|
36
|
+
def stubbed_results_store
|
|
37
|
+
::Thread.current
|
|
38
|
+
end
|
|
39
|
+
|
|
29
40
|
##
|
|
30
41
|
# @return [ConvenientService::Support::Cache]
|
|
31
42
|
#
|
|
@@ -43,6 +54,20 @@ module ConvenientService
|
|
|
43
54
|
def stubbed_results
|
|
44
55
|
Commands::FetchServiceStubbedResultsCache.call(service: self)
|
|
45
56
|
end
|
|
57
|
+
|
|
58
|
+
##
|
|
59
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ServiceStub]
|
|
60
|
+
#
|
|
61
|
+
def stub_result
|
|
62
|
+
Entities::ServiceStub.new(service_class: self)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
##
|
|
66
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ServiceUnstub]
|
|
67
|
+
#
|
|
68
|
+
def unstub_result
|
|
69
|
+
Entities::ServiceUnstub.new(service_class: self)
|
|
70
|
+
end
|
|
46
71
|
end
|
|
47
72
|
end
|
|
48
73
|
end
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @author Marian Kostyk <mariankostyk13895@gmail.com>
|
|
5
|
+
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
module ConvenientService
|
|
9
|
+
module Service
|
|
10
|
+
module Plugins
|
|
11
|
+
module CanHaveStubbedResults
|
|
12
|
+
module Entities
|
|
13
|
+
##
|
|
14
|
+
# @internal
|
|
15
|
+
# IMPORTANT: Do NOT cache `data`, `message`, and `code` since they can be set multiple times by `with_data`, `and_data`, `with_message`, `and_message`, `with_code`, and `and_code`.
|
|
16
|
+
#
|
|
17
|
+
class ResultMock
|
|
18
|
+
##
|
|
19
|
+
# @param status [Symbol]
|
|
20
|
+
# @param service_class [Class<ConvenientService::Service>]
|
|
21
|
+
# @param arguments [ConvenientService::Support::Arguments]
|
|
22
|
+
# @param chain [Hash]
|
|
23
|
+
# @return [void]
|
|
24
|
+
#
|
|
25
|
+
def initialize(status:, service_class: nil, arguments: nil, chain: {})
|
|
26
|
+
@status = status
|
|
27
|
+
@service_class = service_class
|
|
28
|
+
@arguments = arguments
|
|
29
|
+
@chain = chain
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
##
|
|
33
|
+
# @param service_class [Class<ConvenientService::Service>]
|
|
34
|
+
# @param arguments [ConvenientService::Support::Arguments]
|
|
35
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
36
|
+
#
|
|
37
|
+
def for(service_class, arguments)
|
|
38
|
+
self.class.new(status: status, service_class: service_class, arguments: arguments, chain: chain)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
##
|
|
42
|
+
# @param data [Hash]
|
|
43
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
44
|
+
#
|
|
45
|
+
def with_data(data)
|
|
46
|
+
chain[:data] = data
|
|
47
|
+
|
|
48
|
+
self
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
##
|
|
52
|
+
# @param message [String]
|
|
53
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
54
|
+
#
|
|
55
|
+
def with_message(message)
|
|
56
|
+
chain[:message] = message
|
|
57
|
+
|
|
58
|
+
self
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
##
|
|
62
|
+
# @param code [String]
|
|
63
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
64
|
+
#
|
|
65
|
+
def with_code(code)
|
|
66
|
+
chain[:code] = code
|
|
67
|
+
|
|
68
|
+
self
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
##
|
|
72
|
+
# @param data [Hash]
|
|
73
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
74
|
+
#
|
|
75
|
+
def and_data(data)
|
|
76
|
+
chain[:data] = data
|
|
77
|
+
|
|
78
|
+
self
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
##
|
|
82
|
+
# @param message [String]
|
|
83
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
84
|
+
#
|
|
85
|
+
def and_message(message)
|
|
86
|
+
chain[:message] = message
|
|
87
|
+
|
|
88
|
+
self
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
##
|
|
92
|
+
# @param code [String]
|
|
93
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
94
|
+
#
|
|
95
|
+
def and_code(code)
|
|
96
|
+
chain[:code] = code
|
|
97
|
+
|
|
98
|
+
self
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
##
|
|
102
|
+
# @param block [Proc, nil]
|
|
103
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
104
|
+
#
|
|
105
|
+
def register(&block)
|
|
106
|
+
Commands::SetServiceStubbedResult[service: service_class, arguments: arguments, result: result]
|
|
107
|
+
|
|
108
|
+
return self unless block
|
|
109
|
+
|
|
110
|
+
begin
|
|
111
|
+
yield
|
|
112
|
+
ensure
|
|
113
|
+
Commands::DeleteServiceStubbedResult[service: service_class, arguments: arguments]
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
##
|
|
118
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
119
|
+
#
|
|
120
|
+
alias_method :apply, :register
|
|
121
|
+
|
|
122
|
+
##
|
|
123
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
124
|
+
#
|
|
125
|
+
def unregister
|
|
126
|
+
Commands::DeleteServiceStubbedResult[service: service_class, arguments: arguments]
|
|
127
|
+
|
|
128
|
+
self
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
##
|
|
132
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
133
|
+
#
|
|
134
|
+
alias_method :revert, :unregister
|
|
135
|
+
|
|
136
|
+
##
|
|
137
|
+
# @return [ConvenientService::Service]
|
|
138
|
+
#
|
|
139
|
+
def result
|
|
140
|
+
service_class.__send__(status, **kwargs).copy(overrides: {kwargs: {stubbed_result: true}})
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
##
|
|
144
|
+
# @param other [Object] Can be any type.
|
|
145
|
+
# @return [Boolean, nil]
|
|
146
|
+
#
|
|
147
|
+
def ==(other)
|
|
148
|
+
return unless other.instance_of?(self.class)
|
|
149
|
+
|
|
150
|
+
return false if status != other.status
|
|
151
|
+
return false if service_class != other.service_class
|
|
152
|
+
return false if arguments != other.arguments
|
|
153
|
+
return false if chain != other.chain
|
|
154
|
+
|
|
155
|
+
true
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
protected
|
|
159
|
+
|
|
160
|
+
##
|
|
161
|
+
# @!attribute [r] status
|
|
162
|
+
# @return [Symbol]
|
|
163
|
+
#
|
|
164
|
+
attr_reader :status
|
|
165
|
+
|
|
166
|
+
##
|
|
167
|
+
# @!attribute [r] service_class
|
|
168
|
+
# @return [Class<ConvenientService::Service>]
|
|
169
|
+
#
|
|
170
|
+
attr_reader :service_class
|
|
171
|
+
|
|
172
|
+
##
|
|
173
|
+
# @!attribute [r] arguments
|
|
174
|
+
# @return [ConvenientService::Support::Arguments]
|
|
175
|
+
#
|
|
176
|
+
attr_reader :arguments
|
|
177
|
+
|
|
178
|
+
##
|
|
179
|
+
# @!attribute [r] chain
|
|
180
|
+
# @return [Hash]
|
|
181
|
+
#
|
|
182
|
+
attr_reader :chain
|
|
183
|
+
|
|
184
|
+
private
|
|
185
|
+
|
|
186
|
+
##
|
|
187
|
+
# @return [Hash]
|
|
188
|
+
#
|
|
189
|
+
def kwargs
|
|
190
|
+
kwargs = {}
|
|
191
|
+
|
|
192
|
+
kwargs[:data] = data if used_data?
|
|
193
|
+
kwargs[:message] = message if used_message?
|
|
194
|
+
kwargs[:code] = code if used_code?
|
|
195
|
+
|
|
196
|
+
kwargs[:service] = service_instance
|
|
197
|
+
|
|
198
|
+
kwargs
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
##
|
|
202
|
+
# @return [Boolean]
|
|
203
|
+
#
|
|
204
|
+
def used_data?
|
|
205
|
+
chain.key?(:data)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
##
|
|
209
|
+
# @return [Boolean]
|
|
210
|
+
#
|
|
211
|
+
def used_message?
|
|
212
|
+
chain.key?(:message)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
##
|
|
216
|
+
# @return [Boolean]
|
|
217
|
+
#
|
|
218
|
+
def used_code?
|
|
219
|
+
chain.key?(:code)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
##
|
|
223
|
+
# @return [Hash]
|
|
224
|
+
#
|
|
225
|
+
def data
|
|
226
|
+
chain[:data] || {}
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
##
|
|
230
|
+
# @return [String]
|
|
231
|
+
#
|
|
232
|
+
def message
|
|
233
|
+
chain[:message] || ""
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
##
|
|
237
|
+
# @return [String]
|
|
238
|
+
#
|
|
239
|
+
def code
|
|
240
|
+
chain[:code] || ""
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
##
|
|
244
|
+
# @return [ConvenientService::Service]
|
|
245
|
+
#
|
|
246
|
+
def service_instance
|
|
247
|
+
service_class.new_without_initialize
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
end
|
data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/result_unmock.rb
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @author Marian Kostyk <mariankostyk13895@gmail.com>
|
|
5
|
+
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
module ConvenientService
|
|
9
|
+
module Service
|
|
10
|
+
module Plugins
|
|
11
|
+
module CanHaveStubbedResults
|
|
12
|
+
module Entities
|
|
13
|
+
##
|
|
14
|
+
# @internal
|
|
15
|
+
# IMPORTANT: Do NOT cache `data`, `message`, and `code` since they can be set multiple times by `with_data`, `and_data`, `with_message`, `and_message`, `with_code`, and `and_code`.
|
|
16
|
+
#
|
|
17
|
+
class ResultUnmock
|
|
18
|
+
##
|
|
19
|
+
# @param service_class [Class<ConvenientService::Service>]
|
|
20
|
+
# @param arguments [ConvenientService::Support::Arguments]
|
|
21
|
+
# @return [void]
|
|
22
|
+
#
|
|
23
|
+
def initialize(service_class: nil, arguments: nil)
|
|
24
|
+
@service_class = service_class
|
|
25
|
+
@arguments = arguments
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# @param service_class [Class<ConvenientService::Service>]
|
|
30
|
+
# @param arguments [ConvenientService::Support::Arguments]
|
|
31
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultUnmock]
|
|
32
|
+
#
|
|
33
|
+
def for(service_class, arguments)
|
|
34
|
+
self.class.new(service_class: service_class, arguments: arguments)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
##
|
|
38
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultUnmock]
|
|
39
|
+
#
|
|
40
|
+
def register
|
|
41
|
+
Commands::DeleteServiceStubbedResult[service: service_class, arguments: arguments]
|
|
42
|
+
|
|
43
|
+
self
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
##
|
|
47
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultUnmock]
|
|
48
|
+
#
|
|
49
|
+
alias_method :apply, :register
|
|
50
|
+
|
|
51
|
+
##
|
|
52
|
+
# @param other [Object] Can be any type.
|
|
53
|
+
# @return [Boolean, nil]
|
|
54
|
+
#
|
|
55
|
+
def ==(other)
|
|
56
|
+
return unless other.instance_of?(self.class)
|
|
57
|
+
|
|
58
|
+
return false if service_class != other.service_class
|
|
59
|
+
return false if arguments != other.arguments
|
|
60
|
+
|
|
61
|
+
true
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
protected
|
|
65
|
+
|
|
66
|
+
##
|
|
67
|
+
# @!attribute [r] service_class
|
|
68
|
+
# @return [Class<ConvenientService::Service>]
|
|
69
|
+
#
|
|
70
|
+
attr_reader :service_class
|
|
71
|
+
|
|
72
|
+
##
|
|
73
|
+
# @!attribute [r] arguments
|
|
74
|
+
# @return [ConvenientService::Support::Arguments]
|
|
75
|
+
#
|
|
76
|
+
attr_reader :arguments
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @author Marian Kostyk <mariankostyk13895@gmail.com>
|
|
5
|
+
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
module ConvenientService
|
|
9
|
+
module Service
|
|
10
|
+
module Plugins
|
|
11
|
+
module CanHaveStubbedResults
|
|
12
|
+
module Entities
|
|
13
|
+
class ServiceStub
|
|
14
|
+
##
|
|
15
|
+
# @param service_class [Class<ConvenientService::Service>]
|
|
16
|
+
# @return [void]
|
|
17
|
+
#
|
|
18
|
+
# @internal
|
|
19
|
+
# NOTE: `@arguments = nil` means "match any arguments".
|
|
20
|
+
#
|
|
21
|
+
def initialize(service_class:)
|
|
22
|
+
@service_class = service_class
|
|
23
|
+
@arguments = nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
##
|
|
27
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ServiceStub]
|
|
28
|
+
#
|
|
29
|
+
# @internal
|
|
30
|
+
# NOTE: `@arguments = nil` means "match any arguments".
|
|
31
|
+
#
|
|
32
|
+
def with_any_arguments(...)
|
|
33
|
+
@arguments = nil
|
|
34
|
+
|
|
35
|
+
self
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ServiceStub]
|
|
40
|
+
#
|
|
41
|
+
def with_arguments(...)
|
|
42
|
+
@arguments = Support::Arguments.new(...)
|
|
43
|
+
|
|
44
|
+
self
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
##
|
|
48
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ServiceStub]
|
|
49
|
+
#
|
|
50
|
+
def without_arguments
|
|
51
|
+
@arguments = Support::Arguments.null_arguments
|
|
52
|
+
|
|
53
|
+
self
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
##
|
|
57
|
+
# @param result_mock [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
58
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ServiceStub]
|
|
59
|
+
#
|
|
60
|
+
def to(result_mock)
|
|
61
|
+
@result_mock = result_mock.for(service_class, arguments)
|
|
62
|
+
|
|
63
|
+
@result_mock.register
|
|
64
|
+
|
|
65
|
+
self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
##
|
|
69
|
+
# @param status [Symbol]
|
|
70
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
71
|
+
#
|
|
72
|
+
def to_return_result(status)
|
|
73
|
+
@result_mock = Entities::ResultMock.new(status: status, service_class: service_class, arguments: arguments)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
##
|
|
77
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
78
|
+
#
|
|
79
|
+
def to_return_success
|
|
80
|
+
@result_mock = Entities::ResultMock.new(status: :success, service_class: service_class, arguments: arguments)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
##
|
|
84
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
85
|
+
#
|
|
86
|
+
def to_return_failure
|
|
87
|
+
@result_mock = Entities::ResultMock.new(status: :failure, service_class: service_class, arguments: arguments)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
##
|
|
91
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
92
|
+
#
|
|
93
|
+
def to_return_error
|
|
94
|
+
@result_mock = Entities::ResultMock.new(status: :error, service_class: service_class, arguments: arguments)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
##
|
|
98
|
+
# @param other [Object] Can be any type.
|
|
99
|
+
# @return [Boolean, nil]
|
|
100
|
+
#
|
|
101
|
+
def ==(other)
|
|
102
|
+
return unless other.instance_of?(self.class)
|
|
103
|
+
|
|
104
|
+
return false if service_class != other.service_class
|
|
105
|
+
return false if arguments != other.arguments
|
|
106
|
+
return false if result_mock != other.result_mock
|
|
107
|
+
|
|
108
|
+
true
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
protected
|
|
112
|
+
|
|
113
|
+
##
|
|
114
|
+
# @!attribute [r] service_class
|
|
115
|
+
# @return [Class<ConvenientService::Service>]
|
|
116
|
+
#
|
|
117
|
+
attr_reader :service_class
|
|
118
|
+
|
|
119
|
+
##
|
|
120
|
+
# @!attribute [r] arguments
|
|
121
|
+
# @return [ConvenientService::Support::Arguments]
|
|
122
|
+
#
|
|
123
|
+
attr_reader :arguments
|
|
124
|
+
|
|
125
|
+
##
|
|
126
|
+
# @!attribute [r] result_mock
|
|
127
|
+
# @return [ConvenientService::Service::Plugins::CanHaveStubbedResults::Entities::ResultMock]
|
|
128
|
+
#
|
|
129
|
+
attr_reader :result_mock
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|