rubocop 0.13.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (222) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/CHANGELOG.md +42 -0
  4. data/README.md +59 -54
  5. data/config/default.yml +124 -95
  6. data/config/disabled.yml +4 -0
  7. data/config/enabled.yml +286 -264
  8. data/lib/rubocop.rb +10 -3
  9. data/lib/rubocop/cli.rb +10 -171
  10. data/lib/rubocop/cop/cop.rb +14 -11
  11. data/lib/rubocop/cop/lint/debugger.rb +35 -0
  12. data/lib/rubocop/cop/lint/syntax.rb +34 -0
  13. data/lib/rubocop/cop/offence.rb +15 -23
  14. data/lib/rubocop/cop/style/align_array.rb +1 -10
  15. data/lib/rubocop/cop/style/align_hash.rb +14 -2
  16. data/lib/rubocop/cop/style/align_parameters.rb +1 -11
  17. data/lib/rubocop/cop/style/and_or.rb +13 -11
  18. data/lib/rubocop/cop/style/attr.rb +1 -1
  19. data/lib/rubocop/cop/style/autocorrect_alignment.rb +31 -6
  20. data/lib/rubocop/cop/style/blocks.rb +14 -6
  21. data/lib/rubocop/cop/style/character_literal.rb +1 -1
  22. data/lib/rubocop/cop/style/class_length.rb +38 -0
  23. data/lib/rubocop/cop/style/collection_methods.rb +1 -1
  24. data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
  25. data/lib/rubocop/cop/style/configurable_naming.rb +47 -0
  26. data/lib/rubocop/cop/style/def_parentheses.rb +2 -2
  27. data/lib/rubocop/cop/style/empty_literal.rb +1 -1
  28. data/lib/rubocop/cop/style/even_odd.rb +7 -3
  29. data/lib/rubocop/cop/style/hash_methods.rb +1 -1
  30. data/lib/rubocop/cop/style/hash_syntax.rb +36 -7
  31. data/lib/rubocop/cop/style/lambda_call.rb +36 -11
  32. data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -1
  33. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +41 -0
  34. data/lib/rubocop/cop/style/method_length.rb +2 -13
  35. data/lib/rubocop/cop/style/method_name.rb +42 -0
  36. data/lib/rubocop/cop/style/numeric_literals.rb +4 -0
  37. data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
  38. data/lib/rubocop/cop/style/raise_args.rb +60 -0
  39. data/lib/rubocop/cop/style/redundant_exception.rb +32 -0
  40. data/lib/rubocop/cop/style/redundant_return.rb +14 -5
  41. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  42. data/lib/rubocop/cop/style/semicolon.rb +13 -4
  43. data/lib/rubocop/cop/style/signal_exception.rb +63 -14
  44. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  45. data/lib/rubocop/cop/style/string_help.rb +4 -1
  46. data/lib/rubocop/cop/style/string_literals.rb +34 -11
  47. data/lib/rubocop/cop/style/surrounding_space.rb +64 -17
  48. data/lib/rubocop/cop/style/tab.rb +1 -1
  49. data/lib/rubocop/cop/style/variable_name.rb +44 -0
  50. data/lib/rubocop/cop/style/when_then.rb +1 -1
  51. data/lib/rubocop/cop/style/while_until_do.rb +1 -1
  52. data/lib/rubocop/cop/team.rb +4 -7
  53. data/lib/rubocop/cop/util.rb +12 -0
  54. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
  55. data/lib/rubocop/formatter/emacs_style_formatter.rb +5 -2
  56. data/lib/rubocop/formatter/json_formatter.rb +1 -0
  57. data/lib/rubocop/formatter/progress_formatter.rb +9 -13
  58. data/lib/rubocop/formatter/simple_text_formatter.rb +63 -15
  59. data/lib/rubocop/options.rb +184 -0
  60. data/lib/rubocop/processed_source.rb +4 -0
  61. data/lib/rubocop/version.rb +1 -1
  62. data/rubocop.gemspec +1 -1
  63. data/spec/rubocop/cli_spec.rb +870 -1001
  64. data/spec/rubocop/config_spec.rb +13 -13
  65. data/spec/rubocop/config_store_spec.rb +38 -37
  66. data/spec/rubocop/cop/commissioner_spec.rb +42 -46
  67. data/spec/rubocop/cop/cop_spec.rb +72 -77
  68. data/spec/rubocop/cop/corrector_spec.rb +51 -55
  69. data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +100 -106
  70. data/spec/rubocop/cop/lint/block_alignment_spec.rb +403 -409
  71. data/spec/rubocop/cop/lint/debugger_spec.rb +39 -0
  72. data/spec/rubocop/cop/lint/empty_ensure_spec.rb +19 -25
  73. data/spec/rubocop/cop/lint/end_alignment_spec.rb +50 -56
  74. data/spec/rubocop/cop/lint/end_in_method_spec.rb +20 -26
  75. data/spec/rubocop/cop/lint/ensure_return_spec.rb +30 -36
  76. data/spec/rubocop/cop/lint/eval_spec.rb +25 -31
  77. data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +22 -28
  78. data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +51 -57
  79. data/spec/rubocop/cop/lint/loop_spec.rb +17 -23
  80. data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +51 -57
  81. data/spec/rubocop/cop/lint/rescue_exception_spec.rb +105 -111
  82. data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +230 -236
  83. data/spec/rubocop/cop/lint/syntax_spec.rb +33 -0
  84. data/spec/rubocop/cop/lint/unreachable_code_spec.rb +51 -57
  85. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +1544 -1550
  86. data/spec/rubocop/cop/lint/useless_comparison_spec.rb +21 -27
  87. data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +119 -125
  88. data/spec/rubocop/cop/lint/void_spec.rb +50 -56
  89. data/spec/rubocop/cop/offence_spec.rb +101 -131
  90. data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +6 -12
  91. data/spec/rubocop/cop/rails/read_attribute_spec.rb +6 -12
  92. data/spec/rubocop/cop/rails/validation_spec.rb +13 -19
  93. data/spec/rubocop/cop/style/access_control_spec.rb +146 -152
  94. data/spec/rubocop/cop/style/alias_spec.rb +30 -36
  95. data/spec/rubocop/cop/style/align_array_spec.rb +57 -56
  96. data/spec/rubocop/cop/style/align_hash_spec.rb +256 -237
  97. data/spec/rubocop/cop/style/align_parameters_spec.rb +216 -202
  98. data/spec/rubocop/cop/style/and_or_spec.rb +51 -55
  99. data/spec/rubocop/cop/style/ascii_comments_spec.rb +14 -20
  100. data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +26 -32
  101. data/spec/rubocop/cop/style/attr_spec.rb +11 -17
  102. data/spec/rubocop/cop/style/begin_block_spec.rb +6 -12
  103. data/spec/rubocop/cop/style/block_comments_spec.rb +13 -19
  104. data/spec/rubocop/cop/style/block_nesting_spec.rb +134 -140
  105. data/spec/rubocop/cop/style/blocks_spec.rb +81 -84
  106. data/spec/rubocop/cop/style/case_equality_spec.rb +5 -11
  107. data/spec/rubocop/cop/style/case_indentation_spec.rb +71 -77
  108. data/spec/rubocop/cop/style/character_literal_spec.rb +31 -37
  109. data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +31 -37
  110. data/spec/rubocop/cop/style/class_length_spec.rb +65 -0
  111. data/spec/rubocop/cop/style/class_methods_spec.rb +35 -41
  112. data/spec/rubocop/cop/style/class_vars_spec.rb +11 -17
  113. data/spec/rubocop/cop/style/collection_methods_spec.rb +41 -47
  114. data/spec/rubocop/cop/style/colon_method_call_spec.rb +45 -51
  115. data/spec/rubocop/cop/style/comment_annotation_spec.rb +79 -85
  116. data/spec/rubocop/cop/style/constant_name_spec.rb +45 -51
  117. data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +28 -34
  118. data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +23 -29
  119. data/spec/rubocop/cop/style/documentation_spec.rb +60 -66
  120. data/spec/rubocop/cop/style/dot_position_spec.rb +50 -56
  121. data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +109 -110
  122. data/spec/rubocop/cop/style/empty_lines_spec.rb +28 -34
  123. data/spec/rubocop/cop/style/empty_literal_spec.rb +80 -86
  124. data/spec/rubocop/cop/style/encoding_spec.rb +50 -56
  125. data/spec/rubocop/cop/style/end_block_spec.rb +6 -12
  126. data/spec/rubocop/cop/style/end_of_line_spec.rb +13 -19
  127. data/spec/rubocop/cop/style/even_odd_spec.rb +69 -41
  128. data/spec/rubocop/cop/style/favor_join_spec.rb +21 -27
  129. data/spec/rubocop/cop/style/favor_modifier_spec.rb +180 -176
  130. data/spec/rubocop/cop/style/favor_sprintf_spec.rb +41 -47
  131. data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +63 -69
  132. data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +32 -38
  133. data/spec/rubocop/cop/style/final_newline_spec.rb +16 -22
  134. data/spec/rubocop/cop/style/for_spec.rb +18 -24
  135. data/spec/rubocop/cop/style/global_vars_spec.rb +23 -29
  136. data/spec/rubocop/cop/style/hash_methods_spec.rb +39 -45
  137. data/spec/rubocop/cop/style/hash_syntax_spec.rb +93 -65
  138. data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +11 -17
  139. data/spec/rubocop/cop/style/indentation_width_spec.rb +377 -383
  140. data/spec/rubocop/cop/style/lambda_call_spec.rb +40 -22
  141. data/spec/rubocop/cop/style/lambda_spec.rb +30 -34
  142. data/spec/rubocop/cop/style/leading_comment_space_spec.rb +44 -50
  143. data/spec/rubocop/cop/style/line_length_spec.rb +11 -17
  144. data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +14 -20
  145. data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +60 -0
  146. data/spec/rubocop/cop/style/method_length_spec.rb +127 -133
  147. data/spec/rubocop/cop/style/method_name_spec.rb +103 -0
  148. data/spec/rubocop/cop/style/module_function_spec.rb +16 -22
  149. data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +64 -70
  150. data/spec/rubocop/cop/style/multiline_if_then_spec.rb +74 -80
  151. data/spec/rubocop/cop/style/nil_comparison_spec.rb +20 -26
  152. data/spec/rubocop/cop/style/not_spec.rb +13 -19
  153. data/spec/rubocop/cop/style/numeric_literals_spec.rb +36 -35
  154. data/spec/rubocop/cop/style/one_line_conditional_spec.rb +5 -11
  155. data/spec/rubocop/cop/style/op_method_spec.rb +61 -67
  156. data/spec/rubocop/cop/style/parameter_lists_spec.rb +31 -37
  157. data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +62 -68
  158. data/spec/rubocop/cop/style/perl_backrefs_spec.rb +9 -15
  159. data/spec/rubocop/cop/style/proc_spec.rb +13 -19
  160. data/spec/rubocop/cop/style/raise_args_spec.rb +55 -0
  161. data/spec/rubocop/cop/style/reduce_arguments_spec.rb +49 -55
  162. data/spec/rubocop/cop/style/redundant_begin_spec.rb +47 -53
  163. data/spec/rubocop/cop/style/redundant_exception_spec.rb +27 -0
  164. data/spec/rubocop/cop/style/redundant_return_spec.rb +164 -72
  165. data/spec/rubocop/cop/style/redundant_self_spec.rb +109 -115
  166. data/spec/rubocop/cop/style/regexp_literal_spec.rb +57 -63
  167. data/spec/rubocop/cop/style/rescue_modifier_spec.rb +99 -105
  168. data/spec/rubocop/cop/style/semicolon_spec.rb +95 -90
  169. data/spec/rubocop/cop/style/signal_exception_spec.rb +248 -95
  170. data/spec/rubocop/cop/style/single_line_methods_spec.rb +45 -51
  171. data/spec/rubocop/cop/style/space_after_colon_spec.rb +14 -20
  172. data/spec/rubocop/cop/style/space_after_comma_spec.rb +16 -22
  173. data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +48 -54
  174. data/spec/rubocop/cop/style/space_after_method_name_spec.rb +49 -55
  175. data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +10 -16
  176. data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +118 -50
  177. data/spec/rubocop/cop/style/space_around_equals_in_default_parameter_spec.rb +18 -24
  178. data/spec/rubocop/cop/style/space_around_operators_spec.rb +204 -210
  179. data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +36 -42
  180. data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +39 -45
  181. data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +62 -68
  182. data/spec/rubocop/cop/style/space_inside_parens_spec.rb +18 -24
  183. data/spec/rubocop/cop/style/special_global_vars_spec.rb +40 -46
  184. data/spec/rubocop/cop/style/string_literals_spec.rb +148 -70
  185. data/spec/rubocop/cop/style/symbol_array_spec.rb +28 -34
  186. data/spec/rubocop/cop/style/symbol_name_spec.rb +132 -138
  187. data/spec/rubocop/cop/style/tab_spec.rb +9 -15
  188. data/spec/rubocop/cop/style/ternary_operator_spec.rb +25 -31
  189. data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +10 -16
  190. data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +14 -20
  191. data/spec/rubocop/cop/style/trivial_accessors_spec.rb +374 -380
  192. data/spec/rubocop/cop/style/unless_else_spec.rb +17 -23
  193. data/spec/rubocop/cop/style/variable_interpolation_spec.rb +36 -42
  194. data/spec/rubocop/cop/style/variable_name_spec.rb +83 -0
  195. data/spec/rubocop/cop/style/when_then_spec.rb +31 -37
  196. data/spec/rubocop/cop/style/while_until_do_spec.rb +47 -53
  197. data/spec/rubocop/cop/style/word_array_spec.rb +49 -55
  198. data/spec/rubocop/cop/team_spec.rb +125 -127
  199. data/spec/rubocop/cop/variable_inspector/assignment_spec.rb +176 -180
  200. data/spec/rubocop/cop/variable_inspector/locatable_spec.rb +580 -586
  201. data/spec/rubocop/cop/variable_inspector/scope_spec.rb +140 -146
  202. data/spec/rubocop/cop/variable_inspector/variable_spec.rb +52 -58
  203. data/spec/rubocop/cop/variable_inspector/variable_table_spec.rb +217 -223
  204. data/spec/rubocop/cop/variable_inspector_spec.rb +15 -19
  205. data/spec/rubocop/formatter/clang_style_formatter_spec.rb +35 -36
  206. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +2 -2
  207. data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +24 -1
  208. data/spec/rubocop/formatter/file_list_formatter_spec.rb +1 -1
  209. data/spec/rubocop/formatter/formatter_set_spec.rb +3 -3
  210. data/spec/rubocop/formatter/json_formatter_spec.rb +7 -2
  211. data/spec/rubocop/formatter/offence_count_formatter_spec.rb +1 -1
  212. data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
  213. data/spec/rubocop/formatter/simple_text_formatter_spec.rb +55 -6
  214. data/spec/rubocop/options_spec.rb +233 -0
  215. data/spec/rubocop/processed_source_spec.rb +85 -42
  216. data/spec/rubocop/source_parser_spec.rb +108 -110
  217. data/spec/rubocop/target_finder_spec.rb +125 -127
  218. data/spec/rubocop/token_spec.rb +15 -17
  219. metadata +32 -8
  220. data/lib/rubocop/backports/bsearch.rb +0 -39
  221. data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +0 -77
  222. data/spec/rubocop/cop/style/method_and_variable_snake_case_spec.rb +0 -102
