cane 2.6.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cdf72ffbc2d2703ebc9bced476ff1405f3a8a25
4
- data.tar.gz: b52ec92312ffc04e2a2f410705bcbb06bdaebd58
3
+ metadata.gz: 3038468a984c0181fcd109612a08c5f263b93ff9
4
+ data.tar.gz: d11758c7e61a2553b747c6fdea13fcf248d7cfd5
5
5
  SHA512:
6
- metadata.gz: a689a6778c6431208400feab3bf99bc19ff9e64b66eadc7550451a8ba32ad1ded12004f191efe4bcb84da10dbc7b9c7336ebd620922b26ada8c049cd85b22f20
7
- data.tar.gz: 35a5c4b4c452a092e5e9a63202e850e6144be9c06681648ee0a74da9f713855ddd2493d857bb75bf853f22d659ff0daa1617576f73136775568361d39cded562
6
+ metadata.gz: 5f46e8fe84b99920e0259bc8ce71c5bc2a2f05dc49993283caf033cdfc7f85a0c59c62ad55059945e044c58660d594cfeceea4b457ed06f446a6ae04ce819459
7
+ data.tar.gz: d1d407ce3b860e2d915356dbe2339edda226040a506b78a561b80bcadcc4fa012c65d3aac69affb00b01ad1d11aa9a2b51285e352369270b72479feeadd9456c
data/HISTORY.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Cane History
2
2
 
3
+ ## 3.0.0 - 10 March 2016 (f602b9)
4
+
5
+ * Compat: Rake 11 supported
6
+ * Compat: Ruby 1.9 no longer supported.
7
+ * Feature: Glob options now take arrays.
8
+
3
9
  ## 2.6.2 - 20 April 2014 (8f54b4)
4
10
 
5
11
  * Bugfix: Commented methods no longer trigger a documentation violation for
data/README.md CHANGED
@@ -211,7 +211,7 @@ A good README should include at a minimum:
211
211
 
212
212
  ## Compatibility
213
213
 
214
- Requires MRI 1.9, since it depends on the `ripper` library to calculate
214
+ Requires CRuby 2.0, since it depends on the `ripper` library to calculate
215
215
  complexity metrics. This only applies to the Ruby used to run Cane, not the
216
216
  project it is being run against. In other words, you can run Cane against your
217
217
  1.8 or JRuby project.
@@ -179,7 +179,7 @@ module Cane
179
179
  end
180
180
 
181
181
  def file_names
182
- Dir[opts.fetch(:abc_glob)]
182
+ Dir.glob(opts.fetch(:abc_glob))
183
183
  end
184
184
 
185
185
  def order(result)
@@ -114,7 +114,7 @@ module Cane
114
114
  end
115
115
 
116
116
  def file_names
117
- Dir[opts.fetch(:doc_glob)].reject { |file| excluded?(file) }
117
+ Dir.glob(opts.fetch(:doc_glob)).reject { |file| excluded?(file) }
118
118
  end
119
119
 
120
120
  def method_definition?(line)
@@ -139,7 +139,7 @@ module Cane
139
139
 
140
140
  def exclusions
141
141
  @exclusions ||= opts.fetch(:doc_exclude, []).flatten.map do |i|
142
- Dir[i]
142
+ Dir.glob(i)
143
143
  end.flatten.to_set
144
144
  end
145
145
 
@@ -60,7 +60,7 @@ module Cane
60
60
  self.canefile = './.cane'
61
61
  end
62
62
 
63
- unless ::Rake.application.last_comment
63
+ unless ::Rake.application.last_description
64
64
  desc %(Check code quality metrics with cane)
65
65
  end
66
66
 
@@ -60,7 +60,7 @@ module Cane
60
60
  end
61
61
 
62
62
  def file_list
63
- Dir[opts.fetch(:style_glob)].reject {|f| excluded?(f) }
63
+ Dir.glob(opts.fetch(:style_glob)).reject {|f| excluded?(f) }
64
64
  end
65
65
 
66
66
  def measure
@@ -73,7 +73,7 @@ module Cane
73
73
 
74
74
  def exclusions
75
75
  @exclusions ||= opts.fetch(:style_exclude, []).flatten.map do |i|
76
- Dir[i]
76
+ Dir.glob(i)
77
77
  end.flatten.to_set
78
78
  end
79
79
 
@@ -1,3 +1,3 @@
1
1
  module Cane
2
- VERSION = '2.6.2'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -18,7 +18,7 @@ describe Cane::AbcCheck do
18
18
  RUBY
19
19
 
20
20
  violations = check(file_name, abc_max: 1, no_abc: true).violations
21
- violations.should be_empty
21
+ expect(violations).to be_empty
22
22
  end
23
23
 
24
24
  it 'creates an AbcMaxViolation for each method above the threshold' do
@@ -36,9 +36,10 @@ describe Cane::AbcCheck do
36
36
  RUBY
37
37
 
