2011-08-05 16 views
0

Test :: Unit :: TestCaseテストのティアダウン機能を上書きしようとしています。 テストの終了中(終了後)に、私はいくつか余分なものをしたいです。Railsテストの上書きテスト:: Unit :: TestCase

(元ティアダウンを実行し続ける)私はこれを試してみましたが、それは動作しません:

module Test 
    module Unit 
    class TestCase 
     def teardown_modified 
      # do modifications 
      teardown_original 
     end 

     alias teardown_original teardown 
     alias teardown teardown_modified 
     end 
    end 
end 
+0

記号ではありませんか? – Senthess

+0

「エイリアス」はそのように奇妙なので、ほとんどの人はそれを使用しません。 – tadman

答えて

1

あなたは1つのTestCaseで、またはすべてでそれをしたいですか?

あなたはすべてのテストケースの変更が必要な場合:

class Test::Unit::TestCase 
    def teardown_with_hacks 
    teardown_without_hacks 
    end 
    alias_method_chain :teardown, :hacks 
end 

これは自動的にあなたのための多くのものを設定しています

gem 'test-unit' 
require 'test/unit' 

module Test 
    module Unit 
    module Fixture 
     alias :run_teardown_old :run_teardown 
     def run_teardown 
      # do modifications 
      puts "In modified teardown" 
      run_teardown_old 
     end #def run_teardown 
     end #module Fixture 
    end #module Unit 
end #module Test 

class MyTest < Test::Unit::TestCase 
    def teardown 
    puts "In teardown" 
    end 

    def test_4() 
    assert_equal(2,1+1) 
    end 
end 
+0

ありがとうございます、うまく動作します! – Jochen

1

をあなたはalias_method_chainを使用して、より良い結果を生むことがあります。

+0

ありがとう、よく見えます! – Jochen

関連する問題