@@ -2,738 +2,732 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- module Rubocop
6
- module Cop
7
- module VariableInspector
8
- describe Locatable do
9
- include ASTHelper
10
- include AST::Sexp
5
+ describe Rubocop::Cop::VariableInspector::Locatable do
6
+ include ASTHelper
7
+ include AST::Sexp
11
8
 
12
- class LocatableObject
13
- include Locatable
9
+ class LocatableObject
10
+ include Rubocop::Cop::VariableInspector::Locatable
14
11
 
15
- attr_reader :node, :scope
12
+ attr_reader :node, :scope
16
13
 
17
- def initialize(node, scope)
18
- @node = node
19
- @scope = scope
20
- end
21
- end
14
+ def initialize(node, scope)
15
+ @node = node
16
+ @scope = scope
17
+ end
18
+ end
22
19
 
23
- let(:ast) do
24
- processed_source = Rubocop::SourceParser.parse(source)
25
- processed_source.ast
26
- end
20
+ let(:ast) do
21
+ processed_source = Rubocop::SourceParser.parse(source)
22
+ processed_source.ast
23
+ end
27
24
 
28
- let(:def_node) do
29
- found_node = scan_node(ast, include_origin_node: true) do |node|
30
- break node if node.type == :def
31
- end
32
- fail 'No def node found!' unless found_node
33
- found_node
34
- end
25
+ let(:def_node) do
26
+ found_node = scan_node(ast, include_origin_node: true) do |node|
27
+ break node if node.type == :def
28
+ end
29
+ fail 'No def node found!' unless found_node
30
+ found_node
31
+ end
35
32
 
