File tree 7 files changed +164
-0
lines changed
7 files changed +164
-0
lines changed Original file line number Diff line number Diff line change @@ -518,6 +518,7 @@ issue](https://github.com/brigade/overcommit/issues/238) for more details.
518
518
* [Pyflakes](lib/overcommit/hook/pre_commit/pyflakes.rb)
519
519
* [Pylint](lib/overcommit/hook/pre_commit/pylint.rb)
520
520
* [PythonFlake8](lib/overcommit/hook/pre_commit/python_flake8.rb)
521
+ * [RakeTarget](lib/overcommit/hook/pre_commit/rake_target.rb)
521
522
* [RailsBestPractices](lib/overcommit/hook/pre_commit/rails_best_practices.rb)
522
523
* [RailsSchemaUpToDate](lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb)
523
524
* [Reek](lib/overcommit/hook/pre_commit/reek.rb)
@@ -551,6 +552,7 @@ aborted.
551
552
* [Brakeman](lib/overcommit/hook/pre_push/brakeman.rb)
552
553
* [Minitest](lib/overcommit/hook/pre_push/minitest.rb)
553
554
* [ProtectedBranches](lib/overcommit/hook/pre_push/protected_branches.rb)
555
+ * [RakeTarget](lib/overcommit/hook/pre_push/rake_target.rb)
554
556
* [RSpec](lib/overcommit/hook/pre_push/r_spec.rb)
555
557
* [TestUnit](lib/overcommit/hook/pre_push/test_unit.rb)
556
558
Original file line number Diff line number Diff line change @@ -458,6 +458,16 @@ PreCommit:
458
458
install_command : ' pip install flake8'
459
459
include : ' **/*.py'
460
460
461
+ RakeTarget :
462
+ enabled : false
463
+ description : ' Run rake targets'
464
+ # targets:
465
+ # - 'lint'
466
+ # - 'validate'
467
+ # - '...'
468
+ required_executable : ' rake'
469
+ install_command : ' gem install rake'
470
+
461
471
RailsBestPractices :
462
472
enabled : false
463
473
description : ' Analyze with RailsBestPractices'
@@ -895,6 +905,16 @@ PrePush:
895
905
description : ' Run RSpec test suite'
896
906
required_executable : ' rspec'
897
907
908
+ RakeTarget :
909
+ enabled : false
910
+ description : ' Run rake targets'
911
+ # targets:
912
+ # - 'lint'
913
+ # - 'validate'
914
+ # - '...'
915
+ required_executable : ' rake'
916
+ install_command : ' gem install rake'
917
+
898
918
Minitest :
899
919
enabled : false
900
920
description : ' Run Minitest test suite'
Original file line number Diff line number Diff line change
1
+ require 'overcommit/hook/shared/rake_target'
2
+
3
+ module Overcommit ::Hook ::PreCommit
4
+ # Runs rake targets
5
+ #
6
+ # @see {Overcommit::Hook::Shared::RakeTarget}
7
+ class RakeTarget < Base
8
+ include Overcommit ::Hook ::Shared ::RakeTarget
9
+ end
10
+ end
Original file line number Diff line number Diff line change
1
+ require 'overcommit/hook/shared/rake_target'
2
+
3
+ module Overcommit ::Hook ::PrePush
4
+ # Runs rake targets
5
+ #
6
+ # @see {Overcommit::Hook::Shared::RakeTarget}
7
+ class RakeTarget < Base
8
+ include Overcommit ::Hook ::Shared ::RakeTarget
9
+ end
10
+ end
Original file line number Diff line number Diff line change
1
+ module Overcommit ::Hook ::Shared
2
+ # runs specified rake targets. It fails on the first non-
3
+ # successfull exit.
4
+ #
5
+ module RakeTarget
6
+ def run
7
+ targets = config [ 'targets' ]
8
+
9
+ if Array ( targets ) . empty?
10
+ raise 'RakeTarget: targets parameter is empty. Add at least one task to ' \
11
+ 'the targets parameter. Valid: Array of target names or String of ' \
12
+ 'target names'
13
+ end
14
+
15
+ targets . each do |task |
16
+ result = execute ( command + [ task ] )
17
+ unless result . success?
18
+ return :fail , "Rake target #{ task } :\n #{ result . stdout } "
19
+ end
20
+ end
21
+ :pass
22
+ end
23
+ end
24
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Overcommit ::Hook ::PreCommit ::RakeTarget do
4
+ let ( :config ) { Overcommit ::ConfigurationLoader . default_configuration }
5
+ let ( :context ) { double ( 'context' ) }
6
+ subject { described_class . new ( config , context ) }
7
+
8
+ context 'without targets parameters' do
9
+ let ( :result ) { double ( 'result' ) }
10
+ it 'raises' do
11
+ expect { subject . run } . to raise_error (
12
+ RuntimeError , /RakeTarget: targets parameter is empty.*/
13
+ )
14
+ end
15
+ end
16
+
17
+ context 'with targets parameter set' do
18
+ let ( :config ) do
19
+ super ( ) . merge ( Overcommit ::Configuration . new (
20
+ 'PreCommit' => {
21
+ 'RakeTarget' => {
22
+ 'targets' => [ 'test' ] ,
23
+ }
24
+ }
25
+ ) )
26
+ end
27
+ let ( :result ) { double ( 'result' ) }
28
+
29
+ context 'when rake exits successfully' do
30
+ before do
31
+ result . stub ( :success? ) . and_return ( true )
32
+ subject . stub ( :execute ) . and_return ( result )
33
+ result . stub ( :stdout ) . and_return ( 'ANYTHING' )
34
+ end
35
+
36
+ it { should pass }
37
+ end
38
+
39
+ context 'when rake exits unsuccessfully' do
40
+ before do
41
+ result . stub ( :success? ) . and_return ( false )
42
+ subject . stub ( :execute ) . and_return ( result )
43
+ result . stub ( :stdout ) . and_return ( 'ANYTHING' )
44
+ end
45
+
46
+ it { should fail_hook }
47
+ end
48
+ end
49
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Overcommit ::Hook ::PrePush ::RakeTarget do
4
+ let ( :config ) { Overcommit ::ConfigurationLoader . default_configuration }
5
+ let ( :context ) { double ( 'context' ) }
6
+ subject { described_class . new ( config , context ) }
7
+
8
+ context 'without targets parameters' do
9
+ let ( :result ) { double ( 'result' ) }
10
+ it 'raises' do
11
+ expect { subject . run } . to raise_error (
12
+ RuntimeError , /RakeTarget: targets parameter is empty.*/
13
+ )
14
+ end
15
+ end
16
+
17
+ context 'with targets parameter set' do
18
+ let ( :config ) do
19
+ super ( ) . merge ( Overcommit ::Configuration . new (
20
+ 'PrePush' => {
21
+ 'RakeTarget' => {
22
+ 'targets' => [ 'test' ] ,
23
+ }
24
+ }
25
+ ) )
26
+ end
27
+ let ( :result ) { double ( 'result' ) }
28
+
29
+ context 'when rake exits successfully' do
30
+ before do
31
+ result . stub ( :success? ) . and_return ( true )
32
+ subject . stub ( :execute ) . and_return ( result )
33
+ result . stub ( :stdout ) . and_return ( 'ANYTHING' )
34
+ end
35
+
36
+ it { should pass }
37
+ end
38
+
39
+ context 'when rake exits unsuccessfully' do
40
+ before do
41
+ result . stub ( :success? ) . and_return ( false )
42
+ subject . stub ( :execute ) . and_return ( result )
43
+ result . stub ( :stdout ) . and_return ( 'ANYTHING' )
44
+ end
45
+
46
+ it { should fail_hook }
47
+ end
48
+ end
49
+ end
You can’t perform that action at this time.
0 commit comments