2009-06-06 12 views
9

Bazı Rails sınamaları için sınıf veya sistem çapında bir kurulum ve göz atma yöntemine ihtiyacım var, ancak her bir sınama düzeyinde çalışan düzenli bir kurulum/yırtıp çıkarma işlemini tanımlamanın bir yolunu buldum.Rails testleri için bir setup_class/teardown_class var mı?

class ActiveSupport::TestCase 
    setup do 
    puts "Setting up" 
    end 

    teardown do 
    puts "tearing down" 
    end 
end 

her test durumu için çıkışları yürütmek olacak, ama böyle bir şey istiyorum: Bütün test yöntemleri önce kurulum _ fikstür yürütülür

class ActiveSupport::TestCase 
    setup_fixture do 
    puts "Setting up" 
    end 

    teardown_fixture do 
    puts "tearing down" 
    end 
end 

Örneğin

ve daha sonra tüm test yöntemlerini'dan sonra _ fikstürü yıkayın.

Böyle bir mekanizma var mı? Eğer değilse, bu mekanizmayı maymunlara ayırmanın kolay bir yolu var mı?

cevap

4

birçok popüler test mevcuttur kullanabilirsiniz test dosyaları

yılında

 
    fixtures :users 

söyleyerek ve senden başka demirbaşlar kullanabilirsiniz Test::Unit üzerinde oluşturulan ve bu davranışı sağlayan çerçeveler:

RSpec

describe "A Widget" do 
    before(:all) do 
    # stuff that gets run once at startup 
    end 
    before(:each) do 
    # stuff that gets run before each test 
    end 
    after(:each) do 
    # stuff that gets run after each test 
    end 
    after(:all) do 
    # stuff that gets run once at teardown 
    end 
end 

Test/Spec

context "A Widget" do 
    # same syntax as RSpec for before(:all), before(:each), &c. 
end 
-1

Rayların fikstürler için böyle bir işlev sağladığını düşünüyorum. Ayrıca

 
def setup 
    #.... 
end 
test dosyalarında

yanı,

İlgili konular