File tree 3 files changed +60
-0
lines changed
lib/overcommit/hook/pre_push
spec/overcommit/hook/pre_push
3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -783,6 +783,12 @@ PrePush:
783
783
description : ' Running RSpec test suite'
784
784
required_executable : ' rspec'
785
785
786
+ Minitest :
787
+ enabled : false
788
+ description : ' Running Minitest test suite'
789
+ command : ['ruby', '-Ilib:test', 'test']
790
+ required_library : ' minitest'
791
+
786
792
# Hooks that run during `git rebase`, before any commits are rebased.
787
793
# If a hook fails, the rebase is aborted.
788
794
PreRebase :
Original file line number Diff line number Diff line change
1
+ module Overcommit ::Hook ::PrePush
2
+ # Runs `minitest` test suite before push
3
+ #
4
+ # @see https://github.com/seattlerb/minitest
5
+ class Minitest < Base
6
+ def run
7
+ result = execute ( command )
8
+ return :pass if result . success?
9
+
10
+ output = result . stdout + result . stderr
11
+ [ :fail , output ]
12
+ end
13
+ end
14
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Overcommit ::Hook ::PrePush ::Minitest do
4
+ let ( :config ) { Overcommit ::ConfigurationLoader . default_configuration }
5
+ let ( :context ) { double ( 'context' ) }
6
+ subject { described_class . new ( config , context ) }
7
+
8
+ context 'when minitest exits successfully' do
9
+ let ( :result ) { double ( 'result' ) }
10
+
11
+ before do
12
+ result . stub ( :success? ) . and_return ( true )
13
+ subject . stub ( :execute ) . and_return ( result )
14
+ end
15
+
16
+ it { should pass }
17
+ end
18
+
19
+ context 'when minitest exits unsuccessfully' do
20
+ let ( :result ) { double ( 'result' ) }
21
+
22
+ before do
23
+ result . stub ( :success? ) . and_return ( false )
24
+ subject . stub ( :execute ) . and_return ( result )
25
+ end
26
+
27
+ context 'with a runtime error' do
28
+ before do
29
+ result . stub ( stdout : '' , stderr : <<-EOS )
30
+ 1) Error:
31
+ FooTest#test_: foo should bar. :
32
+ RuntimeError:
33
+ test/model/foo_test.rb:1:in `block (2 levels) in <class:FooTest>'
34
+ EOS
35
+ end
36
+
37
+ it { should fail_hook }
38
+ end
39
+ end
40
+ end
You can’t perform that action at this time.
0 commit comments