Q:

Multiple arguments with block in FactoryGirl

I have a method in spec\factories\campaigns.rb:
def campaign_trait(name, *callback_attrs, &block)
  trait name do
    association :campaign_type, factory: [:campaign_type, name]

    after(:build) do |campaign, evaluator|
      eval_str = ""
      callback_attrs.each do |arg|
        arg = [arg] unless arg.is_a? Array

        method_name = arg.shift
        method_args = arg
        method_name = "add_#{method_name}" unless respond_to? method_name

        eval_str << method_name.to_s
        eval_str << "(campaign"
        eval_str << ", evaluator" if method_name == "add_campaign_scopes"
        if method_args.any?
          method_args.map! { |i| i.is_a?(Symbol) ? ":#{i}" : i }
          eval_str << ", " << method_args.map(&:to_s).join(', ')
        end
        eval_str << ")\n"
      end
      eval eval_str
    end

    yield(block) if block_given?
  end
end

I call it here:
FactoryGirl.define do
    campaign_trait :basket, :campaign_scopes, [:banner, :basket] do
      initialize_with { Campaigns::Basket.new(attributes, without_protection: true) }
      emitent_article 'emitent'
      emitent_name 'Emitent'
    end
end

The problem that I face is that in the method campaign_trait I get  callback_attrs that equals [:campaign_scopes, []] instead of expected [:campaign_scopes, [:banner, :basket]]. 
If I call campaign_trait without the block, everything is OK and I get [:campaign_scopes, [:banner, :basket]] as expected.
Could you please help me?

A:

The problem was that I was calling campaign_trait number of times through many tests and somehow (I don't know why), callback_attrs are shared between tests. And method_name = arg.shift breaks my code modifying callback_attrs.
Thanks, BroiSatse! Deep debugging helped me.

