我是 ruby/rails 的新手,目前正在将 railstutorial 书作为大学课程的一部分。我正在使用 ubuntu 11.04、ruby 1.9.2p290 和 Rails 3.0.9、watchr (0.7)、rspec (2.6.0)、rspec-formatter-webkit (2.1.3) 和 spork (0.9.0.rc)。
在 github 上我遇到了这个gem,我认为使用它会非常好。所以基本上我想要实现的是持续的自动化测试,如果完成了通知,并从中生成漂亮的 html 输出。
所以我尝试的是我写了这个观察者脚本:
require 'nokogiri'
require 'open-uri'
watch("spec/.*/*_spec.rb") do |match|
run_spec match[0]
end
watch("app/(.*/.*).rb") do |match|
run_spec %{spec/#{match[1]}_spec.rb}
end
def run_spec(file)
unless File.exist?(file)
puts "#{file} does not exist"
return
end
puts "Running #{file}"
result = `rspec -r rspec/core/formatters/webkit -f RSpec::Core::Formatters::WebKit #{file}`
File.open('out.html', 'w') do |f|
f.puts result
end
notify(result)
puts "DONE"
end
def send_notify title, msg, img, pri='low', time=5000
`notify-send -i #{img} -u #{pri} -t #{time} '#{msg}'`
end
def notify(result)
output = result
doc = Nokogiri::HTML(result)
doc.xpath('//div[@id = "summary"]').each do |node|
output = node.text.split.join(" ")
end
folder = "~/Pictures/autotest/"
if output =~ /([123456789]|[\d]{2,})\sfailed/
send_notify "FAIL:", "#{output}", folder+"rails_fail.png", 'critical', 20000
elsif output =~ /[1-9]\d*\spending?/
send_notify "PENDING:", "#{output}", folder+"rails_pending.png", 'normal', 15000
else
send_notify "PASS:", "#{output}", folder+"rails_ok.png"
end
end
处理通知,并在测试时生成输出。
如果我用 watchr 运行它,一切都很好并且工作正常,但是测试当然需要很长时间。
问题出现在这里:如果我尝试使用 spork 来加快测试速度,我会收到一堆错误,从 LoadError 开始:
Exception encountered: #<LoadError: no such file to load -- rspec/core/formatters/webkit>
backtrace:
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `block in require'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `block in load_dependency'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in `new_constants_in'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `load_dependency'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:247:in `block in requires='
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:247:in `map'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:247:in `requires='
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration_options.rb:21:in `block in configure'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration_options.rb:20:in `each'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration_options.rb:20:in `configure'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:17:in `run'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/monkey/spork/test_framework/rspec.rb:5:in `run_tests'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/run_strategy/forking.rb:13:in `block in run'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/forker.rb:21:in `block in initialize'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/forker.rb:18:in `fork'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/forker.rb:18:in `initialize'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/run_strategy/forking.rb:9:in `new'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/run_strategy/forking.rb:9:in `run'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/server.rb:47:in `run'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1518:in `perform'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
作为一个新手,这当然不会对我说什么。
有没有办法克服这个问题(或者当然以任何其他方式产生结果)?
任何帮助是极大的赞赏 :)