cane 2.5.1 → 2.5.2
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.
- data/HISTORY.md +4 -0
- data/README.md +31 -27
- data/lib/cane/threshold_check.rb +18 -9
- data/lib/cane/version.rb +1 -1
- data/spec/parser_spec.rb +21 -1
- data/spec/spec_helper.rb +15 -0
- data/spec/threshold_check_spec.rb +48 -12
- metadata +1 -1
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -34,33 +34,37 @@ Customize behaviour with a wealth of options:
|
|
34
34
|
|
35
35
|
Default options are loaded from a .cane file in the current directory.
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
-
|
63
|
-
|
37
|
+
-r, --require FILE Load a Ruby file containing user-defined checks
|
38
|
+
-c, --check CLASS Use the given user-defined check
|
39
|
+
|
40
|
+
--abc-glob GLOB Glob to run ABC metrics over (default: {app,lib}/**/*.rb)
|
41
|
+
--abc-max VALUE Ignore methods under this complexity (default: 15)
|
42
|
+
--abc-exclude METHOD Exclude method from analysis (eg. Foo::Bar#method)
|
43
|
+
--no-abc Disable ABC checking
|
44
|
+
|
45
|
+
--style-glob GLOB Glob to run style checks over (default: {app,lib,spec}/**/*.rb)
|
46
|
+
--style-measure VALUE Max line length (default: 80)
|
47
|
+
--style-exclude GLOB Exclude file or glob from style checking
|
48
|
+
--no-style Disable style checking
|
49
|
+
|
50
|
+
--doc-glob GLOB Glob to run doc checks over (default: {app,lib}/**/*.rb)
|
51
|
+
--doc-exclude GLOB Exclude file or glob from documentation checking
|
52
|
+
--no-readme Disable readme checking
|
53
|
+
--no-doc Disable documentation checking
|
54
|
+
|
55
|
+
--lt FILE,THRESHOLD Check the number in FILE is < to THRESHOLD (a number or another file name)
|
56
|
+
--lte FILE,THRESHOLD Check the number in FILE is <= to THRESHOLD (a number or another file name)
|
57
|
+
--eq FILE,THRESHOLD Check the number in FILE is == to THRESHOLD (a number or another file name)
|
58
|
+
--gte FILE,THRESHOLD Check the number in FILE is >= to THRESHOLD (a number or another file name)
|
59
|
+
--gt FILE,THRESHOLD Check the number in FILE is > to THRESHOLD (a number or another file name)
|
60
|
+
|
61
|
+
-f, --all FILE Apply all checks to given file
|
62
|
+
--max-violations VALUE Max allowed violations (default: 0)
|
63
|
+
--json Output as JSON
|
64
|
+
--parallel Use all processors. Slower on small projects, faster on large.
|
65
|
+
|
66
|
+
-v, --version Show version
|
67
|
+
-h, --help Show this message
|
64
68
|
|
65
69
|
Set default options using a `.cane` file:
|
66
70
|
|
data/lib/cane/threshold_check.rb
CHANGED
@@ -5,15 +5,22 @@ module Cane
|
|
5
5
|
# Configurable check that allows the contents of a file to be compared against
|
6
6
|
# a given value.
|
7
7
|
class ThresholdCheck < Struct.new(:opts)
|
8
|
+
THRESHOLDS = {
|
9
|
+
lt: :<,
|
10
|
+
lte: :<=,
|
11
|
+
eq: :==,
|
12
|
+
gte: :>=,
|
13
|
+
gt: :>
|
14
|
+
}
|
8
15
|
|
9
16
|
def self.key; :threshold; end
|
10
17
|
def self.options
|
11
|
-
{
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
THRESHOLDS.each_with_object({}) do |(key, value), h|
|
19
|
+
h[key] = ["Check the number in FILE is #{value} to THRESHOLD " +
|
20
|
+
"(a number or another file name)",
|
21
|
+
variable: "FILE,THRESHOLD",
|
22
|
+
type: Array]
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
26
|
def violations
|
@@ -54,9 +61,11 @@ module Cane
|
|
54
61
|
end
|
55
62
|
|
56
63
|
def thresholds
|
57
|
-
|
58
|
-
|
59
|
-
|
64
|
+
THRESHOLDS.map do |k, v|
|
65
|
+
opts.fetch(k, []).map do |x|
|
66
|
+
x.unshift(v)
|
67
|
+
end
|
68
|
+
end.reduce(:+)
|
60
69
|
end
|
61
70
|
|
62
71
|
# Null object for all cases when the value to be compared against cannot be
|
data/lib/cane/version.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -17,11 +17,31 @@ describe Cane::CLI::Parser do
|
|
17
17
|
result[:style_measure].should == 3
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'allows checking of a value in a file' do
|
20
|
+
it 'allows checking gte of a value in a file' do
|
21
21
|
output, result = run("--gte myfile,90")
|
22
22
|
result[:gte].should == [['myfile', '90']]
|
23
23
|
end
|
24
24
|
|
25
|
+
it 'allows checking eq of a value in a file' do
|
26
|
+
output, result = run("--eq myfile,90")
|
27
|
+
result[:eq].should == [['myfile', '90']]
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'allows checking lte of a value in a file' do
|
31
|
+
output, result = run("--lte myfile,90")
|
32
|
+
result[:lte].should == [['myfile', '90']]
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'allows checking lt of a value in a file' do
|
36
|
+
output, result = run("--lt myfile,90")
|
37
|
+
result[:lt].should == [['myfile', '90']]
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'allows checking gt of a value in a file' do
|
41
|
+
output, resugt = run("--gt myfile,90")
|
42
|
+
resugt[:gt].should == [['myfile', '90']]
|
43
|
+
end
|
44
|
+
|
25
45
|
it 'allows upper bound of failed checks' do
|
26
46
|
output, result = run("--max-violations 1")
|
27
47
|
result[:max_violations].should == 1
|
data/spec/spec_helper.rb
CHANGED
@@ -28,6 +28,21 @@ def make_file(content)
|
|
28
28
|
tempfile.path
|
29
29
|
end
|
30
30
|
|
31
|
+
RSpec::Matchers.define :have_violation do |label|
|
32
|
+
match do |check|
|
33
|
+
violations = check.violations
|
34
|
+
violations.length.should == 1
|
35
|
+
violations[0][:label].should == label
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
RSpec::Matchers.define :have_no_violations do |label|
|
40
|
+
match do |check|
|
41
|
+
violations = check.violations
|
42
|
+
violations.length.should == 0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
31
46
|
require 'simplecov'
|
32
47
|
|
33
48
|
class SimpleCov::Formatter::QualityFormatter
|
@@ -16,23 +16,59 @@ describe Cane::ThresholdCheck do
|
|
16
16
|
|
17
17
|
context "checking violations" do
|
18
18
|
|
19
|
+
def run(threshold, value)
|
20
|
+
described_class.new(threshold => [['x', value]])
|
21
|
+
end
|
22
|
+
|
19
23
|
context "when the current coverage cannot be read" do
|
20
|
-
it
|
21
|
-
|
22
|
-
|
23
|
-
violations.length.should == 1
|
24
|
-
violations[0][:label].should ==
|
25
|
-
'bogus_file is unavailable, should be >= 20.0'
|
24
|
+
it do
|
25
|
+
run(:gte, 20).should \
|
26
|
+
have_violation('x is unavailable, should be >= 20.0')
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
30
|
context "when the coverage threshold is incorrectly specified" do
|
30
|
-
it
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
it do
|
32
|
+
described_class.new(gte: [['20', 'bogus_file']]).should \
|
33
|
+
have_violation('bogus_file is not a number or a file')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when coverage threshold is valid' do
|
38
|
+
before do
|
39
|
+
file = fire_replaced_class_double("Cane::File")
|
40
|
+
stub_const("Cane::File", file)
|
41
|
+
file.should_receive(:contents).with('x').and_return("8\n")
|
42
|
+
end
|
43
|
+
|
44
|
+
context '>' do
|
45
|
+
it { run(:gt, 7).should have_no_violations }
|
46
|
+
it { run(:gt, 8).should have_violation('x is 8.0, should be > 8.0') }
|
47
|
+
it { run(:gt, 9).should have_violation('x is 8.0, should be > 9.0') }
|
48
|
+
end
|
49
|
+
|
50
|
+
context '>=' do
|
51
|
+
it { run(:gte, 7).should have_no_violations }
|
52
|
+
it { run(:gte, 8).should have_no_violations }
|
53
|
+
it { run(:gte, 9).should have_violation('x is 8.0, should be >= 9.0') }
|
54
|
+
end
|
55
|
+
|
56
|
+
context '==' do
|
57
|
+
it { run(:eq, 7).should have_violation('x is 8.0, should be == 7.0') }
|
58
|
+
it { run(:eq, 8).should have_no_violations }
|
59
|
+
it { run(:eq, 9).should have_violation('x is 8.0, should be == 9.0') }
|
60
|
+
end
|
61
|
+
|
62
|
+
context '<=' do
|
63
|
+
it { run(:lte, 7).should have_violation('x is 8.0, should be <= 7.0') }
|
64
|
+
it { run(:lte, 8).should have_no_violations }
|
65
|
+
it { run(:lte, 9).should have_no_violations }
|
66
|
+
end
|
67
|
+
|
68
|
+
context '<' do
|
69
|
+
it { run(:lt, 7).should have_violation('x is 8.0, should be < 7.0') }
|
70
|
+
it { run(:lt, 8).should have_violation('x is 8.0, should be < 8.0') }
|
71
|
+
it { run(:lt, 9).should have_no_violations }
|
36
72
|
end
|
37
73
|
end
|
38
74
|
|