Skip to content

Commit

Permalink
stop using Bundler, fix dependencies, improve loading warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Dec 18, 2013
1 parent c134280 commit d0695cb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 22 deletions.
14 changes: 2 additions & 12 deletions Gemfile
@@ -1,17 +1,7 @@
source "https://rubygems.org"

gem "rake"
gemspec

gem "execjs"
gem "rubocop", :platforms => [:ruby_19, :ruby_20]
gem "rubysl-singleton", :platforms => [:rbx]

group :development do
gem "guard"
gem "guard-minitest"
end

group :test do
gem "minitest"
gem "minitest-rg"
gem "minitest-around"
end
2 changes: 1 addition & 1 deletion Rakefile
@@ -1,7 +1,7 @@
require "rake/testtask"

Rake::TestTask.new do |test|
test.libs << "test"
test.libs << "test" << "lib"
test.pattern = "test/**/*_test.rb"
test.verbose = true
end
Expand Down
7 changes: 5 additions & 2 deletions lib/pre-commit/support/templates/pre-commit-hook
Expand Up @@ -16,8 +16,11 @@ ${cmd} -rrubygems -e '
begin
require "pre-commit"
true
rescue LoadError
$stderr.puts "pre-commit: WARNING: Skipping checks because the pre-commit gem is not installed. (Did you change your Ruby version?)"
rescue LoadError => e
$stderr.puts <<-MESSAGE
pre-commit: WARNING: Skipping checks because: #{e}
pre-commit: Did you set your Ruby version?
MESSAGE
false
end and PreCommit.run
'
7 changes: 6 additions & 1 deletion pre-commit.gemspec
Expand Up @@ -18,8 +18,13 @@ Gem::Specification.new do |s|
s.summary = "A slightly better git pre-commit hook"
s.description = "A git pre-commit hook written in ruby with a few more tricks up its sleeve"

s.add_dependency('execjs')
s.add_dependency('pluginator')
s.add_dependency_dependency('rake')
s.add_dependency_dependency('guard')
s.add_dependency_dependency('guard-minitest')
s.add_dependency_dependency('minitest')
s.add_dependency_dependency('minitest-rg')
s.add_dependency_dependency('minitest-around')

if s.respond_to? :specification_version then
s.specification_version = 3
Expand Down
8 changes: 4 additions & 4 deletions test/integration_test.rb
Expand Up @@ -41,8 +41,8 @@

it "can overwrite existing hook" do
write ".git/hooks/pre-commit", "XXX"
sh "ruby -I #{Bundler.root}/lib #{Bundler.root}/bin/pre-commit install"
read(".git/hooks/pre-commit").must_include "pre-commit gem"
sh "ruby -I #{project_dir}/lib #{project_dir}/bin/pre-commit install"
read(".git/hooks/pre-commit").must_include "pre-commit"
end

describe "local checks" do
Expand All @@ -67,7 +67,7 @@ def in_git_dir(&block)
Dir.mktmpdir(nil, ENV['TMPDIR'] || '/tmp') do |dir|
Dir.chdir(dir) do
sh "git init"
sh "git config pre-commit.ruby 'ruby -I #{Bundler.root}/lib'"
sh "git config pre-commit.ruby 'ruby #{ruby_includes}'"
install
yield
end
Expand All @@ -87,7 +87,7 @@ def sh(command, options={})
end

def install
sh "ruby -I #{Bundler.root}/lib #{Bundler.root}/bin/pre-commit install"
sh "ruby -I #{project_dir}/lib #{project_dir}/bin/pre-commit install"
assert File.exist?(".git/hooks/pre-commit"), "The hook file does not exist"
assert File.executable?(".git/hooks/pre-commit"), "The hook file is not executable"
sh "git commit -m Initial --allow-empty" # or travis fails with: No HEAD commit to compare with
Expand Down
12 changes: 10 additions & 2 deletions test/minitest_helper.rb
Expand Up @@ -3,14 +3,14 @@
require 'minitest/around'
require 'minitest/autorun'
require 'tmpdir'
$LOAD_PATH << File.expand_path("../../lib", __FILE__)
require 'pluginator'

class MiniTest::Unit::TestCase

protected

def test_filename(filename)
file_dir = File.expand_path('../files', __FILE__).sub("#{Bundler.root}/", "")
file_dir = File.expand_path('../files', __FILE__).sub("#{project_dir}/", "")
File.join(file_dir, filename)
end

Expand All @@ -28,4 +28,12 @@ def self.in_temp_dir
end
end
end

def ruby_includes
"-I #{Gem::Specification.find_by_name('pluginator').full_require_paths} -I #{project_dir}/lib"
end

def project_dir
File.expand_path("../../", __FILE__)
end
end

0 comments on commit d0695cb

Please sign in to comment.