36
- let(:lvasgn_node) do
37
- found_node = scan_node(ast) do |node|
38
- break node if node.type == :lvasgn
39
- end
40
- fail 'No lvasgn node found!' unless found_node
41
- found_node
42
- end
33
+ let(:lvasgn_node) do
34
+ found_node = scan_node(ast) do |node|
35
+ break node if node.type == :lvasgn
36
+ end
37
+ fail 'No lvasgn node found!' unless found_node
38
+ found_node
39
+ end
43
40
 
44
- let(:scope) { Scope.new(def_node) }
45
- let(:assignment) { LocatableObject.new(lvasgn_node, scope) }
41
+ let(:scope) { Rubocop::Cop::VariableInspector::Scope.new(def_node) }
42
+ let(:assignment) { LocatableObject.new(lvasgn_node, scope) }
46
43
 
47
- describe '#ancestor_nodes_in_scope' do
48
- let(:source) do
49
- <<-END
50
- class SomeClass
51
- def some_method(flag)
52
- puts 'Hello World!'
44
+ describe '#ancestor_nodes_in_scope' do
45
+ let(:source) do
46
+ <<-END
47
+ class SomeClass
48
+ def some_method(flag)
49
+ puts 'Hello World!'
53
50
 
54
- if flag > 0
55
- foo = 1
56
- end
57
- end
58
- end
59
- END
60
- end
61
-
62
- it 'returns its ancestor nodes in the scope excluding scope node' do
63
- ancestor_types = assignment.ancestor_nodes_in_scope.map(&:type)
64
- expect(ancestor_types).to eq([:begin, :if])
51
+ if flag > 0
52
+ foo = 1
53
+ end
65
54
  end
66
55
  end
56
+ END
57
+ end
67
58
 
