Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
114 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
test/tmp | ||
spec/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rspec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.2.5) | ||
rspec (3.5.0) | ||
rspec-core (~> 3.5.0) | ||
rspec-expectations (~> 3.5.0) | ||
rspec-mocks (~> 3.5.0) | ||
rspec-core (3.5.3) | ||
rspec-support (~> 3.5.0) | ||
rspec-expectations (3.5.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.5.0) | ||
rspec-mocks (3.5.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.5.0) | ||
rspec-support (3.5.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
rspec | ||
|
||
BUNDLED WITH | ||
1.12.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require 'fileutils' | ||
|
||
describe 'pre-commit' do | ||
let(:tmp_dir) { 'spec/tmp' } | ||
let(:hook_dir) { "#{tmp_dir}/.quickhook/pre-commit" } | ||
|
||
def system(command) | ||
Kernel.system(command) || exit($?.exitstatus) | ||
end | ||
|
||
def write_file(path, contents) | ||
File.open(path, 'w') do |f| | ||
f.write contents | ||
end | ||
end | ||
|
||
Result = Struct.new(:status, :output) do | ||
def lines | ||
self.output.strip.split("\n") | ||
end | ||
end | ||
|
||
def run_hook | ||
Dir.chdir(tmp_dir) do | ||
output = `../../quickhook hook pre-commit --no-color` | ||
|
||
Result.new $?.exitstatus, output | ||
end | ||
end | ||
|
||
before do | ||
FileUtils.mkdir_p tmp_dir | ||
FileUtils.mkdir_p hook_dir | ||
|
||
Dir.chdir(tmp_dir) do | ||
system 'git init --quiet .' | ||
system 'echo "Changed!" > example' | ||
system 'git add example' | ||
end | ||
end | ||
|
||
after do | ||
FileUtils.rm_r [ | ||
'spec/tmp/.git', | ||
'spec/tmp/.quickhook', | ||
'spec/tmp/example', | ||
] | ||
end | ||
|
||
it "fails if any of the hooks failed" do | ||
write_file "#{hook_dir}/fails", "#!/bin/bash \n echo \"failed\" \n exit 1" | ||
system "chmod +x #{hook_dir}/*" | ||
|
||
result = run_hook | ||
|
||
expect(result.status).not_to eq 0 | ||
expect(result.lines).to eq([ | ||
'fails: fail', | ||
'failed', | ||
]) | ||
end | ||
|
||
it "passes if all hooks pass" do | ||
write_file "#{hook_dir}/passes1", "#!/bin/bash \n echo \"passed\" \n exit 0" | ||
write_file "#{hook_dir}/passes2", "#!/bin/bash \n echo \"passed\" \n exit 0" | ||
system "chmod +x #{hook_dir}/*" | ||
|
||
result = run_hook | ||
|
||
expect(result.status).to eq 0 | ||
expect(result.lines.sort).to eq([ | ||
'passes1: ok', | ||
'passes2: ok', | ||
]) | ||
end | ||
end |
File renamed without changes.
This file was deleted.
Oops, something went wrong.