aspectual 0.1.0 → 0.9.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.
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../lib/aspectual'
4
+
5
+ class ComplexArgsTestClass
6
+ extend Aspectual
7
+
8
+ attr_reader :methods_called
9
+
10
+ def initialize
11
+ # This is to ensure that all methods are properly called within the
12
+ # context of the current instance of this object.
13
+ @methods_called = []
14
+ end
15
+
16
+ def all_params_aspect_method(arg_1, *args, kwarg_1:, **kwargs, &block)
17
+ methods_called << "all_params_aspect_method_block_arg1_#{
18
+ arg_1}_args_#{args.join('_')}_kwarg_1_#{kwarg_1}_#{
19
+ kwargs.to_a.join('_')}_block_result_#{block.call}"
20
+
21
+ self
22
+ end
23
+
24
+ def all_params_around_aspect_method(arg_1, *args, kwarg_1:, **kwargs, &block)
25
+ methods_called << "before_block_block_around_aspect_method_block_arg1_#{
26
+ arg_1}_args_#{args.join('_')}_kwarg_1_#{kwarg_1}_#{kwargs.to_a.join('_')}"
27
+
28
+ block.call
29
+
30
+ methods_called << "after_block_block_around_aspect_method_block_arg1_#{
31
+ arg_1}_args_#{args.join('_')}_kwarg_1_#{kwarg_1}_#{kwargs.to_a.join('_')}"
32
+
33
+ self
34
+ end
35
+
36
+ aspects before: :all_params_aspect_method
37
+ def before_all_params_test_method(arg_1, *args, kwarg_1:, **kwargs, &block)
38
+ methods_called << "before_all_params_test_method_block_arg1_#{
39
+ arg_1}_args_#{args.join('_')}_kwarg_1_#{kwarg_1}_#{
40
+ kwargs.to_a.join('_')}_block_result_#{block.call}"
41
+
42
+ self
43
+ end
44
+
45
+ aspects around: :all_params_around_aspect_method
46
+ def around_all_params_test_method(arg_1, *args, kwarg_1:, **kwargs, &block)
47
+ methods_called << "around_all_params_test_method_block_arg1_#{
48
+ arg_1}_args_#{args.join('_')}_kwarg_1_#{kwarg_1}_#{
49
+ kwargs.to_a.join('_')}_block_result_#{block.call}"
50
+
51
+ self
52
+ end
53
+
54
+ aspects after: :all_params_aspect_method
55
+ def after_all_params_test_method(arg_1, *args, kwarg_1:, **kwargs, &block)
56
+ methods_called << "after_all_params_test_method_block_arg1_#{
57
+ arg_1}_args_#{args.join('_')}_kwarg_1_#{kwarg_1}_#{
58
+ kwargs.to_a.join('_')}_block_result_#{block.call}"
59
+
60
+ self
61
+ end
62
+ end
63
+
64
+ describe Aspectual do
65
+ describe 'methods with many complex arguments' do
66
+ it 'can handle before aspects' do
67
+ test_instance = ComplexArgsTestClass.new.before_all_params_test_method(
68
+ 'arg1',
69
+ 'arg2',
70
+ kwarg_1: :val_1,
71
+ kwarg_2: :val_2,
72
+ ) { 'called' }
73
+
74
+ expect(test_instance.methods_called).to eq(
75
+ %w[
76
+ all_params_aspect_method_block_arg1_arg1_args_arg2_kwarg_1_val_1_kwarg_2_val_2_block_result_called
77
+ before_all_params_test_method_block_arg1_arg1_args_arg2_kwarg_1_val_1_kwarg_2_val_2_block_result_called
78
+ ],
79
+ )
80
+ end
81
+
82
+ it 'can handle around aspects' do
83
+ test_instance = ComplexArgsTestClass.new.around_all_params_test_method(
84
+ 'arg1',
85
+ 'arg2',
86
+ kwarg_1: :val_1,
87
+ kwarg_2: :val_2,
88
+ ) { 'called' }
89
+
90
+ expect(test_instance.methods_called).to eq(
91
+ %w[
92
+ before_block_block_around_aspect_method_block_arg1_arg1_args_arg2_kwarg_1_val_1_kwarg_2_val_2
93
+ around_all_params_test_method_block_arg1_arg1_args_arg2_kwarg_1_val_1_kwarg_2_val_2_block_result_called
94
+ after_block_block_around_aspect_method_block_arg1_arg1_args_arg2_kwarg_1_val_1_kwarg_2_val_2
95
+ ],
96
+ )
97
+ end
98
+
99
+ it 'can handle after aspects' do
100
+ test_instance = ComplexArgsTestClass.new.after_all_params_test_method(
101
+ 'arg1',
102
+ 'arg2',
103
+ kwarg_1: :val_1,
104
+ kwarg_2: :val_2,
105
+ ) { 'called' }
106
+
107
+ expect(test_instance.methods_called).to eq(
108
+ %w[
109
+ after_all_params_test_method_block_arg1_arg1_args_arg2_kwarg_1_val_1_kwarg_2_val_2_block_result_called
110
+ all_params_aspect_method_block_arg1_arg1_args_arg2_kwarg_1_val_1_kwarg_2_val_2_block_result_called
111
+ ],
112
+ )
113
+ end
114
+ end
115
+ end