いくつかのコミット フックを git リポジトリに追加しようとしています。Rspec を活用して、コミットするたびに実行されるコミット メッセージ仕様を作成したいと考えています。「spec」コマンドの外で rspec を実行する方法を見つけましたが、興味深い問題が発生しました。
これが私の現在のコードです:
.git/hooks/commit-msg
#!/usr/bin/env ruby
require 'rubygems'
require 'spec/autorun'
message = File.read(ARGV[0])
describe "failing" do
it "should fail" do
true.should == false
end
end
これは、describe 呼び出しに到達したときにエラーをスローしています。基本的に、受信したコミット メッセージは、spec を読み込んで実行するファイルであると考えます。これが実際のエラーです
./.git/COMMIT_EDITMSG:1: undefined local variable or method `commit-message-here' for main:Object (NameError)
from /Users/roykolak/.gem/ruby/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in `load'
from /Users/roykolak/.gem/ruby/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in `load_files'
from /Users/roykolak/.gem/ruby/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `each'
from /Users/roykolak/.gem/ruby/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `load_files'
from /Users/roykolak/.gem/ruby/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:133:in `run_examples'
from /Users/roykolak/.gem/ruby/1.8/gems/rspec-1.3.0/lib/spec/runner.rb:61:in `run'
from /Users/roykolak/.gem/ruby/1.8/gems/rspec-1.3.0/lib/spec/runner.rb:45:in `autorun'
from .git/hooks/commit-msg:12
ファイルをロードしないようにrspecに指示する方法を探しています。独自のスペック ランナーを作成する必要があるのではないかと疑っています。rspec-1.3.0/lib/spec/runner/example_group_runner.rb でこれらの行を表示した後、この結論に達しました
def load_files(files)
$KCODE = 'u' if RUBY_VERSION.to_f < 1.9
# It's important that loading files (or choosing not to) stays the
# responsibility of the ExampleGroupRunner. Some implementations (like)
# the one using DRb may choose *not* to load files, but instead tell
# someone else to do it over the wire.
files.each do |file|
load file
end
end
しかし、その前にフィードバックをお願いします。何かご意見は?