10
10
11
11
include ConvenientService ::RSpec ::Matchers ::DelegateTo
12
12
13
- let ( :container ) do
14
- Class . new . tap do |klass |
15
- klass . class_exec ( first_step_service ) do |first_step_service |
16
- include ConvenientService ::Standard ::Config
17
-
18
- step first_step_service , out : :foo
19
- end
20
- end
21
- end
22
-
23
13
let ( :organizer ) { container . new }
24
14
25
15
let ( :first_step_service ) do
@@ -39,110 +29,148 @@ def result
39
29
describe ".call" do
40
30
subject ( :command_result ) { described_class . call ( method : method , container : step . container , index : step . index ) }
41
31
42
- it "returns `true`" do
43
- expect ( command_result ) . to eq ( true )
44
- end
32
+ context "when `method` is NOT defined in container" do
33
+ let ( :container ) do
34
+ Class . new . tap do |klass |
35
+ klass . class_exec ( first_step_service ) do |first_step_service |
36
+ include ConvenientService ::Standard ::Config
45
37
46
- it "defines `method` in `container`" do
47
- expect { command_result } . to change { ConvenientService ::Utils ::Method . defined? ( method . name . to_s , step . container . klass , private : true ) } . from ( false ) . to ( true )
48
- end
38
+ step first_step_service , out : :foo
39
+ end
40
+ end
41
+ end
49
42
50
- example_group "generated method" do
51
- before do
52
- command_result
43
+ it "returns `true`" do
44
+ expect ( command_result ) . to eq ( true )
53
45
end
54
46
55
- context "when corresponding step is NOT completed" do
56
- let ( :exception_message ) do
57
- <<~TEXT
58
- `out` method `#{ method } ` is called before its corresponding step is completed.
47
+ it "defines `method` in `container`" do
48
+ expect { command_result } . to change { ConvenientService ::Utils ::Method . defined? ( method . name . to_s , step . container . klass , private : true ) } . from ( false ) . to ( true )
49
+ end
59
50
60
- Maybe it makes sense to change steps order?
61
- TEXT
51
+ example_group "generated method" do
52
+ before do
53
+ command_result
62
54
end
63
55
64
- it "raises `ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Exceptions::OutMethodStepIsNotCompleted`" do
65
- expect { organizer . foo }
66
- . to raise_error ( ConvenientService ::Service ::Plugins ::CanHaveSteps ::Entities ::Method ::Exceptions ::OutMethodStepIsNotCompleted )
67
- . with_message ( exception_message )
68
- end
56
+ context "when corresponding step is NOT completed" do
57
+ let ( :exception_message ) do
58
+ <<~TEXT
59
+ `out` method `#{ method } ` is called before its corresponding step is completed.
69
60
70
- specify do
71
- expect { ignoring_exception ( ConvenientService ::Service ::Plugins ::CanHaveSteps ::Entities ::Method ::Exceptions ::OutMethodStepIsNotCompleted ) { organizer . foo } }
72
- . to delegate_to ( ConvenientService , :raise )
73
- end
74
- end
61
+ Maybe it makes sense to change steps order?
62
+ TEXT
63
+ end
75
64
76
- context "when corresponding step is completed" do
77
- before do
78
- ##
79
- # NOTE: Completes the step.
80
- #
81
- organizer . steps [ 0 ] . save_outputs_in_organizer!
82
- end
65
+ it "raises `ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Exceptions::OutMethodStepIsNotCompleted`" do
66
+ expect { organizer . foo }
67
+ . to raise_error ( ConvenientService ::Service ::Plugins ::CanHaveSteps ::Entities ::Method ::Exceptions ::OutMethodStepIsNotCompleted )
68
+ . with_message ( exception_message )
69
+ end
83
70
84
- it "returns corresponding step service result data attribute by key" do
85
- expect ( organizer . foo ) . to eq ( organizer . steps [ 0 ] . result . unsafe_data [ :foo ] )
71
+ specify do
72
+ expect { ignoring_exception ( ConvenientService ::Service ::Plugins ::CanHaveSteps ::Entities ::Method ::Exceptions ::OutMethodStepIsNotCompleted ) { organizer . foo } }
73
+ . to delegate_to ( ConvenientService , :raise )
74
+ end
86
75
end
87
76
88
- context "when multiple corresponding steps are completed" do
89
- let ( :container ) do
90
- Class . new . tap do |klass |
91
- klass . class_exec ( first_step_service , second_step_service ) do |first_step_service , second_step_service |
92
- include ConvenientService ::Standard ::Config
77
+ context "when corresponding step is completed" do
78
+ before do
79
+ ##
80
+ # NOTE: Completes the step.
81
+ #
82
+ organizer . steps [ 0 ] . save_outputs_in_organizer!
83
+ end
84
+
85
+ it "returns corresponding step service result data attribute by key" do
86
+ expect ( organizer . foo ) . to eq ( organizer . steps [ 0 ] . result . unsafe_data [ :foo ] )
87
+ end
93
88
94
- step first_step_service , out : :foo
89
+ context "when multiple corresponding steps are completed" do
90
+ let ( :container ) do
91
+ Class . new . tap do |klass |
92
+ klass . class_exec ( first_step_service , second_step_service ) do |first_step_service , second_step_service |
93
+ include ConvenientService ::Standard ::Config
95
94
96
- step second_step_service , out : :foo
95
+ step first_step_service , out : :foo
96
+
97
+ step second_step_service , out : :foo
98
+ end
97
99
end
98
100
end
101
+
102
+ let ( :second_step_service ) do
103
+ Class . new do
104
+ include ConvenientService ::Standard ::Config
105
+
106
+ def result
107
+ success ( data : { foo : "foo from second step" } )
108
+ end
109
+ end
110
+ end
111
+
112
+ before do
113
+ ##
114
+ # NOTE: Completes the steps.
115
+ #
116
+ organizer . steps [ 0 ] . save_outputs_in_organizer!
117
+ organizer . steps [ 1 ] . save_outputs_in_organizer!
118
+ end
119
+
120
+ it "returns last corresponding step service result data attribute by key" do
121
+ expect ( organizer . foo ) . to eq ( organizer . steps [ 1 ] . result . unsafe_data [ :foo ] )
122
+ end
99
123
end
124
+ end
100
125
101
- let ( :second_step_service ) do
102
- Class . new do
103
- include ConvenientService ::Standard ::Config
126
+ context "when method has alias" do
127
+ let ( :container ) do
128
+ Class . new . tap do |klass |
129
+ klass . class_exec ( first_step_service ) do |first_step_service |
130
+ include ConvenientService ::Standard ::Config
104
131
105
- def result
106
- success ( data : { foo : "foo from second step" } )
132
+ step first_step_service , out : { foo : :bar }
107
133
end
108
134
end
109
135
end
110
136
111
137
before do
112
138
##
113
- # NOTE: Completes the steps .
139
+ # NOTE: Completes the step .
114
140
#
115
141
organizer . steps [ 0 ] . save_outputs_in_organizer!
116
- organizer . steps [ 1 ] . save_outputs_in_organizer!
117
142
end
118
143
119
- it "returns last corresponding step service result data attribute by key" do
120
- expect ( organizer . foo ) . to eq ( organizer . steps [ 1 ] . result . unsafe_data [ :foo ] )
144
+ it "returns corresponding step service result data attribute by key" do
145
+ expect ( organizer . bar ) . to eq ( organizer . steps [ 0 ] . result . unsafe_data [ :bar ] )
121
146
end
122
147
end
123
148
end
149
+ end
150
+
151
+ context "when `method` is defined in container" do
152
+ let ( :container ) do
153
+ Class . new . tap do |klass |
154
+ klass . class_exec ( first_step_service ) do |first_step_service |
155
+ include ConvenientService ::Standard ::Config
124
156
125
- context "when method has alias" do
126
- let ( :container ) do
127
- Class . new . tap do |klass |
128
- klass . class_exec ( first_step_service ) do |first_step_service |
129
- include ConvenientService ::Standard ::Config
157
+ step first_step_service , out : :foo
130
158
131
- step first_step_service , out : { foo : :bar }
159
+ def foo
160
+ :foo
132
161
end
133
162
end
134
163
end
164
+ end
135
165
136
- before do
137
- ##
138
- # NOTE: Completes the step.
139
- #
140
- organizer . steps [ 0 ] . save_outputs_in_organizer!
141
- end
166
+ it "returns `false`" do
167
+ described_class . call ( method : method , container : step . container , index : step . index )
142
168
143
- it "returns corresponding step service result data attribute by key" do
144
- expect ( organizer . bar ) . to eq ( organizer . steps [ 0 ] . result . unsafe_data [ :bar ] )
145
- end
169
+ expect ( command_result ) . to eq ( false )
170
+ end
171
+
172
+ it "does NOT define `method` in `container`" do
173
+ expect { command_result } . not_to change { ConvenientService ::Utils ::Method . defined? ( method . name . to_s , step . container . klass , private : true ) }
146
174
end
147
175
end
148
176
end
0 commit comments