convenient_service 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/ROADMAP.md +26 -4
- data/Taskfile.yml +30 -0
- data/convenient_service.gemspec +5 -2
- data/lib/convenient_service/aliases.rb +2 -0
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/concern.rb +0 -2
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_dry_initializer/concern.rb +0 -2
- data/lib/convenient_service/common/plugins/has_around_callbacks/middleware.rb +24 -4
- data/lib/convenient_service/common/plugins/has_callbacks/container.rb +17 -0
- data/lib/convenient_service/common/plugins/has_callbacks/entities/callback.rb +98 -5
- data/lib/convenient_service/common/plugins/has_callbacks/middleware.rb +25 -4
- data/lib/convenient_service/common/plugins/has_callbacks.rb +1 -0
- data/lib/convenient_service/common/plugins.rb +1 -1
- data/lib/convenient_service/configs/standard.rb +25 -12
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/resolve_methods_middlewares_callers.rb +1 -24
- data/lib/convenient_service/dependencies.rb +19 -0
- data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +4 -2
- data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +4 -2
- data/lib/convenient_service/examples/rails/gemfile/services/format.rb +35 -6
- data/lib/convenient_service/examples/rails/gemfile/services/format_header.rb +1 -2
- data/lib/convenient_service/examples/rails/gemfile/services/merge_sections.rb +25 -0
- data/lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb +37 -0
- data/lib/convenient_service/examples/rails/gemfile/services.rb +8 -4
- data/lib/convenient_service/examples/standard/gemfile/services/format.rb +45 -6
- data/lib/convenient_service/examples/standard/gemfile/services/merge_sections.rb +52 -0
- data/lib/convenient_service/examples/standard/gemfile/services/replace_file_content.rb +48 -0
- data/lib/convenient_service/examples/standard/gemfile/services.rb +8 -4
- data/lib/convenient_service/examples/standard/request_params/constants.rb +15 -0
- data/lib/convenient_service/examples/standard/request_params/entities/description.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/entities/format.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/entities/id.rb +47 -0
- data/lib/convenient_service/examples/standard/request_params/entities/logger.rb +21 -0
- data/lib/convenient_service/examples/standard/request_params/entities/request.rb +23 -0
- data/lib/convenient_service/examples/standard/request_params/entities/source.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/entities/tag.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/entities/title.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/entities.rb +11 -0
- data/lib/convenient_service/examples/standard/request_params/services/apply_default_param_values.rb +26 -0
- data/lib/convenient_service/examples/standard/request_params/services/cast_params.rb +38 -0
- data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_body.rb +70 -0
- data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_path.rb +62 -0
- data/lib/convenient_service/examples/standard/request_params/services/filter_out_unpermitted_params.rb +26 -0
- data/lib/convenient_service/examples/standard/request_params/services/log_request_params.rb +54 -0
- data/lib/convenient_service/examples/standard/request_params/services/merge_params.rb +26 -0
- data/lib/convenient_service/examples/standard/request_params/services/prepare.rb +65 -0
- data/lib/convenient_service/examples/standard/request_params/services/validate_casted_params.rb +94 -0
- data/lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb +72 -0
- data/lib/convenient_service/examples/standard/request_params/services.rb +13 -0
- data/lib/convenient_service/examples/standard/request_params/utils/array/wrap.rb +46 -0
- data/lib/convenient_service/examples/standard/request_params/utils/array.rb +21 -0
- data/lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb +42 -0
- data/lib/convenient_service/examples/standard/request_params/utils/http/request/parse_path.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/utils/http/request.rb +28 -0
- data/lib/convenient_service/examples/standard/request_params/utils/http.rb +3 -0
- data/lib/convenient_service/examples/standard/request_params/utils/integer/safe_parse.rb +31 -0
- data/lib/convenient_service/examples/standard/request_params/utils/integer.rb +25 -0
- data/lib/convenient_service/examples/standard/request_params/utils/json/safe_parse.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/utils/json.rb +21 -0
- data/lib/convenient_service/examples/standard/request_params/utils/object/blank.rb +34 -0
- data/lib/convenient_service/examples/standard/request_params/utils/object/present.rb +31 -0
- data/lib/convenient_service/examples/standard/request_params/utils/object.rb +26 -0
- data/lib/convenient_service/examples/standard/request_params/utils.rb +7 -0
- data/lib/convenient_service/examples/standard/request_params.rb +48 -0
- data/lib/convenient_service/factories/arguments.rb +43 -0
- data/lib/convenient_service/factories/results.rb +214 -0
- data/lib/convenient_service/factories/services.rb +189 -0
- data/lib/convenient_service/factories/step/instance.rb +32 -0
- data/lib/convenient_service/factories/step.rb +3 -0
- data/lib/convenient_service/factories/steps.rb +126 -0
- data/lib/convenient_service/factories.rb +22 -0
- data/lib/convenient_service/factory.rb +21 -0
- data/lib/convenient_service/rspec/matchers/custom/be_descendant_of.rb +2 -2
- data/lib/convenient_service/rspec/matchers/custom/be_direct_descendant_of.rb +2 -2
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/commands/generate_printable_method.rb +50 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/commands.rb +3 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands/apply_stub_to_track_delegations.rb +78 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands/generate_printable_arguments.rb +100 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands.rb +4 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments.rb +95 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/base.rb +87 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/return_its_value.rb +129 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/with_any_arguments.rb +37 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/with_concrete_arguments.rb +37 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/without_arguments.rb +37 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/values/base.rb +41 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/values/with_calling_original.rb +30 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/values/without_calling_original.rb +30 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings.rb +12 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings_collection/errors.rb +57 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings_collection.rb +171 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/delegation.rb +79 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities.rb +5 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher.rb +276 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities.rb +3 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +66 -233
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_method_step.rb +74 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_result_method_step.rb +66 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_service_step.rb +48 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/generate_expected_step_part.rb +42 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/generate_got_step_part.rb +42 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/match_result_step.rb +89 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands.rb +10 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/errors.rb +35 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base.rb +73 -12
- data/lib/convenient_service/rspec/matchers/custom/singleton_prepend_module.rb +79 -0
- data/lib/convenient_service/rspec/matchers/custom.rb +1 -0
- data/lib/convenient_service/rspec/matchers/singleton_prepend_module.rb +13 -0
- data/lib/convenient_service/rspec/matchers.rb +2 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/concern.rb +85 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/initialize/middleware.rb +27 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/initialize.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/to_kwargs/middleware.rb +25 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/to_kwargs.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb +7 -1
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/concern.rb +27 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/initialize/middleware.rb +27 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/initialize.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/to_kwargs/middleware.rb +25 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/to_kwargs.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +2 -0
- data/lib/convenient_service/service/plugins/has_result_method_steps.rb +0 -2
- data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +40 -4
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb +8 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_direction.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_key.rb +8 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_name.rb +9 -5
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/define_method_in_container.rb +2 -2
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/concern/instance_methods.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/base.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment/commands/define_method_in_container.rb +74 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment/commands.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment.rb +50 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers.rb +1 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values/reassignment.rb +43 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities.rb +1 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/errors.rb +22 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/concern/instance_methods.rb +39 -3
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/can_have_parent_result/middleware.rb +23 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/can_have_parent_result.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins.rb +1 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step_collection.rb +13 -0
- data/lib/convenient_service/service/plugins/has_result_steps/middleware.rb +18 -4
- data/lib/convenient_service/services/run_method_in_organizer.rb +28 -0
- data/lib/convenient_service/services/run_own_method_in_organizer.rb +64 -0
- data/lib/convenient_service/{service/plugins/has_result_method_steps/services.rb → services.rb} +0 -1
- data/lib/convenient_service/support/arguments/null_arguments.rb +28 -0
- data/lib/convenient_service/support/arguments.rb +87 -0
- data/lib/convenient_service/support/copyable.rb +6 -2
- data/lib/convenient_service/support/dependency_container/commands/assert_valid_scope.rb +32 -0
- data/lib/convenient_service/support/dependency_container/commands/import_method.rb +13 -23
- data/lib/convenient_service/support/dependency_container/commands.rb +1 -0
- data/lib/convenient_service/support/dependency_container/constants.rb +4 -2
- data/lib/convenient_service/support/dependency_container/entities/method.rb +2 -9
- data/lib/convenient_service/support/dependency_container/entities/namespace_collection.rb +0 -9
- data/lib/convenient_service/support/dependency_container/errors.rb +26 -1
- data/lib/convenient_service/support/dependency_container/export.rb +8 -0
- data/lib/convenient_service/support/dependency_container/import.rb +3 -1
- data/lib/convenient_service/support/not_passed.rb +3 -1
- data/lib/convenient_service/support/version/null_version.rb +7 -0
- data/lib/convenient_service/support/version.rb +11 -1
- data/lib/convenient_service/support.rb +1 -0
- data/lib/convenient_service/utils/object/instance_variable_delete.rb +41 -0
- data/lib/convenient_service/utils/object/instance_variable_fetch.rb +4 -0
- data/lib/convenient_service/utils/object.rb +9 -0
- data/lib/convenient_service/utils/proc/display.rb +43 -0
- data/lib/convenient_service/utils/proc.rb +5 -0
- data/lib/convenient_service/version.rb +1 -1
- data/lib/convenient_service.rb +6 -0
- data/logo.png +0 -0
- metadata +154 -10
- data/lib/convenient_service/service/plugins/has_result_method_steps/errors.rb +0 -23
- data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +0 -55
- data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_method_in_organizer.rb +0 -30
- data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_own_method_in_organizer.rb +0 -52
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "arguments/commands"
|
4
|
+
|
5
|
+
module ConvenientService
|
6
|
+
module RSpec
|
7
|
+
module Matchers
|
8
|
+
module Custom
|
9
|
+
class DelegateTo
|
10
|
+
module Entities
|
11
|
+
class Matcher
|
12
|
+
module Entities
|
13
|
+
module Chainings
|
14
|
+
module SubMatchers
|
15
|
+
class Arguments < Chainings::SubMatchers::Base
|
16
|
+
##
|
17
|
+
# @return [void]
|
18
|
+
#
|
19
|
+
def apply_stubs!
|
20
|
+
Commands::ApplyStubToTrackDelegations.call(matcher: matcher)
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# @param block_expectation_value [Object]
|
25
|
+
# @return [Boolean]
|
26
|
+
#
|
27
|
+
def matches?(block_expectation_value)
|
28
|
+
super
|
29
|
+
|
30
|
+
matcher.delegations.any? { |delegation| matches_arguments?(delegation.arguments) }
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# @return [String]
|
35
|
+
#
|
36
|
+
# @internal
|
37
|
+
# TODO: Prettier message.
|
38
|
+
#
|
39
|
+
def failure_message
|
40
|
+
<<~MESSAGE.chomp
|
41
|
+
#{failure_message_expected_part}
|
42
|
+
|
43
|
+
#{failure_message_got_part}
|
44
|
+
MESSAGE
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# @return [String]
|
49
|
+
#
|
50
|
+
def failure_message_when_negated
|
51
|
+
"expected `#{matcher.printable_block_expectation}` NOT to delegate to `#{matcher.printable_method}` #{printable_expected_arguments} at least once, but it did."
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# @return [String]
|
56
|
+
#
|
57
|
+
def printable_actual_arguments
|
58
|
+
return "" if matcher.delegations.none?
|
59
|
+
|
60
|
+
matcher.delegations
|
61
|
+
.map { |delegation| Commands::GeneratePrintableArguments.call(arguments: delegation.arguments) }
|
62
|
+
.join(", ")
|
63
|
+
.prepend("with ")
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def failure_message_expected_part
|
69
|
+
"expected `#{matcher.printable_block_expectation}` to delegate to `#{matcher.printable_method}` #{printable_expected_arguments} at least once, but it didn't."
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# @return [String]
|
74
|
+
#
|
75
|
+
# @internal
|
76
|
+
# TODO: String diff.
|
77
|
+
#
|
78
|
+
def failure_message_got_part
|
79
|
+
if matcher.delegations.any?
|
80
|
+
"got delegated #{printable_actual_arguments}"
|
81
|
+
else
|
82
|
+
"got not delegated at all"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
module Chainings
|
12
|
+
module SubMatchers
|
13
|
+
class Base
|
14
|
+
##
|
15
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::DelegateTo]
|
16
|
+
#
|
17
|
+
attr_reader :matcher
|
18
|
+
|
19
|
+
##
|
20
|
+
# @return [Object] Can be any type.
|
21
|
+
#
|
22
|
+
attr_reader :block_expectation_value
|
23
|
+
|
24
|
+
##
|
25
|
+
# @overload initialize(matcher:)
|
26
|
+
# @param matcher [ConvenientService::RSpec::Matchers::Custom::DelegateTo]
|
27
|
+
# @return [void]
|
28
|
+
#
|
29
|
+
# @overload initialize(matcher:, block_expectation_value:)
|
30
|
+
# @param matcher [ConvenientService::RSpec::Matchers::Custom::DelegateTo]
|
31
|
+
# @param block_expectation_value [Object] Can be any type.
|
32
|
+
# @return [void]
|
33
|
+
# @api private
|
34
|
+
#
|
35
|
+
def initialize(matcher:, block_expectation_value: nil)
|
36
|
+
@matcher = matcher
|
37
|
+
@block_expectation_value = block_expectation_value
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# @return [void]
|
42
|
+
#
|
43
|
+
def apply_stubs!
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# @param block_expectation_value [Object] Can be any type.
|
48
|
+
# @return [Boolean]
|
49
|
+
#
|
50
|
+
def matches?(block_expectation_value)
|
51
|
+
@block_expectation_value = block_expectation_value
|
52
|
+
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# @param block_expectation_value [Object] Can be any type.
|
58
|
+
# @return [Boolean]
|
59
|
+
#
|
60
|
+
def does_not_match?(block_expectation_value)
|
61
|
+
!matches?(block_expectation_value)
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# @return [String]
|
66
|
+
#
|
67
|
+
def failure_message
|
68
|
+
""
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# @return [String]
|
73
|
+
#
|
74
|
+
def failure_message_when_negated
|
75
|
+
""
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
module Chainings
|
12
|
+
module SubMatchers
|
13
|
+
class ReturnItsValue < Chainings::SubMatchers::Base
|
14
|
+
##
|
15
|
+
# @param block_expectation_value [Object]
|
16
|
+
# @return [Boolean]
|
17
|
+
#
|
18
|
+
def matches?(block_expectation_value)
|
19
|
+
super
|
20
|
+
|
21
|
+
##
|
22
|
+
# TODO: `with_warmup`.
|
23
|
+
#
|
24
|
+
# IMPORTANT: `and_return_its_value` works only when `delegate_to` checks a pure function.
|
25
|
+
#
|
26
|
+
# For example (1):
|
27
|
+
# def require_dependencies_pure
|
28
|
+
# RequireDependenciesPure.call
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# class RequireDependenciesPure
|
32
|
+
# def self.call
|
33
|
+
# dependencies.require!
|
34
|
+
#
|
35
|
+
# true
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# # Works since `RequireDependenciesPure.call` always returns `true`.
|
40
|
+
# specify do
|
41
|
+
# expect { require_dependencies_pure }
|
42
|
+
# .to delegate_to(RequireDependenciesPure, :call)
|
43
|
+
# .and_return_its_value
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# Example (2):
|
47
|
+
# def require_dependencies_not_pure
|
48
|
+
# RequireDependenciesNotPure.call
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# class RequireDependenciesNotPure
|
52
|
+
# def self.call
|
53
|
+
# return false if dependencies.required?
|
54
|
+
#
|
55
|
+
# dependencies.require!
|
56
|
+
#
|
57
|
+
# true
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# # Does NOT work since `RequireDependenciesNotPure.call` returns `true` for the first time and `false` for the subsequent call.
|
62
|
+
# specify do
|
63
|
+
# expect { require_dependencies_not_pure }
|
64
|
+
# .to delegate_to(RequireDependenciesNotPure, :call)
|
65
|
+
# .and_return_its_value
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
block_expectation_value == matcher.delegation_value
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# @return [String]
|
73
|
+
#
|
74
|
+
def failure_message
|
75
|
+
[failure_message_permanent_part, same_visual_output_note].reject(&:empty?).join("\n\n")
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# @return [String]
|
80
|
+
#
|
81
|
+
def failure_message_when_negated
|
82
|
+
"expected `#{matcher.printable_block_expectation}` NOT to delegate to `#{matcher.printable_method}` and return its value, but it did."
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def failure_message_permanent_part
|
88
|
+
<<~MESSAGE.chomp
|
89
|
+
expected `#{matcher.printable_block_expectation}` to delegate to `#{matcher.printable_method}` and return its value, but it didn't.
|
90
|
+
|
91
|
+
`#{matcher.printable_block_expectation}` returns `#{block_expectation_value.inspect}`, but delegation returns `#{matcher.delegation_value.inspect}`.
|
92
|
+
MESSAGE
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# @internal
|
97
|
+
# NOTE: Early return is harder to understand in this particular case, that is why a casual if is used.
|
98
|
+
#
|
99
|
+
# def note
|
100
|
+
# return "" if block_expectation_value.inspect != matcher.delegation_value.inspect
|
101
|
+
# return "" if block_expectation_value == matcher.delegation_value
|
102
|
+
#
|
103
|
+
# # ...
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
def same_visual_output_note
|
107
|
+
if block_expectation_value.inspect == matcher.delegation_value.inspect && block_expectation_value != matcher.delegation_value
|
108
|
+
<<~MESSAGE.chomp
|
109
|
+
NOTE: `#{block_expectation_value.inspect}` and `#{matcher.delegation_value.inspect}` have the same visual output, but they are different objects in terms of `#==`.
|
110
|
+
|
111
|
+
If it is expected behavior, ignore this note.
|
112
|
+
|
113
|
+
Otherwise, define a meaningful `#==` for `#{block_expectation_value.class}` or adjust its `#inspect` to generate different output.
|
114
|
+
MESSAGE
|
115
|
+
else
|
116
|
+
""
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
module Chainings
|
12
|
+
module SubMatchers
|
13
|
+
class WithAnyArguments < Chainings::SubMatchers::Arguments
|
14
|
+
##
|
15
|
+
# @return [Boolean]
|
16
|
+
#
|
17
|
+
def matches_arguments?(arguments)
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# @return [String]
|
23
|
+
#
|
24
|
+
def printable_expected_arguments
|
25
|
+
"with any arguments (no arguments is also valid)"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
module Chainings
|
12
|
+
module SubMatchers
|
13
|
+
class WithConcreteArguments < Chainings::SubMatchers::Arguments
|
14
|
+
##
|
15
|
+
# @return [Boolean]
|
16
|
+
#
|
17
|
+
def matches_arguments?(arguments)
|
18
|
+
Utils::Bool.to_bool(arguments == matcher.expected_arguments)
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# @return [String]
|
23
|
+
#
|
24
|
+
def printable_expected_arguments
|
25
|
+
"with `#{Arguments::Commands::GeneratePrintableArguments.call(arguments: matcher.expected_arguments)}`"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
module Chainings
|
12
|
+
module SubMatchers
|
13
|
+
class WithoutArguments < Chainings::SubMatchers::Arguments
|
14
|
+
##
|
15
|
+
# @return [Boolean]
|
16
|
+
#
|
17
|
+
def matches_arguments?(arguments)
|
18
|
+
arguments.none?
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# @return [String]
|
23
|
+
#
|
24
|
+
def printable_expected_arguments
|
25
|
+
"without arguments"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
module Chainings
|
12
|
+
module Values
|
13
|
+
class Base
|
14
|
+
##
|
15
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::DelegateTo]
|
16
|
+
#
|
17
|
+
attr_reader :matcher
|
18
|
+
|
19
|
+
##
|
20
|
+
# @return [Object] Can be any type.
|
21
|
+
#
|
22
|
+
attr_reader :value
|
23
|
+
|
24
|
+
##
|
25
|
+
# @param matcher [ConvenientService::RSpec::Matchers::Custom::DelegateTo]
|
26
|
+
# @return [void]
|
27
|
+
#
|
28
|
+
def initialize(matcher:)
|
29
|
+
@matcher = matcher
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
module Chainings
|
12
|
+
module Values
|
13
|
+
class WithCallingOriginal < Chainings::Values::Base
|
14
|
+
##
|
15
|
+
# @return [Boolean]
|
16
|
+
#
|
17
|
+
def value
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
module Chainings
|
12
|
+
module Values
|
13
|
+
class WithoutCallingOriginal < Chainings::Values::Base
|
14
|
+
##
|
15
|
+
# @return [Boolean]
|
16
|
+
#
|
17
|
+
def value
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "chainings/sub_matchers/base"
|
4
|
+
require_relative "chainings/sub_matchers/arguments"
|
5
|
+
require_relative "chainings/sub_matchers/with_any_arguments"
|
6
|
+
require_relative "chainings/sub_matchers/with_concrete_arguments"
|
7
|
+
require_relative "chainings/sub_matchers/without_arguments"
|
8
|
+
require_relative "chainings/sub_matchers/return_its_value"
|
9
|
+
|
10
|
+
require_relative "chainings/values/base"
|
11
|
+
require_relative "chainings/values/with_calling_original"
|
12
|
+
require_relative "chainings/values/without_calling_original"
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
class ChainingsCollection
|
12
|
+
module Errors
|
13
|
+
class CallOriginalChainingIsAlreadySet < ConvenientService::Error
|
14
|
+
def initialize
|
15
|
+
message = <<~TEXT
|
16
|
+
Call original chaining is already set.
|
17
|
+
|
18
|
+
Did you use `with_calling_original` or `without_calling_original` multiple times? Or a combination of them?
|
19
|
+
TEXT
|
20
|
+
|
21
|
+
super(message)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class ArgumentsChainingIsAlreadySet < ConvenientService::Error
|
26
|
+
def initialize
|
27
|
+
message = <<~TEXT
|
28
|
+
Arguments chaining is already set.
|
29
|
+
|
30
|
+
Did you use `with_arguments` or `without_arguments` multiple times? Or a combination of them?
|
31
|
+
TEXT
|
32
|
+
|
33
|
+
super(message)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class ReturnItsValueChainingIsAlreadySet < ConvenientService::Error
|
38
|
+
def initialize
|
39
|
+
message = <<~TEXT
|
40
|
+
Returns its value chaining is already set.
|
41
|
+
|
42
|
+
Did you use `and_returns_its_value` multiple times?
|
43
|
+
TEXT
|
44
|
+
|
45
|
+
super(message)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|