38
38
  violations = check(file_name, abc_max: 1, no_abc: false).violations
39
- violations.length.should == 1
40
- violations[0].values_at(:file, :label, :value).should ==
39
+ expect(violations.length).to eq(1)
40
+ expect(violations[0].values_at(:file, :label, :value)).to eq(
41
41
  [file_name, "Harness#complex_method", 2]
42
+ )
42
43
  end
43
44
 
44
45
  it 'sorts violations by complexity' do
@@ -56,9 +57,9 @@ describe Cane::AbcCheck do
56
57
  RUBY
57
58
 
58
59
  violations = check(file_name, abc_max: 0).violations
59
- violations.length.should == 2
60
+ expect(violations.length).to eq(2)
60
61
  complexities = violations.map {|x| x[:value] }
61
- complexities.should == complexities.sort.reverse
62
+ expect(complexities).to eq(complexities.sort.reverse)
62
63
  end
63
64
 
64
65
  it 'creates a violation when code cannot be parsed' do
@@ -67,9 +68,9 @@ describe Cane::AbcCheck do
67
68
  RUBY
68
69
 
69
70
  violations = check(file_name).violations
70
- violations.length.should == 1
71
- violations[0][:file].should == file_name
72
- violations[0][:description].should be_instance_of(String)
71
+ expect(violations.length).to eq(1)
72
+ expect(violations[0][:file]).to eq(file_name)
73
+ expect(violations[0][:description]).to be_instance_of(String)
73
74
  end
74
75
 
75
76
  it 'skips declared exclusions' do
@@ -105,9 +106,10 @@ describe Cane::AbcCheck do
105
106
  abc_max: 0,
106
107
  abc_exclude: exclusions
107
108
  ).violations
108
- violations.length.should == 1
109
- violations[0].values_at(:file, :label, :value).should ==
109
+ expect(violations.length).to eq(1)
110
+ expect(violations[0].values_at(:file, :label, :value)).to eq(
110
111
  [file_name, "Harness::Nested#other_meth", 1]
112
+ )
111
113
  end
112
114
 
113
115
  it "creates an AbcMaxViolation for method in assigned anonymous class" do
@@ -135,7 +137,7 @@ describe Cane::AbcCheck do
135
137
  RUBY
136
138
 
137
139
  violations = check(file_name, abc_max: 1).violations
138
- violations[0][:label].should == "(anon)#test_method"
140
+ expect(violations[0][:label]).to eq("(anon)#test_method")
139
141
  end
140
142
 
141
143
  def self.it_should_extract_method_name(name, label=name, sep='#')
@@ -150,7 +152,7 @@ describe Cane::AbcCheck do
150
152
  RUBY
151
153
 
152
154
  violations = check(file_name, abc_max: 1).violations
153
- violations[0][:label].should == "Harness#{sep}#{label}"
155
+ expect(violations[0][:label]).to eq("Harness#{sep}#{label}")
154
156
  end
155
157
  end
156
158
 
@@ -161,4 +163,21 @@ describe Cane::AbcCheck do
161
163
  it_should_extract_method_name 'GET'
162
164
  it_should_extract_method_name '`'
163
165
  it_should_extract_method_name '>='
166
+
167
+ describe "#file_names" do
168
+ context "abc_glob is an array" do
169
+ it "returns an array of relative file paths" do
170
+ glob = [
171
+ 'spec/fixtures/a/**/*.{rb,prawn}',
172
+ 'spec/fixtures/b/**/*.rb'
173
+ ]
174
+ check = described_class.new(abc_glob: glob)
175
+ expect(check.send(:file_names)).to eq([
176
+ 'spec/fixtures/a/1.rb',
177
+ 'spec/fixtures/a/3.prawn',
178
+ 'spec/fixtures/b/1.rb'
179
+ ])
180
+ end
181
+ end
182
+ end
164
183
  end
@@ -49,12 +49,12 @@ describe 'The cane application' do
49
49
  --check #{class_name}
50
50
  --unhappy-file #{fn}
51
51
  )
