metric_fu-roodi 2.2.2 → 3.0.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.
- checksums.yaml +7 -0
- data/bin/metric_fu-roodi +2 -19
- data/bin/metric_fu-roodi-describe +2 -5
- data/lib/roodi.rb +6 -2
- data/lib/roodi/version.rb +1 -1
- metadata +13 -119
- data/.gitignore +0 -3
- data/.rspec +0 -2
- data/Gemfile +0 -6
- data/History.txt +0 -111
- data/Manifest.txt +0 -56
- data/README.txt +0 -98
- data/Rakefile +0 -31
- data/TODO.md +0 -3
- data/lib/roodi/checks.rb +0 -18
- data/lib/roodi/checks/abc_metric_method_check.rb +0 -79
- data/lib/roodi/checks/assignment_in_conditional_check.rb +0 -32
- data/lib/roodi/checks/case_missing_else_check.rb +0 -20
- data/lib/roodi/checks/check.rb +0 -76
- data/lib/roodi/checks/class_line_count_check.rb +0 -28
- data/lib/roodi/checks/class_name_check.rb +0 -31
- data/lib/roodi/checks/class_variable_check.rb +0 -24
- data/lib/roodi/checks/control_coupling_check.rb +0 -20
- data/lib/roodi/checks/cyclomatic_complexity_block_check.rb +0 -41
- data/lib/roodi/checks/cyclomatic_complexity_check.rb +0 -50
- data/lib/roodi/checks/cyclomatic_complexity_method_check.rb +0 -42
- data/lib/roodi/checks/empty_rescue_body_check.rb +0 -32
- data/lib/roodi/checks/for_loop_check.rb +0 -20
- data/lib/roodi/checks/line_count_check.rb +0 -28
- data/lib/roodi/checks/method_line_count_check.rb +0 -29
- data/lib/roodi/checks/method_name_check.rb +0 -31
- data/lib/roodi/checks/missing_foreign_key_index_check.rb +0 -99
- data/lib/roodi/checks/module_line_count_check.rb +0 -28
- data/lib/roodi/checks/module_name_check.rb +0 -31
- data/lib/roodi/checks/name_check.rb +0 -16
- data/lib/roodi/checks/npath_complexity_check.rb +0 -75
- data/lib/roodi/checks/npath_complexity_method_check.rb +0 -29
- data/lib/roodi/checks/parameter_number_check.rb +0 -34
- data/lib/roodi/core.rb +0 -1
- data/lib/roodi/core/checking_visitor.rb +0 -26
- data/lib/roodi/core/error.rb +0 -17
- data/lib/roodi/core/parser.rb +0 -48
- data/lib/roodi/core/runner.rb +0 -81
- data/lib/roodi/core/visitable_sexp.rb +0 -25
- data/lib/roodi_task.rb +0 -35
- data/roodi.gemspec +0 -26
- data/roodi.yml +0 -25
- data/spec/roodi/checks/abc_metric_method_check_spec.rb +0 -89
- data/spec/roodi/checks/assignment_in_conditional_check_spec.rb +0 -105
- data/spec/roodi/checks/case_missing_else_check_spec.rb +0 -32
- data/spec/roodi/checks/class_line_count_check_spec.rb +0 -39
- data/spec/roodi/checks/class_name_check_spec.rb +0 -39
- data/spec/roodi/checks/class_variable_check_spec.rb +0 -17
- data/spec/roodi/checks/control_coupling_check_spec.rb +0 -23
- data/spec/roodi/checks/cyclomatic_complexity_block_check_spec.rb +0 -67
- data/spec/roodi/checks/cyclomatic_complexity_method_check_spec.rb +0 -200
- data/spec/roodi/checks/empty_rescue_body_check_spec.rb +0 -154
- data/spec/roodi/checks/for_loop_check_spec.rb +0 -18
- data/spec/roodi/checks/method_line_count_check_spec.rb +0 -56
- data/spec/roodi/checks/method_name_check_spec.rb +0 -76
- data/spec/roodi/checks/missing_foreign_key_index_check_spec.rb +0 -33
- data/spec/roodi/checks/module_line_count_check_spec.rb +0 -39
- data/spec/roodi/checks/module_name_check_spec.rb +0 -27
- data/spec/roodi/checks/npath_complexity_method_check_spec.rb +0 -53
- data/spec/roodi/checks/parameter_number_check_spec.rb +0 -47
- data/spec/roodi/core/runner_spec.rb +0 -25
- data/spec/roodi/roodi.yml +0 -2
- data/spec/spec_helper.rb +0 -3
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Roodi::Checks::CaseMissingElseCheck do
|
4
|
-
before(:each) do
|
5
|
-
@roodi = Roodi::Core::Runner.new(Roodi::Checks::CaseMissingElseCheck.make)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should accept case statements that do have an else" do
|
9
|
-
content = <<-END
|
10
|
-
case foo
|
11
|
-
when "bar": "ok"
|
12
|
-
else "good"
|
13
|
-
end
|
14
|
-
END
|
15
|
-
@roodi.check_content(content)
|
16
|
-
errors = @roodi.errors
|
17
|
-
errors.should be_empty
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should reject case statements that do have an else" do
|
21
|
-
content = <<-END
|
22
|
-
case foo
|
23
|
-
when "bar": "ok"
|
24
|
-
when "bar": "bad"
|
25
|
-
end
|
26
|
-
END
|
27
|
-
@roodi.check_content(content)
|
28
|
-
errors = @roodi.errors
|
29
|
-
errors.should_not be_empty
|
30
|
-
errors[0].to_s.should match(/dummy-file.rb:[1-2] - Case statement is missing an else clause./)
|
31
|
-
end
|
32
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Roodi::Checks::ClassLineCountCheck do
|
4
|
-
before(:each) do
|
5
|
-
@roodi = Roodi::Core::Runner.new(Roodi::Checks::ClassLineCountCheck.make({'line_count' => 1}))
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should accept classes with less lines than the threshold" do
|
9
|
-
content = <<-END
|
10
|
-
class ZeroLineClass
|
11
|
-
end
|
12
|
-
END
|
13
|
-
@roodi.check_content(content)
|
14
|
-
@roodi.errors.should be_empty
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should accept classes with the same number of lines as the threshold" do
|
18
|
-
content = <<-END
|
19
|
-
Class OneLineClass
|
20
|
-
@foo = 1
|
21
|
-
end
|
22
|
-
END
|
23
|
-
@roodi.check_content(content)
|
24
|
-
@roodi.errors.should be_empty
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should reject classes with more lines than the threshold" do
|
28
|
-
content = <<-END
|
29
|
-
class TwoLineClass
|
30
|
-
@foo = 1
|
31
|
-
@bar = 2
|
32
|
-
end
|
33
|
-
END
|
34
|
-
@roodi.check_content(content)
|
35
|
-
errors = @roodi.errors
|
36
|
-
errors.should_not be_empty
|
37
|
-
errors[0].to_s.should eql("dummy-file.rb:1 - Class \"TwoLineClass\" has 2 lines. It should have 1 or less.")
|
38
|
-
end
|
39
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Roodi::Checks::ClassNameCheck do
|
4
|
-
before(:each) do
|
5
|
-
@roodi = Roodi::Core::Runner.new(Roodi::Checks::ClassNameCheck.make)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should accept camel case class names starting in capitals" do
|
9
|
-
content = <<-END
|
10
|
-
class GoodClassName
|
11
|
-
end
|
12
|
-
END
|
13
|
-
@roodi.check_content(content)
|
14
|
-
@roodi.errors.should be_empty
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should be able to parse scoped class names" do
|
18
|
-
content = <<-END
|
19
|
-
class MyScope::GoodClassName
|
20
|
-
def method
|
21
|
-
end
|
22
|
-
end
|
23
|
-
END
|
24
|
-
# @roodi.print_content(content)
|
25
|
-
@roodi.check_content(content)
|
26
|
-
@roodi.errors.should be_empty
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should reject class names with underscores" do
|
30
|
-
content = <<-END
|
31
|
-
class Bad_ClassName
|
32
|
-
end
|
33
|
-
END
|
34
|
-
@roodi.check_content(content)
|
35
|
-
errors = @roodi.errors
|
36
|
-
errors.should_not be_empty
|
37
|
-
errors[0].to_s.should eql("dummy-file.rb:1 - Class name \"Bad_ClassName\" should match pattern /^[A-Z][a-zA-Z0-9]*$/")
|
38
|
-
end
|
39
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Roodi::Checks::ClassVariableCheck do
|
4
|
-
before(:each) do
|
5
|
-
@roodi = Roodi::Core::Runner.new(Roodi::Checks::ClassVariableCheck.make)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should reject class variables" do
|
9
|
-
content = <<-END
|
10
|
-
@@foo
|
11
|
-
END
|
12
|
-
@roodi.check_content(content)
|
13
|
-
errors = @roodi.errors
|
14
|
-
errors.should_not be_empty
|
15
|
-
errors[0].to_s.should match(/dummy-file.rb:[1-2] - Don't use class variables. You might want to try a different design./)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Roodi::Checks::ControlCouplingCheck do
|
4
|
-
before(:each) do
|
5
|
-
@roodi = Roodi::Core::Runner.new(Roodi::Checks::ControlCouplingCheck.make)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should reject methods with if checks using a parameter" do
|
9
|
-
content = <<-END
|
10
|
-
def write(quoted, foo)
|
11
|
-
if quoted
|
12
|
-
write_quoted(@value)
|
13
|
-
else
|
14
|
-
puts @value
|
15
|
-
end
|
16
|
-
end
|
17
|
-
END
|
18
|
-
@roodi.check_content(content)
|
19
|
-
errors = @roodi.errors
|
20
|
-
errors.should_not be_empty
|
21
|
-
errors[0].to_s.should match(/dummy-file.rb:[2-3] - Method \"write\" uses the argument \"quoted\" for internal control./)
|
22
|
-
end
|
23
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Roodi::Checks::CyclomaticComplexityBlockCheck do
|
4
|
-
before(:each) do
|
5
|
-
@roodi = Roodi::Core::Runner.new(Roodi::Checks::CyclomaticComplexityBlockCheck.make({'complexity' => 0}))
|
6
|
-
end
|
7
|
-
|
8
|
-
def verify_content_complexity(content, complexity)
|
9
|
-
@roodi.check_content(content)
|
10
|
-
errors = @roodi.errors
|
11
|
-
errors.should_not be_empty
|
12
|
-
errors[0].to_s.should match(/dummy-file.rb:[2-4] - Block cyclomatic complexity is #{complexity}. It should be 0 or less./)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should find a simple block" do
|
16
|
-
content = <<-END
|
17
|
-
def method_name
|
18
|
-
it "should be a simple block" do
|
19
|
-
call_foo
|
20
|
-
end
|
21
|
-
end
|
22
|
-
END
|
23
|
-
verify_content_complexity(content, 1)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should find a block with multiple paths" do
|
27
|
-
content = <<-END
|
28
|
-
def method_name
|
29
|
-
it "should be a complex block" do
|
30
|
-
call_foo if some_condition
|
31
|
-
end
|
32
|
-
end
|
33
|
-
END
|
34
|
-
verify_content_complexity(content, 2)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should evaluate real example 1 correctly" do
|
38
|
-
content = <<-END
|
39
|
-
def method_name
|
40
|
-
UNIXMbox.lock(@filename) {|f|
|
41
|
-
begin
|
42
|
-
f.each do |line|
|
43
|
-
if /\AFrom / === line
|
44
|
-
w.close if w
|
45
|
-
File.utime time, time, port.filename if time
|
46
|
-
|
47
|
-
port = @real.new_port
|
48
|
-
w = port.wopen
|
49
|
-
time = fromline2time(line)
|
50
|
-
else
|
51
|
-
w.print line if w
|
52
|
-
end
|
53
|
-
end
|
54
|
-
ensure
|
55
|
-
if w and not w.closed?
|
56
|
-
w.close
|
57
|
-
File.utime time, time, port.filename if time
|
58
|
-
end
|
59
|
-
end
|
60
|
-
f.truncate(0) unless @readonly
|
61
|
-
@updated = Time.now
|
62
|
-
}
|
63
|
-
end
|
64
|
-
END
|
65
|
-
verify_content_complexity(content, 9)
|
66
|
-
end
|
67
|
-
end
|
@@ -1,200 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Roodi::Checks::CyclomaticComplexityMethodCheck do
|
4
|
-
before(:each) do
|
5
|
-
@roodi = Roodi::Core::Runner.new(Roodi::Checks::CyclomaticComplexityMethodCheck.make({'complexity' => 0}))
|
6
|
-
end
|
7
|
-
|
8
|
-
def verify_content_complexity(content, complexity)
|
9
|
-
@roodi.check_content(content)
|
10
|
-
errors = @roodi.errors
|
11
|
-
errors.should_not be_empty
|
12
|
-
errors[0].to_s.should eql("dummy-file.rb:1 - Method name \"method_name\" cyclomatic complexity is #{complexity}. It should be 0 or less.")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should find an if block" do
|
16
|
-
content = <<-END
|
17
|
-
def method_name
|
18
|
-
call_foo if some_condition
|
19
|
-
end
|
20
|
-
END
|
21
|
-
verify_content_complexity(content, 2)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should find an unless block" do
|
25
|
-
content = <<-END
|
26
|
-
def method_name
|
27
|
-
call_foo unless some_condition
|
28
|
-
end
|
29
|
-
END
|
30
|
-
verify_content_complexity(content, 2)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should find an elsif block" do
|
34
|
-
content = <<-END
|
35
|
-
def method_name
|
36
|
-
if first_condition then
|
37
|
-
call_foo
|
38
|
-
elsif second_condition then
|
39
|
-
call_bar
|
40
|
-
else
|
41
|
-
call_bam
|
42
|
-
end
|
43
|
-
end
|
44
|
-
END
|
45
|
-
verify_content_complexity(content, 3)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should find a ternary operator" do
|
49
|
-
content = <<-END
|
50
|
-
def method_name
|
51
|
-
value = some_condition ? 1 : 2
|
52
|
-
end
|
53
|
-
END
|
54
|
-
verify_content_complexity(content, 2)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should find a while loop" do
|
58
|
-
content = <<-END
|
59
|
-
def method_name
|
60
|
-
while some_condition do
|
61
|
-
call_foo
|
62
|
-
end
|
63
|
-
end
|
64
|
-
END
|
65
|
-
verify_content_complexity(content, 2)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should find an until loop" do
|
69
|
-
content = <<-END
|
70
|
-
def method_name
|
71
|
-
until some_condition do
|
72
|
-
call_foo
|
73
|
-
end
|
74
|
-
end
|
75
|
-
END
|
76
|
-
verify_content_complexity(content, 2)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should find a for loop" do
|
80
|
-
content = <<-END
|
81
|
-
def method_name
|
82
|
-
for i in 1..2 do
|
83
|
-
call_method
|
84
|
-
end
|
85
|
-
end
|
86
|
-
END
|
87
|
-
verify_content_complexity(content, 2)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should find a rescue block" do
|
91
|
-
content = <<-END
|
92
|
-
def method_name
|
93
|
-
begin
|
94
|
-
call_foo
|
95
|
-
rescue Exception
|
96
|
-
call_bar
|
97
|
-
end
|
98
|
-
end
|
99
|
-
END
|
100
|
-
verify_content_complexity(content, 2)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should find a case and when block" do
|
104
|
-
content = <<-END
|
105
|
-
def method_name
|
106
|
-
case value
|
107
|
-
when 1
|
108
|
-
call_foo
|
109
|
-
when 2
|
110
|
-
call_bar
|
111
|
-
end
|
112
|
-
end
|
113
|
-
END
|
114
|
-
verify_content_complexity(content, 4)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should find the && symbol" do
|
118
|
-
content = <<-END
|
119
|
-
def method_name
|
120
|
-
call_foo && call_bar
|
121
|
-
end
|
122
|
-
END
|
123
|
-
verify_content_complexity(content, 2)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should find the and symbol" do
|
127
|
-
content = <<-END
|
128
|
-
def method_name
|
129
|
-
call_foo and call_bar
|
130
|
-
end
|
131
|
-
END
|
132
|
-
verify_content_complexity(content, 2)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should find the || symbol" do
|
136
|
-
content = <<-END
|
137
|
-
def method_name
|
138
|
-
call_foo || call_bar
|
139
|
-
end
|
140
|
-
END
|
141
|
-
verify_content_complexity(content, 2)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should find the or symbol" do
|
145
|
-
content = <<-END
|
146
|
-
def method_name
|
147
|
-
call_foo or call_bar
|
148
|
-
end
|
149
|
-
END
|
150
|
-
verify_content_complexity(content, 2)
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should deal with nested if blocks containing && and ||" do
|
154
|
-
content = <<-END
|
155
|
-
def method_name
|
156
|
-
if first_condition then
|
157
|
-
call_foo if second_condition && third_condition
|
158
|
-
call_bar if fourth_condition || fifth_condition
|
159
|
-
end
|
160
|
-
end
|
161
|
-
END
|
162
|
-
verify_content_complexity(content, 6)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should count stupid nested if and else blocks" do
|
166
|
-
content = <<-END
|
167
|
-
def method_name
|
168
|
-
if first_condition then
|
169
|
-
call_foo
|
170
|
-
else
|
171
|
-
if second_condition then
|
172
|
-
call_bar
|
173
|
-
else
|
174
|
-
call_bam if third_condition
|
175
|
-
end
|
176
|
-
call_baz if fourth_condition
|
177
|
-
end
|
178
|
-
end
|
179
|
-
END
|
180
|
-
verify_content_complexity(content, 5)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should count only a single method" do
|
184
|
-
content = <<-END
|
185
|
-
def method_name_1
|
186
|
-
call_foo if some_condition
|
187
|
-
end
|
188
|
-
def method_name_2
|
189
|
-
call_foo if some_condition
|
190
|
-
end
|
191
|
-
END
|
192
|
-
|
193
|
-
@roodi.check_content(content)
|
194
|
-
errors = @roodi.errors
|
195
|
-
errors.should_not be_empty
|
196
|
-
errors[0].to_s.should eql("dummy-file.rb:1 - Method name \"method_name_1\" cyclomatic complexity is 2. It should be 0 or less.")
|
197
|
-
errors[1].to_s.should eql("dummy-file.rb:4 - Method name \"method_name_2\" cyclomatic complexity is 2. It should be 0 or less.")
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
@@ -1,154 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Roodi::Checks::EmptyRescueBodyCheck do
|
4
|
-
before(:each) do
|
5
|
-
@roodi = Roodi::Core::Runner.new(Roodi::Checks::EmptyRescueBodyCheck.make)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should accept a rescue body with content and no parameter" do
|
9
|
-
content = <<-END
|
10
|
-
begin
|
11
|
-
call_method
|
12
|
-
rescue
|
13
|
-
puts "Recover from the call"
|
14
|
-
end
|
15
|
-
END
|
16
|
-
@roodi.check_content(content)
|
17
|
-
@roodi.errors.should be_empty
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should accept a rescue body with a return" do
|
21
|
-
content = <<-END
|
22
|
-
begin
|
23
|
-
call_method
|
24
|
-
rescue
|
25
|
-
return true
|
26
|
-
end
|
27
|
-
END
|
28
|
-
@roodi.check_content(content)
|
29
|
-
@roodi.errors.should be_empty
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should accept a method call that Ruby won't tell apart from a variable (a vcall)" do
|
33
|
-
content = <<-END
|
34
|
-
begin
|
35
|
-
call_method
|
36
|
-
rescue
|
37
|
-
show_error
|
38
|
-
end
|
39
|
-
END
|
40
|
-
@roodi.check_content(content)
|
41
|
-
@roodi.errors.should be_empty
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should accept a rescue body with content and a parameter" do
|
45
|
-
content = <<-END
|
46
|
-
begin
|
47
|
-
call_method
|
48
|
-
rescue Exception => e
|
49
|
-
puts "Recover from the call"
|
50
|
-
end
|
51
|
-
END
|
52
|
-
@roodi.check_content(content)
|
53
|
-
@roodi.errors.should be_empty
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should accept a rescue body with an assignment" do
|
57
|
-
content = <<-END
|
58
|
-
begin
|
59
|
-
call_method
|
60
|
-
rescue Exception => e
|
61
|
-
my_var = 1
|
62
|
-
end
|
63
|
-
END
|
64
|
-
@roodi.check_content(content)
|
65
|
-
@roodi.errors.should be_empty
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should accept a rescue body with an attribute assignment" do
|
69
|
-
content = <<-END
|
70
|
-
begin
|
71
|
-
call_method
|
72
|
-
rescue Exception => e
|
73
|
-
self.var = 1
|
74
|
-
end
|
75
|
-
END
|
76
|
-
@roodi.check_content(content)
|
77
|
-
@roodi.errors.should be_empty
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should reject an empty rescue block with no parameter" do
|
81
|
-
content = <<-END
|
82
|
-
begin
|
83
|
-
call_method
|
84
|
-
rescue
|
85
|
-
end
|
86
|
-
END
|
87
|
-
@roodi.check_content(content)
|
88
|
-
errors = @roodi.errors
|
89
|
-
errors.should_not be_empty
|
90
|
-
errors[0].to_s.should match(/dummy-file.rb:[3-4] - Rescue block should not be empty./)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should accept a rescue block with an explicit nil" do
|
94
|
-
content = <<-END
|
95
|
-
call_method rescue nil
|
96
|
-
END
|
97
|
-
@roodi.check_content(content)
|
98
|
-
errors = @roodi.errors
|
99
|
-
errors.should be_empty
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should reject an empty rescue block with a parameter" do
|
103
|
-
content = <<-END
|
104
|
-
begin
|
105
|
-
call_method
|
106
|
-
rescue Exception => e
|
107
|
-
end
|
108
|
-
END
|
109
|
-
@roodi.check_content(content)
|
110
|
-
errors = @roodi.errors
|
111
|
-
errors.should_not be_empty
|
112
|
-
errors[0].to_s.should match(/dummy-file.rb:[3-4] - Rescue block should not be empty./)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should accept a rescue block that returns true" do
|
116
|
-
content = <<-END
|
117
|
-
begin
|
118
|
-
call_method
|
119
|
-
rescue Exception => e
|
120
|
-
true
|
121
|
-
end
|
122
|
-
END
|
123
|
-
@roodi.check_content(content)
|
124
|
-
errors = @roodi.errors
|
125
|
-
errors.should be_empty
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should accept a rescue block that returns false" do
|
129
|
-
content = <<-END
|
130
|
-
begin
|
131
|
-
call_method
|
132
|
-
rescue Exception => e
|
133
|
-
false
|
134
|
-
end
|
135
|
-
END
|
136
|
-
@roodi.check_content(content)
|
137
|
-
errors = @roodi.errors
|
138
|
-
errors.should be_empty
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should accept a rescue block that has only a next statement" do
|
142
|
-
content = <<-END
|
143
|
-
begin
|
144
|
-
call_method
|
145
|
-
rescue Exception => e
|
146
|
-
next
|
147
|
-
end
|
148
|
-
END
|
149
|
-
@roodi.check_content(content)
|
150
|
-
errors = @roodi.errors
|
151
|
-
errors.should be_empty
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|