68
- describe '#branch_point_node' do
69
- context 'when it is not in branch' do
70
- let(:source) do
71
- <<-END
72
- def some_method(flag)
73
- foo = 1
74
- end
75
- END
76
- end
59
+ it 'returns its ancestor nodes in the scope excluding scope node' do
60
+ ancestor_types = assignment.ancestor_nodes_in_scope.map(&:type)
61
+ expect(ancestor_types).to eq([:begin, :if])
62
+ end
63
+ end
77
64
 
78
- it 'returns nil' do
79
- expect(assignment.branch_point_node).to be_nil
80
- end
65
+ describe '#branch_point_node' do
66
+ context 'when it is not in branch' do
67
+ let(:source) do
68
+ <<-END
69
+ def some_method(flag)
70
+ foo = 1
81
71
  end
72
+ END
73
+ end
82
74
 
83
- context 'when it is inside of if' do
84
- let(:source) do
85
- <<-END
86
- def some_method(flag)
87
- if flag
88
- foo = 1
89
- end
90
- end
91
- END
92
- end
75
+ it 'returns nil' do
76
+ expect(assignment.branch_point_node).to be_nil
77
+ end
78
+ end
93
79
 
94
- it 'returns the if node' do
95
- expect(assignment.branch_point_node.type).to eq(:if)
80
+ context 'when it is inside of if' do
81
+ let(:source) do
82
+ <<-END
83
+ def some_method(flag)
84
+ if flag
85
+ foo = 1
96
86
  end
97
87
  end
88
+ END
89
+ end
98
90
 
99
- context 'when it is inside of else of if' do
100
- let(:source) do
101
- <<-END
102
- def some_method(flag)
103
- if flag
104
- else
105
- foo = 1
106
- end
107
- end
108
- END
109
- end
91
+ it 'returns the if node' do
92
+ expect(assignment.branch_point_node.type).to eq(:if)
93
+ end
94
+ end
110
95
 
111
- it 'returns the if node' do
112
- expect(assignment.branch_point_node.type).to eq(:if)
96
+ context 'when it is inside of else of if' do
97
+ let(:source) do
98
+ <<-END
99
+ def some_method(flag)
100
+ if flag
101
+ else
102
+ foo = 1
113
103
  end
114
104
  end
105
+ END
106
+ end
115
107
 
116
- context 'when it is inside of if condition' do
117
- let(:source) do
118
- <<-END
119
- def some_method(flag)
120
- if foo = 1
121
- do_something
122
- end
123
- end
124
- END
125
- end
108
+ it 'returns the if node' do
109
+ expect(assignment.branch_point_node.type).to eq(:if)
110
+ end
111
+ end
126
112
 
127
- it 'returns nil' do
128
- expect(assignment.branch_point_node).to be_nil
113
+ context 'when it is inside of if condition' do
114
+ let(:source) do
115
+ <<-END
116
+ def some_method(flag)
117
+ if foo = 1
118
+ do_something
129
119
  end
130
120
  end
121
+ END
122
+ end
131
123
 
132
- context 'when multiple if are nested' do
133
- context 'and it is inside of inner if' do
134
- let(:source) do
135
- <<-END
136
- def some_method(a, b)
137
- if a
138
- if b
139
- foo = 1
140
- end
141
- end
142
- end
143
- END
144
- end
124
+ it 'returns nil' do
125
+ expect(assignment.branch_point_node).to be_nil
126
+ end
127
+ end
145
128
 
146
- it 'returns inner if node' do
147
- if_node = assignment.branch_point_node
148
- expect(if_node.type).to eq(:if)
149
- condition_node = if_node.children.first
150
- expect(condition_node).to eq(s(:lvar, :b))
129
+ context 'when multiple if are nested' do
130
+ context 'and it is inside of inner if' do
131
+ let(:source) do
132
+ <<-END
133
+ def some_method(a, b)
134
+ if a
135
+ if b
136
+ foo = 1
137
+ end
151
138
  end
152
139
  end
140
+ END
141
+ end
153
142
 
154
- context 'and it is inside of inner if condition' do
155
- let(:source) do
156
- <<-END
157
- def some_method(a, b)
158
- if a
159
- if foo = 1
160
- do_something
161
- end
162
- end
163
- end
164
- END
165
- end
143
+ it 'returns inner if node' do
144
+ if_node = assignment.branch_point_node
145
+ expect(if_node.type).to eq(:if)
146
+ condition_node = if_node.children.first
147
+ expect(condition_node).to eq(s(:lvar, :b))
148
+ end
149
+ end
166
150
 
167
- it 'returns the next outer if node' do
168
- if_node = assignment.branch_point_node
169
- expect(if_node.type).to eq(:if)
170
- condition_node = if_node.children.first
171
- expect(condition_node).to eq(s(:lvar, :a))
151
+ context 'and it is inside of inner if condition' do
152
+ let(:source) do
153
+ <<-END
154
+ def some_method(a, b)
155
+ if a
156
+ if foo = 1
157
+ do_something
158
+ end
172
159
  end
173
160
  end
174
- end
161
+ END
162
+ end
175
163
 
176
- context 'when it is inside of when of case' do
177
- let(:source) do
178
- <<-END
179
- def some_method(flag)
180
- case flag
181
- when 1
182
- foo = 1
183
- end
184
- end
185
- END
186
- end
164
+ it 'returns the next outer if node' do
165
+ if_node = assignment.branch_point_node
166
+ expect(if_node.type).to eq(:if)
167
+ condition_node = if_node.children.first
168
+ expect(condition_node).to eq(s(:lvar, :a))
169
+ end
170
+ end
171
+ end
187
172
 
188
- it 'returns the case node' do
189
- expect(assignment.branch_point_node.type).to eq(:case)
173
+ context 'when it is inside of when of case' do
174
+ let(:source) do
175
+ <<-END
176
+ def some_method(flag)
177
+ case flag
178
+ when 1
179
+ foo = 1
190
180
  end
191
181
  end
182
+ END
183
+ end
192
184
 
193
- context 'when it is on the left side of &&' do
194
- let(:source) do
195
- <<-END
196
- def some_method
197
- (foo = 1) && do_something
198
- end
199
- END
200
- end
185
+ it 'returns the case node' do
186
+ expect(assignment.branch_point_node.type).to eq(:case)
187
+ end
188
+ end
201
189
 
202
- it 'returns nil' do
203
- expect(assignment.branch_point_node).to be_nil
204
- end
190
+ context 'when it is on the left side of &&' do
191
+ let(:source) do
192
+ <<-END
193
+ def some_method
194
+ (foo = 1) && do_something
205
195
  end