52
- output.should include("Lines violated style requirements")
53
- output.should include("Methods exceeded maximum allowed ABC complexity")
54
- output.should include(
52
+ expect(output).to include("Lines violated style requirements")
53
+ expect(output).to include("Methods exceeded maximum allowed ABC complexity")
54
+ expect(output).to include(
55
55
  "Class and Module definitions require explanatory comments"
56
56
  )
57
- exitstatus.should == 1
57
+ expect(exitstatus).to eq(1)
58
58
  end
59
59
 
60
60
  it 'handles invalid unicode input' do
@@ -62,19 +62,19 @@ describe 'The cane application' do
62
62
 
63
63
  _, exitstatus = run("--style-glob #{fn} --abc-glob #{fn} --doc-glob #{fn}")
64
64
 
65
- exitstatus.should == 0
65
+ expect(exitstatus).to eq(0)
66
66
  end
67
67
 
68
68
  it 'can run tasks in parallel' do
69
69
  # This spec isn't great, but there is no good way to actually observe that
70
70
  # tasks run in parallel and we want to verify the conditional is correct.
71
- Cane.task_runner(parallel: true).should == Parallel
71
+ expect(Cane.task_runner(parallel: true)).to eq(Parallel)
72
72
  end
73
73
 
74
74
  it 'colorizes output' do
75
75
  output, exitstatus = run("--color --abc-max 0")
76
76
 
77
- output.should include("\e[31m")
77
+ expect(output).to include("\e[31m")
78
78
  end
79
79
 
80
80
  after do
@@ -9,16 +9,16 @@ describe Cane::CLI do
9
9
  let!(:cane) { class_double("Cane").as_stubbed_const }
10
10
 
11
11
  it 'runs Cane with the given arguments' do
12
- parser.should_receive(:parse).with("--args").and_return(args: true)
13
- cane.should_receive(:run).with(args: true).and_return("tracer")
12
+ expect(parser).to receive(:parse).with("--args").and_return(args: true)
13
+ expect(cane).to receive(:run).with(args: true).and_return("tracer")
14
14
 
15
- described_class.run("--args").should == "tracer"
15
+ expect(described_class.run("--args")).to eq("tracer")
16
16
  end
17
17
 
18
18
  it 'does not run Cane if parser was able to handle input' do
19
- parser.should_receive(:parse).with("--args").and_return("tracer")
19
+ expect(parser).to receive(:parse).with("--args").and_return("tracer")
20
20
 
21
- described_class.run("--args").should == "tracer"
21
+ expect(described_class.run("--args")).to eq("tracer")
22
22
  end
23
23
  end
24
24
  end
@@ -43,19 +43,19 @@ end
43
43
  RUBY
44
44
 
45
45
  violations = check(file_name).violations
46
- violations.length.should == 3
46
+ expect(violations.length).to eq(3)
47
47
 
48
- violations[0].values_at(:file, :line, :label).should == [
48
+ expect(violations[0].values_at(:file, :line, :label)).to eq([
49
49
  file_name, 3, "NoDoc"
50
- ]
50
+ ])
51
51
 
52
- violations[1].values_at(:file, :line, :label).should == [
52
+ expect(violations[1].values_at(:file, :line, :label)).to eq([
53
53
  file_name, 15, "AlsoNeedsDoc"
54
- ]
54
+ ])
55
55
 
56
- violations[2].values_at(:file, :line, :label).should == [
56
+ expect(violations[2].values_at(:file, :line, :label)).to eq([
57
57
  file_name, 17, "ButThisNeedsDoc"
58
- ]
58
+ ])
59
59
  end
60
60
 
61
61
  it 'does not create violations for single line classes without methods' do
@@ -71,15 +71,15 @@ end
71
71
  RUBY
72
72
 
73
73
  violations = check(file_name).violations
74
- violations.length.should == 2
74
+ expect(violations.length).to eq(2)
75
75
 
76
- violations[0].values_at(:file, :line, :label).should == [
76
+ expect(violations[0].values_at(:file, :line, :label)).to eq([
77
77
  file_name, 1, "NeedsDoc"
78
- ]
78
+ ])
79
79
 
80
- violations[1].values_at(:file, :line, :label).should == [
80
+ expect(violations[1].values_at(:file, :line, :label)).to eq([
81
81
  file_name, 2, "AlsoNeedsDoc"
82
- ]
82
+ ])
83
83
  end
84
84
 
85
85
  it 'ignores magic encoding comments' do
@@ -93,39 +93,41 @@ class Doc; end
93
93
  RUBY
94
94
 
95
95
  violations = check(file_name).violations
96
- violations.length.should == 2
96
+ expect(violations.length).to eq(2)
97
97
 
98
- violations[0].values_at(:file, :line, :label).should == [
98
+ expect(violations[0].values_at(:file, :line, :label)).to eq([
99
99
  file_name, 2, "NoDoc"
100
- ]
101
- violations[1].values_at(:file, :line, :label).should == [
100
+ ])
101
+ expect(violations[1].values_at(:file, :line, :label)).to eq([
102
102
  file_name, 4, "AlsoNoDoc"
103
- ]
103
+ ])
104
104
  end
105
105
 
106
106
  it 'creates a violation for missing README' do
107
107
  file = class_double("Cane::File").as_stubbed_const
108
108
  stub_const("Cane::File", file)
109
- file.should_receive(:case_insensitive_glob).with("README*").and_return([])
109
+ expect(file).to receive(:case_insensitive_glob).with(
110
+ "README*"
111
+ ).and_return([])
110
112
 
111
113
  violations = check("").violations
112
- violations.length.should == 1
114
+ expect(violations.length).to eq(1)
113
115
 
114
- violations[0].values_at(:description, :label).should == [
116
+ expect(violations[0].values_at(:description, :label)).to eq([
115
117
  "Missing documentation", "No README found"
116
- ]
118
+ ])
117
119
  end
118
120
 
119
121
  it 'does not create a violation when readme exists' do
120
122
  file = class_double("Cane::File").as_stubbed_const
121
123
  stub_const("Cane::File", file)
122
- file
123
- .should_receive(:case_insensitive_glob)
124
+ expect(file)
125
+ .to receive(:case_insensitive_glob)
124
126
  .with("README*")
125
127
  .and_return(%w(readme.md))
126
128
 
127
129
  violations = check("").violations
128
- violations.length.should == 0
130
+ expect(violations.length).to eq(0)
129
131
  end
130
132
 
131
133
  it 'skips declared exclusions' do
@@ -138,7 +140,7 @@ class Doc; end
138
140
  doc_exclude: [file_name]
139
141
  ).violations
