アクトインディ開発者ブログ

子供とお出かけ情報「いこーよ」を運営する、アクトインディ株式会社の開発者ブログです

autotest-stumpwm

こんにちは!! tahara です。

script/autospec の結果を表示してくれる Growl がうらやましいのですが、私 の使っているのは Linux です。しかし、Linux には Stumpwm があります。 Stumpwm の stumpish を使えば echo でメッセージを表示することができます。

そこで script/autospec の結果を Stumpwm で表示する gem を作ってみます。

参考サイト

gem を作るには Jeweler を使うのがよさそうです。 Jeweler は GitHubAPI を使うようなので、まずその設定を行います。 user_name と api_token には自分の Username と API Token を指定します。

git config --global github.user user_name
git config --global github.token api_token

Jeweler をインストールしてプロジェクトを作ってみます。

gem install jeweler
jeweler --rspec --create-repo autotest-stumpwm

これで綺麗にプロジェクトが作成されます。 おまけに GitHubリポジトリまでできています。

次に Rakefile を編集します。TODO になっている次の二箇所を適当に編集すればよさそうです。 あと依存する gem も指定しておきます。

    gem.summary = %Q{TODO: one-line summary of your gem}
    gem.description = %Q{TODO: longer description of your gem}
    gem.add_dependency "autotest-growl", ">= 0.1.7"

次に lib の下のファイルに Stumpwm を使って script/autospec の結果を表示するたコードを書きます。 コードが出きたら次のようにリリースします。

rake version:write
rake gemspec
rake release

これだけで Gemcutter にも自動的に公開されます。 Jeweler すばらしい!!

修正したら git commit して、次のいずれかでバージョンをあげ rake release するだけ。

rake version:bump:major              # Bump the gemspec by a major version.
rake version:bump:minor              # Bump the gemspec by a minor version.
rake version:bump:patch              # Bump the gemspec by a patch

できあがった autotest-stumpwm を使うには gem install autotest-stumpwm して、 ~/.autotest に次の一行を書きます。これで autospec と Stumpwm の幸せな生活がおくれます。

require 'autotest/stumpwm'

さて、一番大切な Stumpwm で結果を表示するコードですが、

# -*- coding: undecided -*-
require 'rubygems'
require 'autotest/growl'

module Autotest::Growl
  def self.growl(title, message, icon, priority=0, stick="")
    priority = if priority > 0  # error or feailed
                 1              # red
               elsif priority == -2 # passed
                 2                  # green
               else
                 3              # yellow
               end
    system "stumpish echo ^#{priority}* #{title} #{message}"
  end
end

ごめんなさい autotest-growl にモンキーパッチをあてただけです。