昔は違った気がするのですが、手元の環境のautotest(ZenTest-3.10.0)とRSpec-1.1.4を使った状態で、テスト中に一度例外が発生した後に、全てのテストをgreenにすると、全てのテストがもう一回全部実行されるという現象が起きています。

全部テストを実行するのは大変なので、とりあえず、.autotest でパッチを当てて回避しました。

   1  class Autotest
   2    alias_method :handle_results_old, :handle_results
   3    undef_method :handle_results
   4  
   5    def handle_results(results)
   6      failed = results.scan(self.failed_results_re)
   7      completed = results =~ self.completed_re
   8  
   9      self.files_to_test = consolidate_failures failed if completed
  10  
  11      color = completed && self.files_to_test.empty? ? :green : :red
  12      hook color unless $TESTING
  13  
  14      #self.tainted = true unless self.files_to_test.empty?
  15      self.tainted = !self.files_to_test.empty?
  16    end
  17  end

L14-15行目が修正箇所です。

posted by Png genki on Sun 6 Jul 2008 at 11:46

メモもかねて。

MacBookにRailsの自動テスト環境を構築した

RAILS_ROOTでautotestを実行。起動時に全部のテストを実行するのでちょっとだけ重くなるかもしれません。それ以降はテストファイルやモデル、コントローラファイルなどを修正する度に該当のテストが走ります。

autotestを-fオプションを付けて立ち上げると、Fast startモードになり、最初に全部のテストを実行しなくなります。

posted by Png genki on Sun 6 Jul 2008 at 10:53

KagemushaでActiveRecordのfindなどのクラスメソッドをswap しようとすると、

   1  singleton method bound for a different object (TypeError)

というエラーが発生するという問題がありました。

このままでは困るので、とりあえず動くようにしてみました。 Unboundにしなければ問題は起こらないと思ったので、 instance_methodの代わりにalias_methodを使っています。

kagemusha_core_ext.rb

   1  require 'uuidtools'
   2  
   3  class Kagemusha #:nodoc:
   4    def swap #:nodoc:
   5      original_class_methods    = {}
   6      original_instance_methods = {}
   7  
   8      @class_methods.each { |name, proc|
   9        if proc
  10          begin
  11            # replace method
  12            #method = @meta.instance_method(name)
  13            method = random_name
  14            @meta.instance_eval { alias_method method, name }
  15            @meta.instance_eval { define_method(name, proc) }
  16            original_class_methods[name] = method
  17          rescue NameError
  18            # insert method
  19            @meta.instance_eval { define_method(name, proc) }
  20            original_class_methods[name] = false
  21          end
  22        else
  23          begin
  24            # remove method
  25            #method = @meta.instance_method(name)
  26            method = random_name
  27            @meta.instance_eval { alias_method method, name }
  28            @meta.instance_eval { undef_method(name) }
  29            original_class_methods[name] = method
  30          rescue NameError
  31            # nop
  32          end
  33        end
  34      }
  35  
  36      @instance_methods.each { |name, proc|
  37        if proc
  38          begin
  39            # replace method
  40            method = @klass.instance_method(name)
  41            @klass.instance_eval { define_method(name, proc) }
  42            original_instance_methods[name] = method
  43          rescue NameError
  44            # insert method
  45            @klass.instance_eval { define_method(name, proc) }
  46            original_instance_methods[name] = false
  47          end
  48        else
  49          begin
  50            # remove method
  51            method = @klass.instance_method(name)
  52            @klass.instance_eval { undef_method(name) }
  53            original_instance_methods[name] = method
  54          rescue NameError
  55            # nop
  56          end
  57        end
  58      }
  59  
  60      return yield
  61    ensure
  62      original_class_methods.each { |name, method|
  63        if method
  64          # replace method
  65          #@meta.instance_eval { define_method(name, method) }
  66          @meta.instance_eval { alias_method name, method }
  67          @meta.instance_eval { undef_method method }
  68        else
  69          # remove method
  70          @meta.instance_eval { undef_method(name) }
  71        end
  72      }
  73      original_instance_methods.each { |name, method|
  74        if method
  75          # replace method
  76          @klass.instance_eval { define_method(name, method) }
  77        else
  78          # remove method
  79          @klass.instance_eval { undef_method(name) }
  80        end
  81      }
  82    end
  83  
  84  private
  85    def random_name
  86      [UUID.random_128].pack("m").tr("=\n", '')
  87    end
  88  end

posted by Png genki on Sun 6 Jul 2008 at 05:22 with 2 comments
Contents
autotestでall_good時にrerun_all_testsをしないようにする
autotestで起動時に全部テストを実行しないオプション
KagemushaとActiveRecordの不具合の解消
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
瀧内元気: おお、チェックしてみます。thx! '11-12
overisland: Reeder for iPhone もこの UI を実装していますね。 '11-12
瀧内元気: その情報は見たのですが、以下のサイトによると、現在はまた必要になってるっぽいんですよね。 ... '11-12
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