140
142
 
141
- violations.length.should == 0
143
+ expect(violations.length).to eq(0)
142
144
  end
143
145
 
144
146
  it 'skips declared glob-based exclusions' do
@@ -151,7 +153,7 @@ class Doc; end
151
153
  doc_exclude: ["#{File.dirname(file_name)}/*"]
152
154
  ).violations
153
155
 
154
- violations.length.should == 0
156
+ expect(violations.length).to eq(0)
155
157
  end
156
158
 
157
159
  it 'skips class inside an array' do
@@ -163,6 +165,6 @@ class Doc; end
163
165
  RUBY
164
166
 
165
167
  violations = check(file_name).violations
166
- violations.length.should == 0
168
+ expect(violations.length).to eq(0)
167
169
  end
168
170
  end
@@ -9,18 +9,18 @@ describe Cane::EncodingAwareIterator do
9
9
  it 'handles non-UTF8 input' do
10
10
  lines = ["\xc3\x28"]
11
11
  result = described_class.new(lines).map.with_index do |line, number|
12
- line.should be_kind_of(String)
12
+ expect(line).to be_kind_of(String)
13
13
  [line =~ /\s/, number]
14
14
  end
15
- result.should == [[nil, 0]]
15
+ expect(result).to eq([[nil, 0]])
16
16
  end
17
17
 
18
18
  it 'does not enter an infinite loop on persistently bad input' do
19
- ->{
19
+ expect{
20
20
  described_class.new([""]).map.with_index do |line, number|
21
21
  "\xc3\x28" =~ /\s/
22
22
  end
23
- }.should raise_error(ArgumentError)
23
+ }.to raise_error(ArgumentError)
24
24
  end
25
25
 
26
26
  it 'allows each with no block' do
@@ -28,6 +28,6 @@ describe Cane::EncodingAwareIterator do
28
28
  described_class.new([""]).each.with_index do |line, number|
29
29
  called_with_line = line
30
30
  end
31
- called_with_line.should == ""
31
+ expect(called_with_line).to eq("")
32
32
  end
33
33
  end
@@ -17,7 +17,9 @@ describe Cane::File do
17
17
  expected.each do |x|
18
18
  FileUtils.touch(x)
19
19
  end
20
- Cane::File.case_insensitive_glob("README*").should =~ expected
20
+ expect(Cane::File.case_insensitive_glob("README*")).to match_array(
21
+ expected
22
+ )
21
23
  end
22
24
  end
23
25
  end
@@ -0,0 +1 @@
1
+ puts "wooo I am a/1.rb"
@@ -0,0 +1 @@
1
+ puts "wooo I am b/1.rb"
@@ -5,7 +5,8 @@ require 'cane/json_formatter'
5
5
  describe Cane::JsonFormatter do
6
6
  it 'outputs violations as JSON' do
7
7
  violations = [{description: 'Fail', line: 3}]
8
- JSON.parse(described_class.new(violations).to_s).should ==
8
+ expect(JSON.parse(described_class.new(violations).to_s)).to eq(
9
9
  [{'description' => 'Fail', 'line' => 3}]
10
+ )
10
11
  end
11
12
  end
@@ -13,71 +13,71 @@ describe Cane::CLI::Parser do
13
13
 
14
14
  it 'allows style options to be configured' do
15
15
  output, result = run("--style-glob myfile --style-measure 3")
16
- result[:style_glob].should == 'myfile'
17
- result[:style_measure].should == 3
16
+ expect(result[:style_glob]).to eq('myfile')
17
+ expect(result[:style_measure]).to eq(3)
18
18
  end
19
19
 
20
20
  it 'allows checking gte of a value in a file' do
21
21
  output, result = run("--gte myfile,90")
22
- result[:gte].should == [['myfile', '90']]
22
+ expect(result[:gte]).to eq([['myfile', '90']])
23
23
  end
24
24
 
25
25
  it 'allows checking eq of a value in a file' do
26
26
  output, result = run("--eq myfile,90")
27
- result[:eq].should == [['myfile', '90']]
27
+ expect(result[:eq]).to eq([['myfile', '90']])
28
28
  end
