Can't create inherited fabricator

25 views
Skip to first unread message

Dimitri Pekarovsky

unread,
Mar 18, 2019, 5:58:33 PM3/18/19
to fabrication
Wondering to make inherited fabricators I get error because of Fabricator looks for an class.
I found in docs, that key :from is used both to point to an class name and to an fabricator. Is that correct?

ruby 2.6.1, rspec 3.8.0

The code:

require_relative '../../app/amqp_response'

Fabricator :amqp_rq, class: "AMQPResponse" do
  on_init
{ init_with( meta, props, body ) }
  meta
{{}}
  body
{ body }
end

Fabricator :amqp_anon, :from => :amqp_rq do
  props
do |routing_key|
   
{ correlation_id: (Time.now.to_f*10000).to_i.to_s.freeze,
      app_id
: 'proxy',
      content_type
: 'application/json',
      type
: 'POST',
      routing_key
: routing_key,
      headers
: {
       
'client_id' => nil,
       
'accept_language' => 'ru' } }
 
end
end

Fabricator :amqp_client, :from => :amqp_rq do
  props
do |routing_key|
   
{ correlation_id: (Time.now.to_f*10000).to_i.to_s.freeze,
      app_id
: 'proxy',
      content_type
: 'application/json',
      type
: 'POST',
      routing_key
: routing_key,
      headers
: {
       
'client_id' => client_id,
       
'accept_language' => 'ru' } }
 
end
end


When I'm want to inherit the fabricator :amqp_rq that error shows, that Fabricator is looking for class named "AmqpRq". Isn't it?

     Fabrication::UnfabricatableError:
       
No class found for 'amqp_rq' (original exception: uninitialized constant AmqpRq)


Paul Elliott

unread,
Mar 19, 2019, 10:01:02 AM3/19/19
to fabrica...@googlegroups.com
Fabricators are loaded in the order they are declared and the files under `/spec/fabricators` are loaded alphabetically. Do you have the inheriting fabricators defined prior to the base by any chance? That would definitely cause this issue.

-- Paul


--
You received this message because you are subscribed to the Google Groups "fabrication" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fabricationge...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dimitri Pekarovsky

unread,
Mar 19, 2019, 2:29:41 PM3/19/19
to fabrication
They are defined in one single file exactly as in the post. Should I separate them into 3 different files?

//DP

вторник, 19 марта 2019 г., 16:01:02 UTC+2 пользователь Paul Elliott написал:

Paul Elliott

unread,
Mar 19, 2019, 2:32:01 PM3/19/19
to fabrica...@googlegroups.com
No, having them together is fine.

Actually, I think the issue is using `class` in the base fabricator. That used to be an option but a long time ago it was removed. Change that to use `from` and see if that fixes it for you.

-- Paul

Dimitri Pekarovsky

unread,
Mar 19, 2019, 2:42:59 PM3/19/19
to fabrication
Yes! It dit it. Thank you.

require 'bunny'
require_relative
'../../app/amqp_response'

Fabricator :amqp_rq, from: "AMQPResponse" do
  meta
{|ba, consumer, ch| Bunny::DeliveryInfo.new(basic_deliver, consumer, channel) }
  body
{ '{}' }
  on_init
{ new( meta, props, body ) }
end

Fabricator :amqp_anon, from: :amqp_rq do
  props
do |routing_key|
   
Bunny::MessageProperties.new(

      correlation_id
: (Time.now.to_f*10000).to_i.to_s.freeze,
      app_id
: 'proxy',
      content_type
: 'application/json',
      type
: 'POST',
      routing_key
: routing_key,
      headers
: {
       
'client_id' => nil,

       
'accept_language' => 'ru' } )
 
end
end

Fabricator :amqp_client, from: :amqp_rq do
  props
do |routing_key|
   
Bunny::MessageProperties.new(

      correlation_id
: (Time.now.to_f*10000).to_i.to_s.freeze,
      app_id
: 'proxy',
      content_type
: 'application/json',
      type
: 'POST',
      routing_key
: routing_key,
      headers
: {
       
'client_id' => client_id,

       
'accept_language' => 'ru' } )
 
end
end



вторник, 19 марта 2019 г., 20:32:01 UTC+2 пользователь Paul Elliott написал:
Reply all
Reply to author
Forward
0 new messages