Skip to content

Commit

Permalink
Run specs using Bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk committed Sep 9, 2016
1 parent 2c0e1a6 commit cbfc103
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1 +1 @@
test/tmp
spec/tmp
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--color
12 changes: 7 additions & 5 deletions .travis.yml
Expand Up @@ -3,16 +3,18 @@ go:
- '1.6'

before_install:
# Install Bats
- sudo add-apt-repository ppa:duggan/bats -y
- sudo apt-get update -q
- sudo apt-get install -q bats
# Setup Glide
- go get github.com/Masterminds/glide

install:
- glide install
- go build

before_script:
# Install Ruby and Bundler
- sudo apt-get -q install ruby
- gem install bundler
- bundle install

script:
- bats $(find test -name "*_test.sh")
- bundle exec rspec
3 changes: 3 additions & 0 deletions Gemfile
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'rspec'
26 changes: 26 additions & 0 deletions Gemfile.lock
@@ -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
76 changes: 76 additions & 0 deletions spec/pre_commit_spec.rb
@@ -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.
55 changes: 0 additions & 55 deletions test/pre_commit_test.sh

This file was deleted.

0 comments on commit cbfc103

Please sign in to comment.