29
29
 
30
30
  it 'allows checking lte of a value in a file' do
31
31
  output, result = run("--lte myfile,90")
32
- result[:lte].should == [['myfile', '90']]
32
+ expect(result[:lte]).to eq([['myfile', '90']])
33
33
  end
34
34
 
35
35
  it 'allows checking lt of a value in a file' do
36
36
  output, result = run("--lt myfile,90")
37
- result[:lt].should == [['myfile', '90']]
37
+ expect(result[:lt]).to eq([['myfile', '90']])
38
38
  end
39
39
 
40
40
  it 'allows checking gt of a value in a file' do
41
41
  output, resugt = run("--gt myfile,90")
42
- resugt[:gt].should == [['myfile', '90']]
42
+ expect(resugt[:gt]).to eq([['myfile', '90']])
43
43
  end
44
44
 
45
45
  it 'allows upper bound of failed checks' do
46
46
  output, result = run("--max-violations 1")
47
- result[:max_violations].should == 1
47
+ expect(result[:max_violations]).to eq(1)
48
48
  end
49
49
 
50
50
  it 'uses positional arguments as shortcut for individual files' do
51
51
  output, result = run("--all mysinglefile")
52
- result[:abc_glob].should == 'mysinglefile'
53
- result[:style_glob].should == 'mysinglefile'
54
- result[:doc_glob].should == 'mysinglefile'
52
+ expect(result[:abc_glob]).to eq('mysinglefile')
53
+ expect(result[:style_glob]).to eq('mysinglefile')
54
+ expect(result[:doc_glob]).to eq('mysinglefile')
55
55
 
56
56
  output, result = run("--all mysinglefile --abc-glob myotherfile")
57
- result[:abc_glob].should == 'myotherfile'
58
- result[:style_glob].should == 'mysinglefile'
59
- result[:doc_glob].should == 'mysinglefile'
57
+ expect(result[:abc_glob]).to eq('myotherfile')
58
+ expect(result[:style_glob]).to eq('mysinglefile')
59
+ expect(result[:doc_glob]).to eq('mysinglefile')
60
60
  end
61
61
 
62
62
  it 'displays a help message' do
63
63
  output, result = run("--help")
64
64
 
65
- result.should be
66
- output.should include("Usage:")
65
+ expect(result).to be
66
+ expect(output).to include("Usage:")
67
67
  end
68
68
 
69
69
  it 'handles invalid options by showing help' do
70
70
  output, result = run("--bogus")
71
71
 
72
- output.should include("Usage:")
73
- result.should_not be
72
+ expect(output).to include("Usage:")
73
+ expect(result).not_to be
74
74
  end
75
75
 
76
76
  it 'displays version' do
77
77
  output, result = run("--version")
78
78
 
79
- result.should be
80
- output.should include(Cane::VERSION)
79
+ expect(result).to be
80
+ expect(output).to include(Cane::VERSION)
81
81
  end
82
82
 
83
83
  it 'supports exclusions' do
@@ -88,18 +88,18 @@ describe Cane::CLI::Parser do
88
88
  ].join(' ')
89
89
 
90
90
  _, result = run(options)
91
- result[:abc_exclude].should == [['Harness#complex_method']]
92
- result[:doc_exclude].should == [['myfile']]
93
- result[:style_exclude].should == [['myfile']]
91
+ expect(result[:abc_exclude]).to eq([['Harness#complex_method']])
92
+ expect(result[:doc_exclude]).to eq([['myfile']])
93
+ expect(result[:style_exclude]).to eq([['myfile']])
94
94
  end
95
95
 
96
96
  describe 'argument ordering' do
97
97
  it 'gives precedence to the last argument #1' do
98
98
  _, result = run("--doc-glob myfile --no-doc")
99
- result[:no_doc].should be
99
+ expect(result[:no_doc]).to be
100
100
 
101
101
  _, result = run("--no-doc --doc-glob myfile")
102
- result[:no_doc].should_not be
102
+ expect(result[:no_doc]).not_to be
103
103
  end
104
104
  end
105
105
 
@@ -111,34 +111,34 @@ describe Cane::CLI::Parser do
111
111
  EOS
112
112
  file = class_double("Cane::File").as_stubbed_const
113
113
  stub_const("Cane::File", file)
114
- file.should_receive(:exists?).with('./.cane').and_return(true)
115
- file.should_receive(:contents).with('./.cane').and_return(defaults)
114
+ expect(file).to receive(:exists?).with('./.cane').and_return(true)
115
+ expect(file).to receive(:contents).with('./.cane').and_return(defaults)
116
116
 
117
117
  _, result = run("--style-glob myotherfile")
118
118
 
119
- result[:no_doc].should be
120
- result[:abc_glob].should == 'myfile'
121
- result[:style_glob].should == 'myotherfile'
119
+ expect(result[:no_doc]).to be
120
+ expect(result[:abc_glob]).to eq('myfile')
121
+ expect(result[:style_glob]).to eq('myotherfile')
122
122
  end
