我想添加一些提交鉤子到我的git倉庫。我想利用Rspec並創建每次提交時都會運行的提交消息規範。我已經想出瞭如何在'spec'命令之外運行rspec,但是現在我有一個有趣的問題。告訴rspec不加載文件
這裏是我當前的代碼:
的.git /鉤/提交-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
當它到達的描述呼叫這是拋出一個錯誤。基本上,它認爲它收到的提交消息是加載和運行規格的文件。這是實際的錯誤
./.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不加載文件。我有一個懷疑,我需要創建我自己的spec跑步者。我得出這一結論在rspec的-1.3.0/lib目錄/規格/跑步/ 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
查看這些行之後,但,我想一些反饋我這樣做了。有什麼想法嗎?
感謝您的想法克里斯。我想正是因爲這個原因使用rspec:匹配器,組織,報告,通過/失敗。 我希望能夠運行如下檢查:「提交消息的第一行應少於51個字符」或「消息應包含錯誤編號」等等...... rspec給我所有這些功能,加上統一的(和熟悉的)報告輸出 – 2010-07-12 03:17:05