196
+ END
197
+ end
206
198
 
207
- context 'when it is on the right side of &&' do
208
- let(:source) do
209
- <<-END
210
- def some_method
211
- do_something && (foo = 1)
212
- end
213
- END
214
- end
199
+ it 'returns nil' do
200
+ expect(assignment.branch_point_node).to be_nil
201
+ end
202
+ end
215
203
 
216
- it 'returns the and node' do
217
- expect(assignment.branch_point_node.type).to eq(:and)
218
- end
204
+ context 'when it is on the right side of &&' do
205
+ let(:source) do
206
+ <<-END
207
+ def some_method
208
+ do_something && (foo = 1)
219
209
  end
210
+ END
211
+ end
220
212
 
221
- context 'when it is on the left side of ||' do
222
- let(:source) do
223
- <<-END
224
- def some_method
225
- (foo = 1) || do_something
226
- end
227
- END
228
- end
213
+ it 'returns the and node' do
214
+ expect(assignment.branch_point_node.type).to eq(:and)
215
+ end
216
+ end
229
217
 
230
- it 'returns nil' do
231
- expect(assignment.branch_point_node).to be_nil
232
- end
218
+ context 'when it is on the left side of ||' do
219
+ let(:source) do
220
+ <<-END
221
+ def some_method
222
+ (foo = 1) || do_something
233
223
  end
224
+ END
225
+ end
234
226
 
235
- context 'when it is on the right side of ||' do
236
- let(:source) do
237
- <<-END
238
- def some_method
239
- do_something || (foo = 1)
240
- end
241
- END
242
- end
227
+ it 'returns nil' do
228
+ expect(assignment.branch_point_node).to be_nil
229
+ end
230
+ end
243
231
 
244
- it 'returns the or node' do
245
- expect(assignment.branch_point_node.type).to eq(:or)
246
- end
232
+ context 'when it is on the right side of ||' do
233
+ let(:source) do
234
+ <<-END
235
+ def some_method
236
+ do_something || (foo = 1)
247
237
  end
238
+ END
239
+ end
248
240
 
249
- context 'when multiple && are chained' do
250
- context 'and it is on the right side of the right &&' do
251
- let(:source) do
252
- <<-END
253
- def some_method
254
- do_something && do_anything && (foo = 1)
255
- end
256
- END
257
- end
241
+ it 'returns the or node' do
242
+ expect(assignment.branch_point_node.type).to eq(:or)
243
+ end
244
+ end
258
245
 
259
- it 'returns the right and node' do
260
- and_node = assignment.branch_point_node
261
- expect(and_node.type).to eq(:and)
262
- right_side_node = and_node.children[1]
263
- expect(right_side_node.type).to eq(:begin)
264
- end
246
+ context 'when multiple && are chained' do
247
+ context 'and it is on the right side of the right &&' do
248
+ let(:source) do
249
+ <<-END
250
+ def some_method
251
+ do_something && do_anything && (foo = 1)
265
252
  end
253
+ END
254
+ end
266
255
 
267
- context 'and it is on the right side of the left &&' do
268
- let(:source) do
269
- <<-END
270
- def some_method
271
- do_something && (foo = 1) && do_anything
272
- end
273
- END
274
- end
256
+ it 'returns the right and node' do
257
+ and_node = assignment.branch_point_node
258
+ expect(and_node.type).to eq(:and)
259
+ right_side_node = and_node.children[1]
260
+ expect(right_side_node.type).to eq(:begin)
261
+ end
262
+ end
275
263
 
276
- it 'returns the left and node' do
277
- and_node = assignment.branch_point_node
278
- expect(and_node.type).to eq(:and)
279
- right_side_node = and_node.children[1]
280
- expect(right_side_node.type).to eq(:begin)
281
- end
264
+ context 'and it is on the right side of the left &&' do
265
+ let(:source) do
266
+ <<-END
267
+ def some_method
268
+ do_something && (foo = 1) && do_anything
282
269
  end
283
- end
270
+ END
271
+ end
284
272
 
285
- context 'when it is inside of begin with rescue' do
286
- let(:source) do
287
- <<-END
288
- def some_method(flag)
289
- begin
290
- foo = 1
291
- rescue
292
- do_something
293
- end
294
- end
295
- END
296
- end
273
+ it 'returns the left and node' do
274
+ and_node = assignment.branch_point_node
275
+ expect(and_node.type).to eq(:and)
276
+ right_side_node = and_node.children[1]
277
+ expect(right_side_node.type).to eq(:begin)
278
+ end
279
+ end
280
+ end
297
281
 
298
- it 'returns the rescue node' do
299
- expect(assignment.branch_point_node.type).to eq(:rescue)
282
+ context 'when it is inside of begin with rescue' do
283
+ let(:source) do
284
+ <<-END
285
+ def some_method(flag)
286
+ begin
287
+ foo = 1
288
+ rescue
289
+ do_something
300
290
  end
301
291
  end
292
+ END
293
+ end
302
294
 
303
- context 'when it is inside of rescue' do
304
- let(:source) do
305
- <<-END
306
- def some_method(flag)
307
- begin
308
- do_something
309
- rescue
310
- foo = 1
311
- end
312
- end
313
- END
314
- end
295
+ it 'returns the rescue node' do
296
+ expect(assignment.branch_point_node.type).to eq(:rescue)
297
+ end
298
+ end
315
299
 
316
- it 'returns the rescue node' do
317
- expect(assignment.branch_point_node.type).to eq(:rescue)
300
+ context 'when it is inside of rescue' do
301
+ let(:source) do
302
+ <<-END
303
+ def some_method(flag)
304
+ begin
305
+ do_something
306
+ rescue
307
+ foo = 1
318
308
  end
319
309
  end
310
+ END
311
+ end
320
312
 
321
- context 'when it is inside of begin with ensure' do
322
- let(:source) do
323
- <<-END
324
- def some_method(flag)
325
- begin
326
- foo = 1
327
- ensure
328
- do_something
329
- end
330
- end
331
- END
332
- end
313
+ it 'returns the rescue node' do
314
+ expect(assignment.branch_point_node.type).to eq(:rescue)
315
+ end
316
+ end
333
317
 
334
- it 'returns the ensure node' do
335
- expect(assignment.branch_point_node.type).to eq(:ensure)
318
+ context 'when it is inside of begin with ensure' do
319
+ let(:source) do
320
+ <<-END
321
+ def some_method(flag)
322
+ begin
323
+ foo = 1
324
+ ensure
325
+ do_something
336
326
  end