123
123
 
124
124
  it 'allows parallel option' do
125
125
  _, result = run("--parallel")
126
- result[:parallel].should be
126
+ expect(result[:parallel]).to be
127
127
  end
128
128
 
129
129
  it 'handles ambiguous options' do
130
130
  output, result = run("-abc-max")
131
- output.should include("Usage:")
132
- result.should_not be
131
+ expect(output).to include("Usage:")
132
+ expect(result).not_to be
133
133
  end
134
134
 
135
135
  it 'handles no_readme option' do
136
136
  _, result = run("--no-readme")
137
- result[:no_readme].should be
137
+ expect(result[:no_readme]).to be
138
138
  end
139
139
 
140
140
  it 'handles json option' do
141
141
  _, result = run("--json")
142
- result[:json].should be
142
+ expect(result[:json]).to be
143
143
  end
144
144
  end
@@ -21,15 +21,15 @@ describe Cane::RakeTask do
21
21
  cane.parallel = false
22
22
  end
23
23
 
24
- task.no_abc.should == true
24
+ expect(task.no_abc).to eq(true)
25
25
 
26
- task.should_receive(:abort)
26
+ expect(task).to receive(:abort)
27
27
  out = capture_stdout do
28
28
  Rake::Task['quality'].invoke
29
29
  end
30
30
 
31
- out.should include("Quality threshold crossed")
32
- out.should include("theopt")
31
+ expect(out).to include("Quality threshold crossed")
32
+ expect(out).to include("theopt")
33
33
  end
34
34
 
35
35
  it 'can be configured using a .cane file' do
@@ -39,12 +39,12 @@ describe Cane::RakeTask do
39
39
  cane.canefile = make_file(conf)
40
40
  end
41
41
 
42
- task.should_receive(:abort)
42
+ expect(task).to receive(:abort)
43
43
  out = capture_stdout do
44
44
  Rake::Task['canefile_quality'].invoke
45
45
  end
46
46
 
47
- out.should include("Quality threshold crossed")
47
+ expect(out).to include("Quality threshold crossed")
48
48
  end
49
49
 
50
50
  it 'defaults to using a canefile without a block' do
@@ -54,12 +54,12 @@ describe Cane::RakeTask do
54
54
 
55
55
  task = Cane::RakeTask.new(:canefile_quality)
56
56
 
57
- task.should_receive(:abort)
57
+ expect(task).to receive(:abort)
58
58
  out = capture_stdout do
59
59
  Rake::Task['canefile_quality'].invoke
60
60
  end
61
61
 
62
- out.should include("Quality threshold crossed")
62
+ expect(out).to include("Quality threshold crossed")
63
63
  end
64
64
  end
65
65
 
@@ -5,20 +5,20 @@ require 'cane/runner'
5
5
  describe Cane::Runner do
6
6
  describe '#run' do
7
7
  it 'returns true iff fewer violations than max allowed' do
8
- described_class.new(checks: [], max_violations: 0).run.should be
9
- described_class.new(checks: [], max_violations: -1).run.should_not be
8
+ expect(described_class.new(checks: [], max_violations: 0).run).to be
9
+ expect(described_class.new(checks: [], max_violations: -1).run).not_to be
10
10
  end
11
11
 
12
12
  it 'returns JSON output' do
13
13
  formatter = class_double("Cane::JsonFormatter").as_stubbed_const
14
- formatter.should_receive(:new).and_return("JSON")
14
+ expect(formatter).to receive(:new).and_return("JSON")
15
15
  buffer = StringIO.new("")
16
16
 
17
17
  described_class.new(
18
18
  out: buffer, checks: [], max_violations: 0, json: true
19
19
  ).run
20
20
 
21
- buffer.string.should == "JSON"
21
+ expect(buffer.string).to eq("JSON")
22
22
  end
23
23
  end
24
24
  end
@@ -37,15 +37,15 @@ end
37
37
  RSpec::Matchers.define :have_violation do |label|
38
38
  match do |check|
39
39
  violations = check.violations
40
- violations.length.should == 1
41
- violations[0][:label].should == label
40
+ expect(violations.length).to eq(1)
41
+ expect(violations[0][:label]).to eq(label)
42
42
  end
43
43
  end
44
44
 
45
45
  RSpec::Matchers.define :have_no_violations do |label|
46
46
  match do |check|
47
47
  violations = check.violations
48
- violations.length.should == 0
48
+ expect(violations.length).to eq(0)
49
49
  end
50
50
  end
51
51
 
@@ -19,7 +19,7 @@ describe Cane::StyleCheck do
19
19
  file_name = make_file(ruby_with_style_issue)
20
20
 
21
21
  violations = check(file_name, style_measure: 8).violations
22
- violations.length.should == 3
22
+ expect(violations.length).to eq(3)
23
23
  end
24
24
 
