File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,13 @@ def body
13
13
node_parts [ 1 ]
14
14
end
15
15
16
+ # Returns the `rescue` node of the `ensure`, if present.
17
+ #
18
+ # @return [Node, nil] The `rescue` node.
19
+ def rescue_node
20
+ node_parts [ 0 ] if node_parts [ 0 ] . rescue_type?
21
+ end
22
+
16
23
# Checks whether this node body is a void context.
17
24
# Always `true` for `ensure`.
18
25
#
Original file line number Diff line number Diff line change 15
15
it { expect ( ensure_node . body ) . to be_sym_type }
16
16
end
17
17
18
+ describe '#rescue_node' do
19
+ subject ( :rescue_node ) { ensure_node . rescue_node }
20
+
21
+ context 'when there is no `rescue` node' do
22
+ let ( :source ) do
23
+ <<~RUBY
24
+ begin
25
+ beginbody
26
+ ensure
27
+ ensurebody
28
+ end
29
+ RUBY
30
+ end
31
+
32
+ it { is_expected . to be_nil }
33
+ end
34
+
35
+ context 'when there is a `rescue` node' do
36
+ let ( :source ) do
37
+ <<~RUBY
38
+ begin
39
+ beginbody
40
+ rescue
41
+ rescuebody
42
+ ensure
43
+ ensurebody
44
+ end
45
+ RUBY
46
+ end
47
+
48
+ it { is_expected . to be_a ( RuboCop ::AST ::RescueNode ) }
49
+ end
50
+ end
51
+
18
52
describe '#void_context?' do
19
53
let ( :source ) { 'begin; beginbody; ensure; ensurebody; end' }
20
54
Original file line number Diff line number Diff line change 24
24
RUBY
25
25
26
26
it { expect ( rescue_node . body ) . to be_send_type }
27
+
28
+ context 'with multiple lines in body' do
29
+ let ( :source ) { <<~RUBY }
30
+ begin
31
+ foo
32
+ bar
33
+ rescue => e
34
+ baz
35
+ end
36
+ RUBY
37
+
38
+ it { expect ( rescue_node . body ) . to be_begin_type }
39
+ end
27
40
end
28
41
29
42
describe '#resbody_branches' do
You can’t perform that action at this time.
0 commit comments