テストのC0カバレッジを上げるために、 何度もrcovを手で実行していたのですが、 テストの数が多くなってくると非常に時間がかかって面倒なため、 自動化するRakeタスクを作りました。

   1  namespace :rcov do
   2    desc 'Automate rcov'
   3    task :auto do
   4      interval = (ENV['INTERVAL'] || 10).to_f
   5      org_path = File.join(RAILS_ROOT, 'coverage', '*')
   6      pub_path = File.join(RAILS_ROOT, 'public', 'coverage')
   7      sh "mkdir -p #{pub_path}"
   8      loop do
   9        Rake::Task['spec:rcov'].execute nil
  10        sh "cp -Rf #{org_path} #{pub_path}"
  11        sleep interval
  12      end
  13    end
  14  end

使い方はRAILS_ROOTで以下のコマンドを実行するだけです。

   1  % rake rcov:auto INTERVAL=10

指定した時間間隔(秒)ごとにspec:rcovを実行します。 実行した結果はRSpecのデフォルトでは RAILS_ROOT/coverageに出力されるので、これを public/coverageに上書きコピーしています。 あとは、ブラウザで/coverageを見ればOKです。

public/coverageは間違ってデプロイしないように.gitignoresvn:ignoreに登録しておきましょう。

posted by Png genki on Sat 5 Jul 2008 at 03:43

I made a small utility library named Wormhole. The library enables us to communicate between caller and callee.

Here is a simple example of use.

   1  require 'rubygems'
   2  require 'wormhole'
   3  
   4  def foo(array)
   5    array << :foo # (1)
   6    Wormhole.throw array
   7    array << :baz # (3)
   8  end
   9  
  10  result = Wormhole.catch do
  11    foo []
  12  end.return do |array|
  13    array << :bar # (2)
  14  end
  15  puts result.inspect # => [:foo, :bar, :baz]

First, the block passed to Wormhole.catch, the caller, is evaluated. The foo method, the callee, throw an array object passing through the wormhole. Then the array is caught by the last block passed to a return method. A block parameter of the block is the array. Finally, the process goes back to the point 3 after the last block ends. A return value of the foo method is returned via the return method.

By using this utility, you can participate to a depth of a complicated system from a safer position.

At the end, you can install this utility from the GitHub by using gem command like this.

   1  % sudo gem sources -a http://gems.github.com
   2  % sudo gem install genki-wormhole

Have fun!

posted by Png takiuchi on Sat 5 Jul 2008 at 01:53 with 2 comments

メソッドやProcの内部で継続(Continuation)を実行した後に、 そのメソッドの戻り値がどうなるのか理解があやふやだったので実験。

前準備。

   1  a = nil
   2  foo = proc{callcc{|a|}; 1}
   3  bar = proc{foo.call; 2}
   4  baz = proc{a.call; 3}

実験開始。

   1  >> foo.call
   2  => 1
   3  >> baz.call
   4  => 1
   5  >> bar.call
   6  => 2
   7  >> baz.call
   8  => 2

なるほど。

posted by Png genki on Fri 4 Jul 2008 at 18:57
Contents
RCovを自動実行させる rake rcov:auto
Wormhole: Let's Communicate Between Caller and Callee
継続を実行した後のメソッドやProcの戻り値に関するメモ
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