Search code examples
rubyruby-on-rails-3rspecfabrication-gem

spec and fabrication validating mailer. Fabrication::UnfabricatableError: No class found for


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) {"[email protected]" }
  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(["[email protected]", "[email protected]"])
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("[email protected]", "[email protected]", "[email protected]"))}
 Fabrication::UnknownFabricatorError:
   No Fabricator defined for 'diffusion'

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

Thanks in advance


Solution

  • 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