質問

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

役に立ちましたか?

解決

If the Diffusion object is not a ruby model, the fabrication gem has trouble locating it. At to what i can see it looks like its a sub-class of the Message model.

try this:

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

That should solve the error. For more info on defining Fabricators check here

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top