25
25
  it 'skips declared exclusions' do
@@ -30,7 +30,7 @@ describe Cane::StyleCheck do
30
30
  style_exclude: [file_name]
31
31
  ).violations
32
32
 
33
- violations.length.should == 0
33
+ expect(violations.length).to eq(0)
34
34
  end
35
35
 
36
36
  it 'skips declared glob-based exclusions' do
@@ -41,7 +41,7 @@ describe Cane::StyleCheck do
41
41
  style_exclude: ["#{File.dirname(file_name)}/*"]
42
42
  ).violations
43
43
 
44
- violations.length.should == 0
44
+ expect(violations.length).to eq(0)
45
45
  end
46
46
 
47
47
  it 'does not include trailing new lines in the character count' do
@@ -52,7 +52,38 @@ describe Cane::StyleCheck do
52
52
  style_exclude: [file_name]
53
53
  ).violations
54
54
 
55
- violations.length.should == 0
55
+ expect(violations.length).to eq(0)
56
56
  end
57
57
 
58
+ describe "#file_list" do
59
+ context "style_glob is an array" do
60
+ it "returns an array of relative file paths" do
61
+ glob = [
62
+ 'spec/fixtures/a/**/*.{rb,prawn}',
63
+ 'spec/fixtures/b/**/*.haml'
64
+ ]
65
+ check = described_class.new(style_glob: glob)
66
+ expect(check.send(:file_list)).to eq([
67
+ 'spec/fixtures/a/1.rb',
68
+ 'spec/fixtures/a/3.prawn',
69
+ 'spec/fixtures/b/3/i.haml'
70
+ ])
71
+ end
72
+ end
73
+
74
+ context "style_exclude is an array" do
75
+ it "returns an array of relative file paths" do
76
+ glob = [
77
+ 'spec/fixtures/a/**/*.{rb,prawn}',
78
+ 'spec/fixtures/b/**/*.haml'
79
+ ]
80
+ exclude = [
81
+ 'spec/fixtures/a/**/*.prawn',
82
+ 'spec/fixtures/b/**/*.haml'
83
+ ]
84
+ check = described_class.new(style_exclude: exclude, style_glob: glob)
85
+ expect(check.send(:file_list)).to eq(['spec/fixtures/a/1.rb'])
86
+ end
87
+ end
88
+ end
58
89
  end
@@ -22,14 +22,14 @@ describe Cane::ThresholdCheck do
22
22
 
23
23
  context "when the current coverage cannot be read" do
24
24
  it do
25
- run(:gte, 20).should \
25
+ expect(run(:gte, 20)).to \
26
26
  have_violation('x is unavailable, should be >= 20.0')
27
27
  end
28
28
  end
29
29
 
30
30
  context "when the coverage threshold is incorrectly specified" do
31
31
  it do
32
- described_class.new(gte: [['20', 'bogus_file']]).should \
32
+ expect(described_class.new(gte: [['20', 'bogus_file']])).to \
33
33
  have_violation('bogus_file is not a number or a file')
34
34
  end
35
35
  end
@@ -38,37 +38,53 @@ describe Cane::ThresholdCheck do
38
38
  before do
39
39
  file = class_double("Cane::File").as_stubbed_const
40
40
  stub_const("Cane::File", file)
41
- file.should_receive(:contents).with('x').and_return("8\n")
41
+ expect(file).to receive(:contents).with('x').and_return("8\n")
42
42
  end
43
43
 
44
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') }
45
+ it { expect(run(:gt, 7)).to have_no_violations }
46
+ it {
47
+ expect(run(:gt, 8)).to have_violation('x is 8.0, should be > 8.0')
48
+ }
49
+ it {
50
+ expect(run(:gt, 9)).to have_violation('x is 8.0, should be > 9.0')
51
+ }
48
52
  end
49
53
 
50
54
  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') }
55
+ it { expect(run(:gte, 7)).to have_no_violations }
56
+ it { expect(run(:gte, 8)).to have_no_violations }
57
+ it {
58
+ expect(run(:gte, 9)).to have_violation('x is 8.0, should be >= 9.0')
59
+ }
54
60
  end
55
61
 
56
62
  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') }
63
+ it {
64
+ expect(run(:eq, 7)).to have_violation('x is 8.0, should be == 7.0')
65
+ }
66
+ it { expect(run(:eq, 8)).to have_no_violations }
67
+ it {
68
+ expect(run(:eq, 9)).to have_violation('x is 8.0, should be == 9.0')
69
+ }
60
70
  end
61
71
 
62
72
  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 }
73
+ it {
74
+ expect(run(:lte, 7)).to have_violation('x is 8.0, should be <= 7.0')
75
+ }
76
+ it { expect(run(:lte, 8)).to have_no_violations }
77
+ it { expect(run(:lte, 9)).to have_no_violations }
66
78
  end
67
79
 
68
80
  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 }
