Ubuntu と autotest と notify で快適テスト生活

まだ Test::Unit なんですが1http://blog.s21g.com/articles/913を参考に autotest + notify を導入してみました.

% sudo su -
# gem install ZenTest
# apt-get install libnotify-bin
# exit
% cp /var/lib/gems/1.8/gems/ZenTest-3.11.0/example_dot_autotest.rb ~/.autotest
% chmod 644 ~/.autotest

次に .autotest の修正.

# -*- ruby -*-

# require 'autotest/autoupdate'
# require 'autotest/camping'
# require 'autotest/cctray'
# require 'autotest/emacs'
# require 'autotest/email_notify'
# require 'autotest/fixtures'
# require 'autotest/growl'
# require 'autotest/heckle'
# require 'autotest/html_report'
# require 'autotest/jabber_notify'
# require 'autotest/kdenotify'
# require 'autotest/menu'
# require 'autotest/migrate'
require 'autotest/notify'
# require 'autotest/once'
# require 'autotest/pretty'
# require 'autotest/rcov'
require 'autotest/redgreen'
# require 'autotest/restart'
# require 'autotest/screen'
# require 'autotest/shame'
# require 'autotest/snarl'
# require 'autotest/timestamp'

# Autotest::AutoUpdate.sleep_time = o
# Autotest::AutoUpdate.update_cmd = o
# Autotest::CCTray.project_name = name
# Autotest::Emacs.command = o
# Autotest::EmailNotify.smtp_settings = o
# Autotest::EmailNotify.from = o
# Autotest::EmailNotify.recipients = o
# Autotest::EmailNotify.use_svn = o
# Autotest::EmailNotify.report_every_run = o
# Autotest::Growl.growl title, msg, pri = 0, img = nil
# Autotest::JabberNotify.recipients = o
# Autotest::JabberNotify.account = o
# Autotest::JabberNotify.password = o
# Autotest::JabberNotify.use_svn = o
# Autotest::JabberNotify.report_every_run = o
# Autotest::RCov.command = o
# Autotest::RCov.pattern = o
# Autotest::Shame.chat_app = o
# Autotest::Snarl.snarl title, msg, ico = nil

module Autotest::Notify
  def self.mod_notify title, msg, img, pri='low', time=10000
    `notify-send -i #{img} -u #{pri} -t #{time} '#{msg}'`
  end

  Autotest.add_hook :ran_command do |autotest|
    results = [autotest.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/)
    folder = "~/pics/"
    if output  =~ /[1-9]\d*\sfailures?/
      mod_notify "FAIL:", "#{output}", folder+"rails_fail.png", 'critical', 10000
    elsif output  =~ /[1-9]\d*\serrors?/
      mod_notify "PENDING:", "#{output}", folder+"rails_pending.png", 'normal', 10000
    else
      mod_notify "PASS:", "#{output}", folder+"rails_ok.png"
    end
  end
end

autotest でファイル修正のたびに該当テストが走るので,ちゃんとテスト書いておけばすぐに結果がわかります.

image


  1. いま RSpec に移行中 [return]
 
comments powered by Disqus