polishgeeks-dev-tools 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +27 -30
- data/Rakefile +1 -1
- data/lib/polishgeeks-dev-tools.rb +26 -20
- data/lib/polishgeeks/dev-tools/{command → commands}/allowed_extensions.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/base.rb +15 -25
- data/lib/polishgeeks/dev-tools/{command → commands}/brakeman.rb +4 -2
- data/lib/polishgeeks/dev-tools/{command → commands}/empty_method.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/empty_method/file_parser.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/empty_method/string_refinements.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/examples_comparator.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/expires_in.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/final_blank_line.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/haml_lint.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/readme.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/rspec.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/rspec_files_names.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/rspec_files_structure.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/rubocop.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/rubycritic.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command/coverage.rb → commands/simplecov.rb} +22 -9
- data/lib/polishgeeks/dev-tools/{command → commands}/tasks_files_names.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/yard.rb +1 -1
- data/lib/polishgeeks/dev-tools/{command → commands}/yml_parser.rb +1 -1
- data/lib/polishgeeks/dev-tools/config.rb +0 -16
- data/lib/polishgeeks/dev-tools/errors.rb +25 -0
- data/lib/polishgeeks/dev-tools/logger.rb +7 -12
- data/lib/polishgeeks/dev-tools/runner.rb +2 -1
- data/lib/polishgeeks/dev-tools/validators/base.rb +26 -0
- data/lib/polishgeeks/dev-tools/validators/rails.rb +12 -0
- data/lib/polishgeeks/dev-tools/validators/simplecov.rb +20 -0
- data/lib/polishgeeks/dev-tools/version.rb +1 -1
- data/polishgeeks_dev_tools.gemspec +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/allowed_extensions_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/commands/base_spec.rb +55 -0
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/brakeman_spec.rb +10 -9
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/empty_method/file_parser_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/empty_method/string_refinements_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/empty_method_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/examples_comparator_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/expires_in_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/final_blank_line_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/haml_lint_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/readme_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/rspec_files_names_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/rspec_files_structure_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/rspec_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/rubocop_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/rubycritic_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command/coverage_spec.rb → commands/simplecov_spec.rb} +28 -15
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/tasks_files_names_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/yard_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/{command → commands}/yml_parser_spec.rb +1 -1
- data/spec/lib/polishgeeks/dev-tools/config_spec.rb +0 -18
- data/spec/lib/polishgeeks/dev-tools/errors_spec.rb +15 -0
- data/spec/lib/polishgeeks/dev-tools/logger_spec.rb +3 -3
- data/spec/lib/polishgeeks/dev-tools/runner_spec.rb +4 -1
- data/spec/lib/polishgeeks/dev-tools/validators/base_spec.rb +34 -0
- data/spec/lib/polishgeeks/dev-tools/validators/rails_spec.rb +21 -0
- data/spec/lib/polishgeeks/dev-tools/validators/simplecov_spec.rb +34 -0
- metadata +78 -69
- data/lib/polishgeeks/dev-tools/command/simplecov.rb +0 -32
- data/spec/lib/polishgeeks/dev-tools/command/base_spec.rb +0 -127
- data/spec/lib/polishgeeks/dev-tools/command/simplecov_spec.rb +0 -53
@@ -1,13 +1,14 @@
|
|
1
1
|
module PolishGeeks
|
2
2
|
module DevTools
|
3
|
-
module
|
3
|
+
module Commands
|
4
4
|
# Command wrapper for Simple code coverage analysing
|
5
5
|
# It informs us if we didn't reach a proper code coverage level
|
6
|
-
class
|
6
|
+
class Simplecov < Base
|
7
7
|
self.type = :validator
|
8
|
+
self.validators = [
|
9
|
+
Validators::Simplecov
|
10
|
+
]
|
8
11
|
|
9
|
-
# Regexp used to match code coverage level
|
10
|
-
MATCH_REGEXP = /\(\d+.\d+\%\) covered/
|
11
12
|
# Regexp used to match float number from coverage
|
12
13
|
NUMBER_REGEXP = /(\d+[.]\d+)/
|
13
14
|
|
@@ -19,23 +20,35 @@ module PolishGeeks
|
|
19
20
|
# Executes this command
|
20
21
|
# @return [String] command output
|
21
22
|
def execute
|
22
|
-
@output = stored_output.rspec[*MATCH_REGEXP]
|
23
|
+
@output = stored_output.rspec[*Validators::Simplecov::MATCH_REGEXP]
|
23
24
|
end
|
24
25
|
|
25
26
|
# @return [Boolean] true if code coverage level is higher or equal to expected
|
26
27
|
def valid?
|
27
|
-
to_f >=
|
28
|
+
to_f >= threshold
|
28
29
|
end
|
29
30
|
|
30
31
|
# @return [String] default label for this command
|
31
32
|
def label
|
32
|
-
"
|
33
|
+
"SimpleCov covered #{to_f}%, required #{threshold}%"
|
33
34
|
end
|
34
35
|
|
35
36
|
# @return [String] message that should be printed when code coverage level is not met
|
36
37
|
def error_message
|
37
|
-
|
38
|
-
|
38
|
+
'SimpleCov coverage level needs to be ' \
|
39
|
+
"#{threshold}%#{threshold == limit ? '' : ' or more'}, was #{to_f}%"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# @return [Float] desired threshold
|
45
|
+
def threshold
|
46
|
+
DevTools.config.simplecov_threshold.to_f
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [Float] maximum threshold value
|
50
|
+
def limit
|
51
|
+
100.0
|
39
52
|
end
|
40
53
|
end
|
41
54
|
end
|
@@ -48,7 +48,6 @@ module PolishGeeks
|
|
48
48
|
tasks_files_names
|
49
49
|
rspec
|
50
50
|
simplecov
|
51
|
-
coverage
|
52
51
|
yard
|
53
52
|
examples_comparator
|
54
53
|
rubycritic
|
@@ -77,24 +76,9 @@ module PolishGeeks
|
|
77
76
|
def self.setup(&block)
|
78
77
|
self.config = new
|
79
78
|
|
80
|
-
config.detect_framework
|
81
|
-
|
82
79
|
block.call(config)
|
83
80
|
config.freeze
|
84
81
|
end
|
85
|
-
|
86
|
-
# Detects if we use Rails, Sinatra or nothing
|
87
|
-
# We need to set it because some of the commands might work only for Rails
|
88
|
-
# or Sinatra (like brakeman for example - only Rails)
|
89
|
-
def detect_framework
|
90
|
-
define_singleton_method :rails? do
|
91
|
-
!defined?(Rails).nil?
|
92
|
-
end
|
93
|
-
|
94
|
-
define_singleton_method :sinatra? do
|
95
|
-
!defined?(App).nil?
|
96
|
-
end
|
97
|
-
end
|
98
82
|
end
|
99
83
|
end
|
100
84
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PolishGeeks
|
2
|
+
module DevTools
|
3
|
+
# Module that encapsulates all the DevTools errrors
|
4
|
+
module Errors
|
5
|
+
# Base class for all DevTools errors
|
6
|
+
class BaseError < StandardError; end
|
7
|
+
|
8
|
+
# Raised when we want to run method that was not implemented and we have just a stub
|
9
|
+
# from parent class
|
10
|
+
class NotImplementedError < BaseError; end
|
11
|
+
|
12
|
+
# Raised when we want to run an command for which pre validation does not pass
|
13
|
+
class PreCommandValidationError < BaseError; end
|
14
|
+
|
15
|
+
# Raised when validators are defined with an unsupported type
|
16
|
+
class InvalidValidatorsTypeError < BaseError; end
|
17
|
+
|
18
|
+
# Raised when it is a type of task that we don't recognize
|
19
|
+
class UnknownTaskType < BaseError; end
|
20
|
+
|
21
|
+
# Raised when any of tasks fail
|
22
|
+
class RequirementsError < BaseError; end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -5,13 +5,8 @@ module PolishGeeks
|
|
5
5
|
# Regexp used to get only the class name without module names
|
6
6
|
CLASS_NAME_REGEXP = /^.*::/
|
7
7
|
|
8
|
-
# Raised when it is a type of task that we don't recognize
|
9
|
-
class UnknownTaskType < StandardError; end
|
10
|
-
# Raised when any of tasks fail
|
11
|
-
class RequirementsError < StandardError; end
|
12
|
-
|
13
8
|
# Method will print appropriate output with colors and comments
|
14
|
-
# @param [PolishGeeks::DevTools::
|
9
|
+
# @param [PolishGeeks::DevTools::Commands::Base] task that was executed
|
15
10
|
# @raise [PolishGeeks::DevTools::Logger::RequirementsError] raised when task
|
16
11
|
# has failed
|
17
12
|
# @example Log output of a current_task
|
@@ -21,7 +16,7 @@ module PolishGeeks
|
|
21
16
|
info(task)
|
22
17
|
else
|
23
18
|
fatal(task)
|
24
|
-
fail RequirementsError
|
19
|
+
fail Errors::RequirementsError
|
25
20
|
end
|
26
21
|
end
|
27
22
|
|
@@ -29,20 +24,20 @@ module PolishGeeks
|
|
29
24
|
|
30
25
|
# Will print message when task didn't fail while running
|
31
26
|
# @note Handles also generators that never fail
|
32
|
-
# @param [PolishGeeks::DevTools::
|
33
|
-
# @raise [PolishGeeks::DevTools::
|
27
|
+
# @param [PolishGeeks::DevTools::Commands::Base] task that was executed
|
28
|
+
# @raise [PolishGeeks::DevTools::Errors::UnknownTaskType] raised when task type is
|
34
29
|
# not supported (we don't know how to handle it)
|
35
30
|
def info(task)
|
36
31
|
msg = 'GENERATED' if task.class.generator?
|
37
32
|
msg = 'OK' if task.class.validator?
|
38
33
|
|
39
|
-
fail UnknownTaskType unless msg
|
34
|
+
fail Errors::UnknownTaskType unless msg
|
40
35
|
|
41
36
|
printf('%-40s %2s', "#{label(task)} ", "\e[32m#{msg}\e[0m\n")
|
42
37
|
end
|
43
38
|
|
44
39
|
# Will print message when task did fail while running
|
45
|
-
# @param [PolishGeeks::DevTools::
|
40
|
+
# @param [PolishGeeks::DevTools::Commands::Base] task that was executed
|
46
41
|
def fatal(task)
|
47
42
|
printf('%-30s %20s', "#{label(task)} ", "\e[31mFAILURE\e[0m\n\n")
|
48
43
|
puts task.error_message + "\n"
|
@@ -50,7 +45,7 @@ module PolishGeeks
|
|
50
45
|
|
51
46
|
# Generates a label describing a given task
|
52
47
|
# @note Will use a task class name if task doesn't respond to label method
|
53
|
-
# @param [PolishGeeks::DevTools::
|
48
|
+
# @param [PolishGeeks::DevTools::Commands::Base] task that was executed
|
54
49
|
# @return [String] label describing task
|
55
50
|
# @example Get label for a current_task task
|
56
51
|
# label(current_task) #=> 'Rubocop'
|
@@ -15,8 +15,9 @@ module PolishGeeks
|
|
15
15
|
next unless DevTools.config.public_send(:"#{command}?")
|
16
16
|
|
17
17
|
klass = command.to_s.gsub(/(?<=_|^)(\w)/, &:upcase).gsub(/(?:_)(\w)/, '\1')
|
18
|
-
cmd = Object.const_get("PolishGeeks::DevTools::
|
18
|
+
cmd = Object.const_get("PolishGeeks::DevTools::Commands::#{klass}").new
|
19
19
|
cmd.stored_output = output
|
20
|
+
cmd.ensure_executable!
|
20
21
|
cmd.execute
|
21
22
|
output.public_send(:"#{command}=", cmd.output)
|
22
23
|
logger.log(cmd)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PolishGeeks
|
2
|
+
module DevTools
|
3
|
+
# Module encapsulating all the validators that we use to check/verify code
|
4
|
+
module Validators
|
5
|
+
# Base class for all the validators
|
6
|
+
# @abstract Subclass and use
|
7
|
+
class Base
|
8
|
+
def initialize(stored_output)
|
9
|
+
@stored_output = stored_output
|
10
|
+
end
|
11
|
+
|
12
|
+
# This should be implemented in a subclass
|
13
|
+
# @return [Boolean] if validation check is valid or not
|
14
|
+
def valid?
|
15
|
+
fail Errors::NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
# @raise [PreCommandValidationError] when valid? return false
|
19
|
+
# @return [Boolean] if validation check is valid or not
|
20
|
+
def validate!
|
21
|
+
fail Errors::PreCommandValidationError unless valid?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PolishGeeks
|
2
|
+
module DevTools
|
3
|
+
module Validators
|
4
|
+
# It verifies if SimpleCov is available
|
5
|
+
class Simplecov < Base
|
6
|
+
# Regexp used to match code coverage from Simplecov generated output
|
7
|
+
MATCH_REGEXP = /\(\d+.\d+\%\) covered/
|
8
|
+
|
9
|
+
def valid?
|
10
|
+
Object.const_defined?('SimpleCov') || (!output.nil? && output.length > 0)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Searches if we have SimpleCov hooked to rspec
|
14
|
+
def output
|
15
|
+
@output ||= @stored_output.rspec[*MATCH_REGEXP]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe PolishGeeks::DevTools::Commands::Base do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#execute' do
|
7
|
+
let(:error) { PolishGeeks::DevTools::Errors::NotImplementedError }
|
8
|
+
it { expect { subject.execute }. to raise_error(error) }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#valid?' do
|
12
|
+
let(:error) { PolishGeeks::DevTools::Errors::NotImplementedError }
|
13
|
+
it { expect { subject.valid? }. to raise_error(error) }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#error_message' do
|
17
|
+
let(:output) { rand.to_s }
|
18
|
+
|
19
|
+
before do
|
20
|
+
subject.instance_variable_set('@output', output)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'by default should equal raw output' do
|
24
|
+
expect(subject.error_message).to eq output
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#ensure_executable!' do
|
29
|
+
context 'when there are validators' do
|
30
|
+
let(:validator_class) { PolishGeeks::DevTools::Validators::Base }
|
31
|
+
|
32
|
+
before do
|
33
|
+
expect(described_class)
|
34
|
+
.to receive(:validators)
|
35
|
+
.and_return([validator_class])
|
36
|
+
|
37
|
+
expect_any_instance_of(validator_class)
|
38
|
+
.to receive(:valid?)
|
39
|
+
.and_return(true)
|
40
|
+
end
|
41
|
+
|
42
|
+
it { expect { subject.ensure_executable! }.not_to raise_error }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when we dont require any validators' do
|
46
|
+
before do
|
47
|
+
expect(described_class)
|
48
|
+
.to receive(:validators)
|
49
|
+
.and_return([])
|
50
|
+
end
|
51
|
+
|
52
|
+
it { expect { subject.ensure_executable! }.not_to raise_error }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe PolishGeeks::DevTools::
|
4
|
-
subject { described_class
|
5
|
-
let(:config) { double(rails?: true) }
|
6
|
-
|
7
|
-
before do
|
8
|
-
expect(PolishGeeks::DevTools)
|
9
|
-
.to receive(:config)
|
10
|
-
.and_return(config)
|
3
|
+
RSpec.describe PolishGeeks::DevTools::Commands::Brakeman do
|
4
|
+
subject { described_class }
|
11
5
|
|
12
|
-
|
6
|
+
describe '#validators' do
|
7
|
+
it 'should work only when we have Rails framework' do
|
8
|
+
expect(subject.validators).to eq [PolishGeeks::DevTools::Validators::Rails]
|
9
|
+
end
|
13
10
|
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.describe PolishGeeks::DevTools::Commands::Brakeman do
|
14
|
+
subject { described_class.new }
|
14
15
|
|
15
16
|
describe '#execute' do
|
16
17
|
context 'when we run brakeman' do
|