Skip to content

Commit ed26f3c

Browse files
Dan Rabinowitzsds
Dan Rabinowitz
authored andcommitted
Add minitest pre-push hook
1 parent daff6eb commit ed26f3c

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

config/default.yml

+6
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,12 @@ PrePush:
783783
description: 'Running RSpec test suite'
784784
required_executable: 'rspec'
785785

786+
Minitest:
787+
enabled: false
788+
description: 'Running Minitest test suite'
789+
command: ['ruby', '-Ilib:test', 'test']
790+
required_library: 'minitest'
791+
786792
# Hooks that run during `git rebase`, before any commits are rebased.
787793
# If a hook fails, the rebase is aborted.
788794
PreRebase:
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

0 commit comments

Comments
 (0)