ruby on rails - Multiple arguments with block in FactoryGirl -
i have method in spec\factories\campaigns.rb
:
def campaign_trait(name, *callback_attrs, &block) trait name association :campaign_type, factory: [:campaign_type, name] after(:build) |campaign, evaluator| eval_str = "" callback_attrs.each |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}" : } 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 here:
factorygirl.define campaign_trait :basket, :campaign_scopes, [:banner, :basket] initialize_with { campaigns::basket.new(attributes, without_protection: true) } emitent_article 'emitent' emitent_name 'emitent' end end
the problem face in method campaign_trait
callback_attrs
equals [:campaign_scopes, []]
instead of expected [:campaign_scopes, [:banner, :basket]]
.
if call campaign_trait
without block, ok , [:campaign_scopes, [:banner, :basket]]
expected.
could please me?
the problem was calling campaign_trait
number of times through many tests , somehow (i don't know why), callback_attrs shared between tests. , method_name = arg.shift
breaks code modifying callback_attrs.
thanks, broisatse! deep debugging helped me.
Comments
Post a Comment