0

也许我现在看不见,但我尝试根据哈希的内容运行动态规范。在这种特殊情况下,不同版本的电子邮件部分应包含相同的内容,如下所示:

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 块中定义的值。

4

2 回答 2

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
于 2013-06-19T13:33:43.427 回答
0

尝试这个:

before(:all) do
  #testsetup stuff
  @versions = {"Text-Version" => current_email.parts[0].body , "HTML-Version" =>     current_email.parts[1].body}
end
于 2013-06-18T23:29:51.440 回答