337
327
  end
328
+ END
329
+ end
338
330
 
339
- context 'when it is inside of ensure' do
340
- let(:source) do
341
- <<-END
342
- def some_method(flag)
343
- begin
344
- do_something
345
- ensure
346
- foo = 1
347
- end
348
- end
349
- END
350
- end
331
+ it 'returns the ensure node' do
332
+ expect(assignment.branch_point_node.type).to eq(:ensure)
333
+ end
334
+ end
351
335
 
352
- it 'returns nil' do
353
- expect(assignment.branch_point_node).to be_nil
336
+ context 'when it is inside of ensure' do
337
+ let(:source) do
338
+ <<-END
339
+ def some_method(flag)
340
+ begin
341
+ do_something
342
+ ensure
343
+ foo = 1
354
344
  end
355
345
  end
346
+ END
347
+ end
356
348
 
357
- context 'when it is inside of begin without rescue' do
358
- let(:source) do
359
- <<-END
360
- def some_method(flag)
361
- begin
362
- foo = 1
363
- end
364
- end
365
- END
366
- end
349
+ it 'returns nil' do
350
+ expect(assignment.branch_point_node).to be_nil
351
+ end
352
+ end
367
353
 
368
- it 'returns nil' do
369
- expect(assignment.branch_point_node).to be_nil
354
+ context 'when it is inside of begin without rescue' do
355
+ let(:source) do
356
+ <<-END
357
+ def some_method(flag)
358
+ begin
359
+ foo = 1
370
360
  end
371
361
  end
372
- end
362
+ END
363
+ end
373
364
 
374
- describe '#branch_body_node' do
375
- context 'when it is not in branch' do
376
- let(:source) do
377
- <<-END
378
- def some_method(flag)
379
- foo = 1
380
- end
381
- END
382
- end
365
+ it 'returns nil' do
366
+ expect(assignment.branch_point_node).to be_nil
367
+ end
368
+ end
369
+ end
383
370
 
384
- it 'returns nil' do
385
- expect(assignment.branch_body_node).to be_nil
386
- end
371
+ describe '#branch_body_node' do
372
+ context 'when it is not in branch' do
373
+ let(:source) do
374
+ <<-END
375
+ def some_method(flag)
376
+ foo = 1
387
377
  end
378
+ END
379
+ end
388
380
 
389
- context 'when it is inside body of if' do
390
- let(:source) do
391
- <<-END
392
- def some_method(flag)
393
- if flag
394
- foo = 1
395
- puts foo
396
- end
397
- end
398
- END
399
- end
381
+ it 'returns nil' do
382
+ expect(assignment.branch_body_node).to be_nil
383
+ end
384
+ end
400
385
 
401
- it 'returns the body node' do
402
- expect(assignment.branch_body_node.type).to eq(:begin)
386
+ context 'when it is inside body of if' do
387
+ let(:source) do
388
+ <<-END
389
+ def some_method(flag)
390
+ if flag
391
+ foo = 1
392
+ puts foo
403
393
  end
404
394
  end
395
+ END
396
+ end
405
397
 
406
- context 'when it is inside body of else of if' do
407
- let(:source) do
408
- <<-END
409
- def some_method(flag)
410
- if flag
411
- do_something
412
- else
413
- foo = 1
414
- puts foo
415
- end
416
- end
417
- END
418
- end
398
+ it 'returns the body node' do
399
+ expect(assignment.branch_body_node.type).to eq(:begin)
400
+ end
401
+ end
419
402
 
420
- it 'returns the body node' do
421
- expect(assignment.branch_body_node.type).to eq(:begin)
403
+ context 'when it is inside body of else of if' do
404
+ let(:source) do
405
+ <<-END
406
+ def some_method(flag)
407
+ if flag
408
+ do_something
409
+ else
410
+ foo = 1
411
+ puts foo
422
412
  end
423
413
  end
414
+ END
415
+ end
424
416
 
425
- context 'when it is on the right side of &&' do
426
- let(:source) do
427
- <<-END
428
- def some_method
429
- do_something && (foo = 1)
430
- end
431
- END
432
- end
417
+ it 'returns the body node' do
418
+ expect(assignment.branch_body_node.type).to eq(:begin)
419
+ end
420
+ end
433
421
 
434
- it 'returns the right side node' do
435
- expect(assignment.branch_body_node.type).to eq(:begin)
436
- end
422
+ context 'when it is on the right side of &&' do
423
+ let(:source) do
424
+ <<-END
425
+ def some_method
426
+ do_something && (foo = 1)
437
427
  end
428
+ END
429
+ end
438
430
 
439
- context 'when it is on the right side of ||' do
440
- let(:source) do
441
- <<-END
442
- def some_method
443
- do_something || (foo = 1)
444
- end
445
- END
446
- end
431
+ it 'returns the right side node' do
432
+ expect(assignment.branch_body_node.type).to eq(:begin)
433
+ end
434
+ end
447
435
 
448
- it 'returns the right side node' do
449
- expect(assignment.branch_body_node.type).to eq(:begin)
450
- end
436
+ context 'when it is on the right side of ||' do
437
+ let(:source) do
438
+ <<-END
439
+ def some_method
440
+ do_something || (foo = 1)
451
441
  end
442
+ END
443
+ end
452
444
 
453
- context 'when it is inside of begin with rescue' do
454
- let(:source) do
455
- <<-END
456
- def some_method(flag)
457
- begin
458
- foo = 1
459
- rescue
460
- do_something
461
- end
462
- end
463
- END
464
- end
445
+ it 'returns the right side node' do
446
+ expect(assignment.branch_body_node.type).to eq(:begin)
447
+ end
448
+ end
465
449
 
466
- it 'returns the body node' do
467
- expect(assignment.branch_body_node.type).to eq(:lvasgn)
450
+ context 'when it is inside of begin with rescue' do
451
+ let(:source) do
452
+ <<-END
453
+ def some_method(flag)
454
+ begin
455
+ foo = 1
456
+ rescue
457
+ do_something
468
458
  end
469
459
  end
460
+ END
461
+ end
470
462
 
