2013-03-16 2 views

답변

45

선언한다 : 세트는 각각의 최상위 예 기 전에 호출되는 RSpec.configure 블록에서 정의하는 전 (잠시) 코드 블록은 한 번만 호출됩니다.

RSpec.configure do |config| 
    config.before(:all) {puts "Before :all"} 
    config.after(:all) {puts "After :all"} 
    config.before(:suite) {puts "Before :suite"} 
    config.after(:suite) {puts "After :suite"} 
end 

describe "spec1" do 
    example "spec1" do 
    puts "spec1" 
    end 
end 

describe "spec2" do 
    example "spec2" do 
    puts "spec2" 
    end 
end 

출력 :

내 질문이있다
Before :suite 
Before :all 
spec1 
After :all 
Before :all 
spec2 
After :all 
After :suite 
+0

: 나는'사용하여 admin 사용자와 같은 일부 씨앗 데이터를로드 할 경우 "suite' 전에 늘 그 데이터가 예 후 지울 수 있습니다 여기에

은 예입니다 운영?" – illusionist

+0

아니 그들은 당신이 수동으로 처리해야 유지하지 않습니다. 전에 (: 예) 트랜잭션 내에 있습니다. – Foton

+0

: 스위트 룸 : 컨텍스트 (= 모두) 외부 거래이다. 상관 관계가 얼마나 깊든간에. – Foton