2013-06-18 2 views
0

아마도 지금은 보지 못 하겠지만 해시의 내용을 기반으로 동적 사양을 실행하려고합니다.해시 컨텐트를 기반으로 생성 된 테스트를 실행하는 Rspec

context "testcontext" do 
    before do 
    #testsetup stuff 
    @versions = {"Text-Version" => current_email.parts[0].body , "HTML-Version" => current_email.parts[1].body} 
    end 

    it "sets the correct subject" do 
    current_email.subject.should =~ /subject_regex/ 
    end 

    @versions.each do |key, body| 

    it "test something in mail for #{key}" do 
     body.should include("something i want to be there") 
    end 
    end 
end 

을하지만 @versions 다음 테스트 테스트는 내가 이전에 정의 된 값으로 예상 실행 전무하다 :이 특별한 경우처럼 같은 내용을 포함해야 이메일 부품의 다른 버전은 다음과 scatched 블록.

+0

나는 "대답"할만큼 자신감이 없지만 "설정"이전의 것은 "설명"및 "그"방법에만 적용될 수 있다고 생각합니다. –

답변

0

이 시도 :이 방법에 대해

before(:all) do 
    #testsetup stuff 
    @versions = {"Text-Version" => current_email.parts[0].body , "HTML-Version" =>  current_email.parts[1].body} 
end 
+0

이 시도했지만 여전히 정의되지 않은 메서드를 각각에 대해 nil : NilClass (NoMethodError), 원인은 @ 버전입니다 nil – jethroo

0

를?

context "teh emailz" do 
    @parts = [:text, :html] 
    before do 
    @versions = {:text => current_email.parts[0].body, 
       :html => current_email.parts[1].body} 
    end 

    it "sets the correct subject" do 
    current_email.subject.should =~ /subject_regex/ 
    end 

    @parts.each do |name| 
    it "test something the #{name} part of the body" do 
     body = @versions[name] 
     body.should include("something i want to be there") 
    end 
    end 
end 
관련 문제