471
- context 'when it is inside of rescue' do
472
- let(:source) do
473
- <<-END
474
- def some_method(flag)
475
- begin
476
- do_something
477
- rescue
478
- foo = 1
479
- end
480
- end
481
- END
482
- end
463
+ it 'returns the body node' do
464
+ expect(assignment.branch_body_node.type).to eq(:lvasgn)
465
+ end
466
+ end
483
467
 
484
- it 'returns the resbody node' do
485
- expect(assignment.branch_body_node.type).to eq(:resbody)
468
+ context 'when it is inside of rescue' do
469
+ let(:source) do
470
+ <<-END
471
+ def some_method(flag)
472
+ begin
473
+ do_something
474
+ rescue
475
+ foo = 1
486
476
  end
487
477
  end
478
+ END
479
+ end
488
480
 
489
- context 'when it is inside of begin with ensure' do
490
- let(:source) do
491
- <<-END
492
- def some_method(flag)
493
- begin
494
- foo = 1
495
- ensure
496
- do_something
497
- end
498
- end
499
- END
500
- end
481
+ it 'returns the resbody node' do
482
+ expect(assignment.branch_body_node.type).to eq(:resbody)
483
+ end
484
+ end
501
485
 
502
- it 'returns the body node' do
503
- expect(assignment.branch_body_node.type).to eq(:lvasgn)
486
+ context 'when it is inside of begin with ensure' do
487
+ let(:source) do
488
+ <<-END
489
+ def some_method(flag)
490
+ begin
491
+ foo = 1
492
+ ensure
493
+ do_something
504
494
  end
505
495
  end
506
- end
496
+ END
497
+ end
507
498
 
508
- describe '#branch_id' do
509
- context 'when it is not in branch' do
510
- let(:source) do
511
- <<-END
512
- def some_method(flag)
513
- foo = 1
514
- end
515
- END
516
- end
499
+ it 'returns the body node' do
500
+ expect(assignment.branch_body_node.type).to eq(:lvasgn)
501
+ end
502
+ end
503
+ end
517
504
 
518
- it 'returns nil' do
519
- expect(assignment.branch_id).to be_nil
520
- end
505
+ describe '#branch_id' do
506
+ context 'when it is not in branch' do
507
+ let(:source) do
508
+ <<-END
509
+ def some_method(flag)
510
+ foo = 1
521
511
  end
512
+ END
513
+ end
522
514
 
523
- context 'when it is inside body of if' do
524
- let(:source) do
525
- <<-END
526
- def some_method(flag)
527
- if flag
528
- foo = 1
529
- puts foo
530
- end
531
- end
532
- END
533
- end
515
+ it 'returns nil' do
516
+ expect(assignment.branch_id).to be_nil
517
+ end
518
+ end
534
519
 
535
- it 'returns BRANCHNODEID_if_true' do
536
- expect(assignment.branch_id).to match(/^\d+_if_true/)
520
+ context 'when it is inside body of if' do
521
+ let(:source) do
522
+ <<-END
523
+ def some_method(flag)
524
+ if flag
525
+ foo = 1
526
+ puts foo
537
527
  end
538
528
  end
529
+ END
530
+ end
539
531
 
540
- context 'when it is inside body of else of if' do
541
- let(:source) do
542
- <<-END
543
- def some_method(flag)
544
- if flag
545
- do_something
546
- else
547
- foo = 1
548
- puts foo
549
- end
550
- end
551
- END
552
- end
532
+ it 'returns BRANCHNODEID_if_true' do
533
+ expect(assignment.branch_id).to match(/^\d+_if_true/)
534
+ end
535
+ end
553
536
 
554
- it 'returns BRANCHNODEID_if_false' do
555
- expect(assignment.branch_id).to match(/^\d+_if_false/)
537
+ context 'when it is inside body of else of if' do
538
+ let(:source) do
539
+ <<-END
540
+ def some_method(flag)
541
+ if flag
542
+ do_something
543
+ else
544
+ foo = 1
545
+ puts foo
556
546
  end
557
547
  end
548
+ END
549
+ end
558
550
 
559
- context 'when it is inside body of when of case' do
560
- let(:source) do
561
- <<-END
562
- def some_method(flag)
563
- case flag
564
- when first
565
- do_something
566
- when second
567
- foo = 1
568
- puts foo
569
- else
570
- do_something
571
- end
572
- end
573
- END
574
- end
551
+ it 'returns BRANCHNODEID_if_false' do
552
+ expect(assignment.branch_id).to match(/^\d+_if_false/)
553
+ end
554
+ end
575
555
 
576
- it 'returns BRANCHNODEID_case_whenINDEX' do
577
- expect(assignment.branch_id).to match(/^\d+_case_when1/)
578
- end
579
- end
556
+ context 'when it is inside body of when of case' do
557
+ let(:source) do
558
+ <<-END
559
+ def some_method(flag)
560
+ case flag
561
+ when first
562
+ do_something
563
+ when second
564
+ foo = 1
565
+ puts foo
566
+ else
567
+ do_something
568
+ end
569
+ end
570
+ END
571
+ end
580
572
 
581
- context 'when it is inside body of when of case' do
582
- let(:source) do
583
- <<-END
584
- def some_method(flag)
585
- case flag
586
- when first
587
- do_something
588
- when second
589
- do_something
590
- else
591
- foo = 1
592
- puts foo
593
- end
594
- end
595
- END
596
- end
573
+ it 'returns BRANCHNODEID_case_whenINDEX' do
574
+ expect(assignment.branch_id).to match(/^\d+_case_when1/)
575
+ end
576
+ end
597
577
 
598
- it 'returns BRANCHNODEID_case_else' do
599
- expect(assignment.branch_id).to match(/^\d+_case_else/)
600
- end
601
- end
578
+ context 'when it is inside body of when of case' do
579
+ let(:source) do
580
+ <<-END
581
+ def some_method(flag)
582
+ case flag
583
+ when first
584
+ do_something
585
+ when second
586
+ do_something
587
+ else
588
+ foo = 1
589
+ puts foo
590
+ end
591
+ end
592
+ END
593
+ end
602
594
 
603
- context 'when it is on the left side of &&' do
604
- let(:source) do
605
- <<-END
606
- def some_method
607
- (foo = 1) && do_something
608
- end
609
- END
610
- end
595
+ it 'returns BRANCHNODEID_case_else' do
596
+ expect(assignment.branch_id).to match(/^\d+_case_else/)
597
+ end
598
+ end
611
599
 
