Class: FacebookAds::Test::Base

Inherits:
Minitest::Test
  • Object
show all
Includes:
Fixtures
Defined in:
lib/facebook_ads/test/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Fixtures

#ad_account, #create_ad, #create_ad_set, #create_adlabel, #create_campaign, #create_creative, #create_image, #randomize

Instance Attribute Details

#cleanup_queueObject

Returns the value of attribute cleanup_queue.



32
33
34
# File 'lib/facebook_ads/test/base.rb', line 32

def cleanup_queue
  @cleanup_queue
end

#configObject

Returns the value of attribute config.



32
33
34
# File 'lib/facebook_ads/test/base.rb', line 32

def config
  @config
end

Instance Method Details

#after_teardownObject



65
66
67
68
# File 'lib/facebook_ads/test/base.rb', line 65

def after_teardown
  # Collect failures for custom exit code
  FacebookAds::Test.failures.concat(self.failures)
end

#before_setupObject



36
37
38
# File 'lib/facebook_ads/test/base.rb', line 36

def before_setup
  load_config!
end

#generate(type, *args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/facebook_ads/test/base.rb', line 40

def generate(type, *args)
  method = "create_#{type}".to_sym
  if respond_to?(method)
    send(method, *args) do |generated_obj|
      cleanup_later(generated_obj)
    end.tap do |obj|
      cleanup_later(obj)
    end
  else
    raise TestRuntimeError, "#{type} is not a supported generator"
  end
end

#teardownObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/facebook_ads/test/base.rb', line 53

def teardown
  return unless cleanup_queue

  cleanup_queue.reverse.each do |obj_or_id|
    if obj_or_id.is_a?(FacebookAds::AdObject)
      obj_or_id.destroy
    elsif obj_or_id.is_a?(String) || obj_or_id.is_a?(Numeric)
      FacebookAds::AdObject.get(obj_or_id).destroy
    end
  end
end