81
+ it {
82
+ expect(run(:lt, 7)).to have_violation('x is 8.0, should be < 7.0')
83
+ }
84
+ it {
85
+ expect(run(:lt, 8)).to have_violation('x is 8.0, should be < 8.0')
86
+ }
87
+ it { expect(run(:lt, 9)).to have_no_violations }
72
88
  end
73
89
  end
74
90
 
@@ -76,25 +92,27 @@ describe Cane::ThresholdCheck do
76
92
 
77
93
  context "normalizing a user supplied value to a threshold" do
78
94
  it "normalizes an integer to itself" do
79
- subject.normalized_limit(99).should == 99
95
+ expect(subject.normalized_limit(99)).to eq(99)
80
96
  end
81
97
 
82
98
  it "normalizes a float to itself" do
83
- subject.normalized_limit(99.6).should == 99.6
99
+ expect(subject.normalized_limit(99.6)).to eq(99.6)
84
100
  end
85
101
 
86
102
  it "normalizes a valid file to its contents" do
87
- subject.normalized_limit(make_file('99.5')).should == 99.5
103
+ expect(subject.normalized_limit(make_file('99.5'))).to eq(99.5)
88
104
  end
89
105
 
90
106
  it "normalizes an invalid file to an unavailable value" do
91
107
  limit = subject.normalized_limit("/File.does.not.exist")
92
- limit.should be_a Cane::ThresholdCheck::UnavailableValue
108
+ expect(limit).to be_a Cane::ThresholdCheck::UnavailableValue
93
109
  end
94
110
 
95
111
 
96
112
  it 'normalizes a json file to a float' do
97
- subject.normalized_limit(make_file(simplecov_last_run)).should == 93.88
113
+ expect(subject.normalized_limit(make_file(simplecov_last_run))).to eq(
114
+ 93.88
115
+ )
98
116
  end
99
117
 
100
118
  end
@@ -10,30 +10,30 @@ describe Cane::ViolationFormatter do
10
10
  end
11
11
 
12
12
  it 'includes number of violations in the group header' do
13
- described_class.new([violation("FAIL")]).to_s.should include("(1)")
13
+ expect(described_class.new([violation("FAIL")]).to_s).to include("(1)")
14
14
  end
15
15
 
16
16
  it 'includes total number of violations' do
17
17
  violations = [violation("FAIL1"), violation("FAIL2")]
18
18
  result = described_class.new(violations).to_s
19
- result.should include("Total Violations: 2")
19
+ expect(result).to include("Total Violations: 2")
20
20
  end
21
21
 
22
22
  it 'does not colorize output by default' do
23
23
  result = described_class.new([violation("FAIL")]).to_s
24
- result.should_not include("\e[31m")
24
+ expect(result).not_to include("\e[31m")
25
25
  end
26
26
 
27
27
  it 'colorizes output when passed color: true' do
28
28
  result = described_class.new([violation("FAIL")], color: true).to_s
29
- result.should include("\e[31m")
30
- result.should include("\e[0m")
29
+ expect(result).to include("\e[31m")
30
+ expect(result).to include("\e[0m")
31
31
  end
32
32
 
33
33
  it 'does not colorize output if max_violations is not crossed' do
34
34
  options = { color: true, max_violations: 1 }
35
35
  result = described_class.new([violation("FAIL")], options).to_s
36
36
 
37
- result.should_not include("\e[31m")
37
+ expect(result).not_to include("\e[31m")
38
38
  end
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cane
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Shay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-21 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel
@@ -116,6 +116,8 @@ files:
116
116
  - spec/doc_check_spec.rb
117
117
  - spec/encoding_aware_iterator_spec.rb
118
118
  - spec/file_spec.rb
119
+ - spec/fixtures/a/1.rb
120
+ - spec/fixtures/b/1.rb
119
121
  - spec/json_formatter_spec.rb
120
122
  - spec/parser_spec.rb
121
123
  - spec/rake_task_spec.rb
@@ -144,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
146
  version: '0'
145
147
  requirements: []
146
148
  rubyforge_project:
147
- rubygems_version: 2.2.0
149
+ rubygems_version: 2.4.5
148
150
  signing_key:
149
151
  specification_version: 4
150
152
  summary: Fails your build if code quality thresholds are not met. Provides complexity
@@ -156,6 +158,8 @@ test_files:
156
158
  - spec/doc_check_spec.rb
157
159
  - spec/encoding_aware_iterator_spec.rb
158
160
  - spec/file_spec.rb
161
+ - spec/fixtures/a/1.rb
162
+ - spec/fixtures/b/1.rb
159
163
  - spec/json_formatter_spec.rb
160
164
  - spec/parser_spec.rb
161
165
  - spec/rake_task_spec.rb
@@ -164,4 +168,3 @@ test_files:
164
168
  - spec/style_check_spec.rb
165
169
  - spec/threshold_check_spec.rb
166
170
  - spec/violation_formatter_spec.rb
167
- has_rdoc: false