![](/img/trans.png)
[英]Clean test database, only of the data generated running the tests with RSPEC and Capybara
[英]Rspec running generated tests based on hash content
也許我現在不願看到,但我嘗試根據哈希的內容運行動態規范。 在這種特殊情況下,不同版本的電子郵件部件應包含相同的內容,如下所示:
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是nil然后運行測試。我希望它是我在before塊中定義的值。
嘗試這個:
before(:all) do
#testsetup stuff
@versions = {"Text-Version" => current_email.parts[0].body , "HTML-Version" => current_email.parts[1].body}
end
這個怎么樣?
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.