koality 1.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.
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ describe Koality::Runner::Cane do
4
+
5
+ let(:options) do
6
+ Koality::Options.new({
7
+ :abc_file_pattern => '{app,lib}/**/.rb',
8
+ :abc_threshold => 15,
9
+ :abc_enabled => true,
10
+
11
+ :style_file_pattern => '{app,lib}/**/.rb',
12
+ :style_line_length_threshold => 80,
13
+ :style_enabled => true,
14
+
15
+ :code_coverage_enabled => false,
16
+
17
+ :doc_file_pattern => '{app,lib}/**/.rb',
18
+ :doc_enabled => false,
19
+
20
+ :custom_thresholds => [[:>=, 'quality/foo', 42]],
21
+ :total_violations_threshold => 5
22
+ })
23
+ end
24
+ let(:runner) { runner = Koality::Runner::Cane.new options }
25
+
26
+ describe '.new' do
27
+ it 'translates Koality options into the format Cane expects' do
28
+ copts = runner.cane_options
29
+
30
+ copts[:threshold].should == [[:>=, 'quality/foo', 42]]
31
+
32
+ copts[:abc].should == {
33
+ :files => '{app,lib}/**/.rb',
34
+ :max => 15
35
+ }
36
+
37
+ copts[:style].should == {
38
+ :files => '{app,lib}/**/.rb',
39
+ :measure => 80,
40
+ }
41
+
42
+ copts[:doc].should be_nil
43
+ end
44
+ end
45
+
46
+ describe '#checkers' do
47
+ it 'returns all checkers which have configured options' do
48
+ runner.checkers.values.should include(
49
+ Cane::Runner::CHECKERS[:abc],
50
+ Cane::Runner::CHECKERS[:style],
51
+ Cane::Runner::CHECKERS[:threshold]
52
+ )
53
+ runner.checkers.values.should_not include(Cane::Runner::CHECKERS[:doc])
54
+ end
55
+ end
56
+
57
+ describe '#run_checker' do
58
+ let(:checker) { stub('checker', :violations => [:violation_1, :violation_2]) }
59
+ let(:reporter) { stub('reporter', :report => true) }
60
+
61
+ before do
62
+ Koality::Reporter::Cane.stubs(:start).yields(reporter)
63
+ runner.checkers[:abc].stubs(:new).returns(checker)
64
+ end
65
+
66
+ it 'builds and runs the specified checker' do
67
+ runner.checkers[:abc].expects(:new).with(runner.cane_options[:abc]).returns(checker)
68
+ checker.expects(:violations)
69
+
70
+ runner.run_checker(:abc)
71
+ end
72
+
73
+ it 'saves the violations' do
74
+ runner.run_checker(:abc)
75
+ runner.violations[:abc].should == [:violation_1, :violation_2]
76
+ end
77
+
78
+ it 'reports the violations' do
79
+ reporter.expects(:report).with(:abc, [:violation_1, :violation_2])
80
+ runner.run_checker(:abc)
81
+ end
82
+ end
83
+
84
+ describe '#run' do
85
+ before do
86
+ runner.stubs(:run_checker)
87
+ end
88
+
89
+ it 'clears the violations' do
90
+ runner.violations.expects(:clear)
91
+ runner.run
92
+ end
93
+
94
+ it 'runs each checker' do
95
+ runner.stubs(:checkers).returns({
96
+ :abc => (abc = stub('abc_checker')),
97
+ :style => (style = stub('style_checker'))
98
+ })
99
+
100
+ runner.expects(:run_checker).with(:abc)
101
+ runner.expects(:run_checker).with(:style)
102
+ runner.run
103
+ end
104
+
105
+ it 'returns whether or not the run was successful' do
106
+ runner.expects(:success?).returns(true)
107
+ runner.run.should eql(true)
108
+
109
+ runner.expects(:success?).returns(false)
110
+ runner.run.should eql(false)
111
+ end
112
+ end
113
+
114
+ describe '#success?' do
115
+ before do
116
+ runner.stubs(:violations).returns({:abc => [], :style => []})
117
+ end
118
+
119
+ it 'returns true if the total is not exceeded and each type is not exceeded' do
120
+ runner.expects(:exceeds_total_violations_threshold? => false)
121
+ runner.expects(:exceeds_violations_threshold? => false).twice
122
+
123
+ runner.success?.should be_true
124
+ end
125
+
126
+ it 'returns false if the total violations are exceeded' do
127
+ runner.expects(:exceeds_total_violations_threshold? => true)
128
+ runner.success?.should be_false
129
+ end
130
+
131
+ it 'returns false if the total is not exceeded but a single type does' do
132
+ runner.stubs(:exceeds_total_violations_threshold? => false)
133
+ runner.expects(:exceeds_violations_threshold?).with(:abc).returns(false)
134
+ runner.expects(:exceeds_violations_threshold?).with(:style).returns(true)
135
+ runner.success?.should be_false
136
+ end
137
+ end
138
+
139
+ end
@@ -0,0 +1,64 @@
1
+ require 'pathname'
2
+ require 'spec_helper'
3
+
4
+ describe Koality::Runner::RailsBestPractices do
5
+
6
+ let(:options) do
7
+ Koality::Options.new({
8
+ :rails_bp_accept_patterns => %w(app/controllers/.+\\.rb),
9
+ :rails_bp_ignore_patterns => [/app\/helpers\/foo_helper\.rb/],
10
+ :rails_bp_error_file => 'rails_bp_errors',
11
+ :output_directory => 'quality'
12
+ })
13
+ end
14
+ let(:runner) { runner = Koality::Runner::RailsBestPractices.new options }
15
+
16
+ describe '.new' do
17
+ it 'figures out the output file path' do
18
+ runner.output_file.should == options.output_file(:rails_bp_error_file)
19
+ end
20
+
21
+ it 'translates the options into what RBP expects' do
22
+ rbp_opts = runner.rbp_options
23
+
24
+ rbp_opts['only'].should == [Regexp.new("app/controllers/.+\\.rb")]
25
+ rbp_opts['except'].should == [/app\/helpers\/foo_helper\.rb/]
26
+ end
27
+ end
28
+
29
+ describe '#run' do
30
+ let(:reporter) { stub('reporter', :report => true) }
31
+ let(:rbp) { rbp = stub('RailsBestPractices', :analyze => true, :errors => []) }
32
+
33
+ before do
34
+ FileUtils.mkdir_p options.output_directory
35
+ Koality::Reporter::RailsBestPractices.stubs(:start).yields(reporter)
36
+ RailsBestPractices::Analyzer.stubs(:new).returns(rbp)
37
+ end
38
+
39
+ it 'runs a RBP analyzer with the translated options' do
40
+ RailsBestPractices::Analyzer.expects(:new).with('.', runner.rbp_options).returns(rbp)
41
+ rbp.expects(:analyze)
42
+
43
+ runner.run
44
+ end
45
+
46
+ it 'creates a file with the number of failures from the run' do
47
+ errors = [stub('error')] * rand(5)
48
+ rbp.stubs(:errors).returns(errors)
49
+
50
+ runner.run
51
+
52
+ Pathname.new(runner.output_file).read.should == errors.count.to_s
53
+ end
54
+
55
+ it 'reports the errors' do
56
+ errors = [stub('error')] * rand(5)
57
+ rbp.stubs(:errors).returns(errors)
58
+
59
+ reporter.expects(:report).with(errors)
60
+ runner.run
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'koality/simplecov/formatter'
3
+
4
+ describe Koality::SimpleCov::Formatter do
5
+
6
+ let(:formatter) { Koality::SimpleCov::Formatter.new }
7
+ let(:result) do
8
+ stub('result', :source_files => stub('source', :covered_percent => 99.999))
9
+ end
10
+
11
+ describe '#format' do
12
+ before do
13
+ SimpleCov::Formatter::HTMLFormatter.any_instance.stubs(:format)
14
+ end
15
+
16
+ it 'runs the HTML formatter' do
17
+ html_formatter = stub('html')
18
+ html_formatter.expects(:format).with(result)
19
+ SimpleCov::Formatter::HTMLFormatter.stubs(:new => html_formatter)
20
+
21
+ formatter.format(result)
22
+ end
23
+
24
+ it 'ensures that the output directory exists' do
25
+ Koality.options.expects(:ensure_output_directory_exists)
26
+ formatter.format(result)
27
+ end
28
+
29
+ it 'outputs the covered percent to the correct file' do
30
+ formatter.format(result)
31
+ output_file = Pathname.new(Koality.options.output_file(:code_coverage_file))
32
+ output_file.read.should == '99.999'
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Koality do
4
+
5
+ let(:options) do
6
+ Koality::Options.new({
7
+ :output_directory => 'quality'
8
+ })
9
+ end
10
+
11
+ before do
12
+ Koality.stubs(:options).returns(options)
13
+ end
14
+
15
+ describe '.run' do
16
+ before do
17
+ Koality.stubs(:run_rails_bp => true, :run_cane => true)
18
+ end
19
+
20
+ it 'makes sure the output_directory exists' do
21
+ FileUtils.expects(:mkdir_p).with('quality')
22
+ Koality.run
23
+ end
24
+
25
+ it 'runs RailsBestPractices with the passed options if enabled' do
26
+ options.stubs(:rails_bp_enabled?).returns(true)
27
+ Koality.expects(:run_rails_bp)
28
+ Koality.run
29
+ end
30
+
31
+ it 'does not run RailsBestPractices if disabled' do
32
+ options.stubs(:rails_bp_enabled?).returns(false)
33
+ Koality.expects(:run_rails_bp).never
34
+ Koality.run
35
+ end
36
+
37
+ it 'runs Cane with the passed options' do
38
+ Koality.expects(:run_cane).returns(true)
39
+ Koality.run
40
+ end
41
+
42
+ it 'aborts if the abort_on_failure flag is set and the run was not successful' do
43
+ options[:abort_on_failure] = true
44
+ Koality.stubs(:run_cane).returns(false)
45
+ Koality.expects(:abort)
46
+
47
+ Koality.run
48
+ end
49
+
50
+ it 'does not abort if the abort_on_failure flag is set and the run was successful' do
51
+ options[:abort_on_failure] = true
52
+ Koality.stubs(:run_cane).returns(true)
53
+ Koality.expects(:abort).never
54
+
55
+ Koality.run
56
+ end
57
+
58
+ it 'does not abort if the abort_on_failure flag is set to false' do
59
+ options[:abort_on_failure] = false
60
+ Koality.stubs(:run_cane).returns(false)
61
+ Koality.expects(:abort).never
62
+
63
+ Koality.run
64
+ end
65
+ end
66
+
67
+ describe '.run_rails_bp' do
68
+ it 'runs the runner with the passed in options' do
69
+ rbp = mock('RBP', :run => true)
70
+ Koality::Runner::RailsBestPractices.expects(:new).with(options).returns(rbp)
71
+
72
+ Koality.run_rails_bp
73
+ end
74
+ end
75
+
76
+ describe '.run_cane' do
77
+ it 'runs the runner with the passed in options' do
78
+ cane = mock('cane', :run => true)
79
+ Koality::Runner::Cane.expects(:new).with(options).returns(cane)
80
+
81
+ Koality.run_cane
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift "../lib"
2
+
3
+ require 'rspec'
4
+ require 'koality'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ config.color_enabled = true
12
+ config.mock_with :mocha
13
+
14
+ config.formatter = :progress
15
+ config.color_enabled = true
16
+ config.filter_run :focused => true
17
+ config.run_all_when_everything_filtered = true
18
+ config.alias_example_to :fit, :focused => true
19
+ config.alias_example_to :they
20
+ end
@@ -0,0 +1,43 @@
1
+ module Kernel
2
+ class << self
3
+
4
+ def with_warnings(flag, &block)
5
+ old_verbose, $VERBOSE = $VERBOSE, flag
6
+ yield
7
+ ensure
8
+ $VERBOSE = old_verbose
9
+ end
10
+
11
+ def silence_warnings(&block)
12
+ with_warnings(nil, &block)
13
+ end
14
+
15
+ end
16
+ end
17
+
18
+ class Object
19
+ def self.with_constants(constants, &block)
20
+ old_constants = Hash.new
21
+ missing_constants = []
22
+
23
+ constants.each do |constant, val|
24
+ if const_defined?(constant)
25
+ old_constants[constant] = const_get(constant)
26
+ else
27
+ missing_constants << constant
28
+ end
29
+
30
+ Kernel::silence_warnings{ const_set(constant, val) }
31
+ end
32
+
33
+ yield
34
+
35
+ old_constants.each do |constant, val|
36
+ Kernel::silence_warnings{ const_set(constant, val) }
37
+ end
38
+
39
+ missing_constants.each do |constant|
40
+ Kernel::silence_warnings{ remove_const(constant) }
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: koality
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jared Pace
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails_best_practices
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.9'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.9'
30
+ - !ruby/object:Gem::Dependency
31
+ name: simplecov
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.6'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.6'
46
+ - !ruby/object:Gem::Dependency
47
+ name: cane
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: terminal-table
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.4'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.4'
78
+ - !ruby/object:Gem::Dependency
79
+ name: term-ansicolor
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '2.10'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '2.10'
110
+ - !ruby/object:Gem::Dependency
111
+ name: mocha
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.11'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '0.11'
126
+ description: Runs opinionated code quality tools as part of you test stuite
127
+ email:
128
+ - jared@thinkrelevance.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE
136
+ - README.md
137
+ - Rakefile
138
+ - koality.gemspec
139
+ - lib/koality.rb
140
+ - lib/koality/options.rb
141
+ - lib/koality/rake_task.rb
142
+ - lib/koality/reporter/base.rb
143
+ - lib/koality/reporter/cane.rb
144
+ - lib/koality/reporter/rails_best_practices.rb
145
+ - lib/koality/runner/cane.rb
146
+ - lib/koality/runner/rails_best_practices.rb
147
+ - lib/koality/simplecov.rb
148
+ - lib/koality/simplecov/formatter.rb
149
+ - lib/koality/version.rb
150
+ - spec/koality/options_spec.rb
151
+ - spec/koality/rake_task_spec.rb
152
+ - spec/koality/runner/cane_spec.rb
153
+ - spec/koality/runner/rails_best_practices_spec.rb
154
+ - spec/koality/simplecov/formatter_spec.rb
155
+ - spec/koality_spec.rb
156
+ - spec/spec_helper.rb
157
+ - spec/support/with_constants.rb
158
+ homepage: https://github.com/relevance/koality
159
+ licenses: []
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 1.8.23
179
+ signing_key:
180
+ specification_version: 3
181
+ summary: Runs opinionated code quality tools as part of you test stuite
182
+ test_files:
183
+ - spec/koality/options_spec.rb
184
+ - spec/koality/rake_task_spec.rb
185
+ - spec/koality/runner/cane_spec.rb
186
+ - spec/koality/runner/rails_best_practices_spec.rb
187
+ - spec/koality/simplecov/formatter_spec.rb
188
+ - spec/koality_spec.rb
189
+ - spec/spec_helper.rb
190
+ - spec/support/with_constants.rb