0

I'm validating a mailer using rspec. The problem is that when I want to test the diffusion (multiple deliverers mailer) rspec give me an error.

my Fabricator:

Fabricator(:message) do
  email(count: 1) {"proof@example.com" }
  subject:"Hackety-hack email"
  body:"This is an email from hackety-hack.com"
end

Fabricator(:diffusion) do
  email(count: 3) {"proof#{i}@example.com" }
  subject:"Hackety-hack email"
  body:"This is an email from hackety-hack.com"
end

In my message_mailer_spec.rb I have

it "Works the diffusion" do
  diffusion.to.should eq(["proof@example.com", "proof2@example.com"])
end

When I try to pass the tests give me a lot of errors. The main (i think):

  10) MessageMailer Works the diffusion
 Failure/Error: let(:diffusion) { MessageMailer.new_message(Fabricate(:diffusion), Array("proof@example.com", "proof2@example.com", "proof3@example.com"))}
 Fabrication::UnknownFabricatorError:
   No Fabricator defined for 'diffusion'

Why? I already created the diffusion. Can anyone helps me?

Thanks in advance

4

1 回答 1

2

如果 Diffusion 对象不是红宝石模型,则制造宝石很难找到它。就我所见,它看起来像是 Message 模型的子类。

尝试这个:

Fabricator(:diffusion, from: message)  do
  email(count: 3) {"proof#{i}@example.com" }
  subject:"Hackety-hack email"
  body:"This is an email from hackety-hack.com"
end

那应该可以解决错误。有关定义制造商的更多信息,请查看此处

于 2013-11-14T14:33:12.310 回答