612
- it 'returns nil' do
613
- expect(assignment.branch_id).to be_nil
614
- end
600
+ context 'when it is on the left side of &&' do
601
+ let(:source) do
602
+ <<-END
603
+ def some_method
604
+ (foo = 1) && do_something
615
605
  end
606
+ END
607
+ end
616
608
 
617
- context 'when it is on the right side of &&' do
618
- let(:source) do
619
- <<-END
620
- def some_method
621
- do_something && (foo = 1)
622
- end
623
- END
624
- end
609
+ it 'returns nil' do
610
+ expect(assignment.branch_id).to be_nil
611
+ end
612
+ end
625
613
 
626
- it 'returns BRANCHNODEID_and_right' do
627
- expect(assignment.branch_id).to match(/^\d+_and_right/)
628
- end
614
+ context 'when it is on the right side of &&' do
615
+ let(:source) do
616
+ <<-END
617
+ def some_method
618
+ do_something && (foo = 1)
629
619
  end
620
+ END
621
+ end
630
622
 
631
- context 'when it is on the left side of ||' do
632
- let(:source) do
633
- <<-END
634
- def some_method
635
- (foo = 1) || do_something
636
- end
637
- END
638
- end
623
+ it 'returns BRANCHNODEID_and_right' do
624
+ expect(assignment.branch_id).to match(/^\d+_and_right/)
625
+ end
626
+ end
639
627
 
640
- it 'returns nil' do
641
- expect(assignment.branch_id).to be_nil
642
- end
628
+ context 'when it is on the left side of ||' do
629
+ let(:source) do
630
+ <<-END
631
+ def some_method
632
+ (foo = 1) || do_something
643
633
  end
634
+ END
635
+ end
644
636
 
645
- context 'when it is on the right side of ||' do
646
- let(:source) do
647
- <<-END
648
- def some_method
649
- do_something || (foo = 1)
650
- end
651
- END
652
- end
637
+ it 'returns nil' do
638
+ expect(assignment.branch_id).to be_nil
639
+ end
640
+ end
653
641
 
654
- it 'returns BRANCHNODEID_or_right' do
655
- expect(assignment.branch_id).to match(/^\d+_or_right/)
656
- end
642
+ context 'when it is on the right side of ||' do
643
+ let(:source) do
644
+ <<-END
645
+ def some_method
646
+ do_something || (foo = 1)
657
647
  end
648
+ END
649
+ end
658
650
 
659
- context 'when it is inside of begin with rescue' do
660
- let(:source) do
661
- <<-END
662
- def some_method(flag)
663
- begin
664
- foo = 1
665
- rescue
666
- do_something
667
- end
668
- end
669
- END
670
- end
651
+ it 'returns BRANCHNODEID_or_right' do
652
+ expect(assignment.branch_id).to match(/^\d+_or_right/)
653
+ end
654
+ end
671
655
 
672
- it 'returns BRANCHNODEID_rescue_main' do
673
- expect(assignment.branch_id).to match(/^\d+_rescue_main/)
656
+ context 'when it is inside of begin with rescue' do
657
+ let(:source) do
658
+ <<-END
659
+ def some_method(flag)
660
+ begin
661
+ foo = 1
662
+ rescue
663
+ do_something
674
664
  end
675
665
  end
666
+ END
667
+ end
676
668
 
677
- context 'when it is inside of rescue' do
678
- let(:source) do
679
- <<-END
680
- def some_method(flag)
681
- begin
682
- do_something
683
- rescue FirstError
684
- do_something
685
- rescue SecondError
686
- foo = 1
687
- end
688
- end
689
- END
690
- end
669
+ it 'returns BRANCHNODEID_rescue_main' do
670
+ expect(assignment.branch_id).to match(/^\d+_rescue_main/)
671
+ end
672
+ end
691
673
 
692
- it 'returns BRANCHNODEID_rescue_rescueINDEX' do
693
- expect(assignment.branch_id).to match(/^\d+_rescue_rescue1/)
674
+ context 'when it is inside of rescue' do
675
+ let(:source) do
676
+ <<-END
677
+ def some_method(flag)
678
+ begin
679
+ do_something
680
+ rescue FirstError
681
+ do_something
682
+ rescue SecondError
683
+ foo = 1
694
684
  end
695
685
  end
686
+ END
687
+ end
696
688
 
697
- context 'when it is inside of else of rescue' do
698
- let(:source) do
699
- <<-END
700
- def some_method(flag)
701
- begin
702
- do_something
703
- rescue FirstError
704
- do_something
705
- rescue SecondError
706
- do_something
707
- else
708
- foo = 1
709
- end
710
- end
711
- END
712
- end
689
+ it 'returns BRANCHNODEID_rescue_rescueINDEX' do
690
+ expect(assignment.branch_id).to match(/^\d+_rescue_rescue1/)
691
+ end
692
+ end
713
693
 
714
- it 'returns BRANCHNODEID_rescue_else' do
715
- expect(assignment.branch_id).to match(/^\d+_rescue_else/)
716
- end
717
- end
694
+ context 'when it is inside of else of rescue' do
695
+ let(:source) do
696
+ <<-END
697
+ def some_method(flag)
698
+ begin
699
+ do_something
700
+ rescue FirstError
701
+ do_something
702
+ rescue SecondError
703
+ do_something
704
+ else
705
+ foo = 1
706
+ end
707
+ end
708
+ END
709
+ end
718
710
 
719
- context 'when it is inside of begin with ensure' do
720
- let(:source) do
721
- <<-END
722
- def some_method(flag)
723
- begin
724
- foo = 1
725
- ensure
726
- do_something
727
- end
728
- end
729
- END
730
- end
711
+ it 'returns BRANCHNODEID_rescue_else' do
712
+ expect(assignment.branch_id).to match(/^\d+_rescue_else/)
713
+ end
714
+ end
731
715
 
732
- it 'returns BRANCHNODEID_ensure_main' do
733
- expect(assignment.branch_id).to match(/^\d+_ensure_main/)
716
+ context 'when it is inside of begin with ensure' do
717
+ let(:source) do
718
+ <<-END
719
+ def some_method(flag)
720
+ begin
721
+ foo = 1
722
+ ensure
723
+ do_something
734
724
  end
735
725
  end
736
- end
726
+ END
727
+ end
728
+
729
+ it 'returns BRANCHNODEID_ensure_main' do
730
+ expect(assignment.branch_id).to match(/^\d+_ensure_main/)
737
731
  end
738
732
  end
739
733
  end