Sha256: f58fb4c765041251369767308461037556476fcc88d7ceec5921fced3d998e76

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

module LiveTestingDataHelper
  # in RSpec 2, included example groups no longer share any hooks or state with outside examples 
  # even if in the same block
  # so we have to use a module to provide setup and teardown hooks for live testing
  
  def self.included(base)
    base.class_eval do
      before :each do
        @token = $testing_data["oauth_token"]
        raise Exception, "Must supply access token to run FacebookWithAccessTokenTests!" unless @token
        # track temporary objects created
        @temporary_object_ids = []
      end
  
      after :each do 
        # clean up any temporary objects
        @temporary_object_ids << @temporary_object_id if @temporary_object_id
        count = @temporary_object_ids.length
        errors = []
        
        if count > 0
          print "\nCleaning up #{count} temporary #{count > 1 ? "objects" : "object"}..."
          @temporary_object_ids.each do |id|
            # get our API
            api = @api || (@test_users ? @test_users.graph_api : nil)
            raise "Unable to locate API when passed temporary object to delete!" unless api
          
            # delete the object
            result = (api.delete_object(id) rescue false)
            # if we errored out or Facebook returned false, track that
            errors << id unless result
          end
          
          if errors.length == 0
            puts "done."
          else 
            puts "cleaned up #{count - errors.length} objects, but errored out on the following:\n #{errors.join(", ")}"
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
koala-0.10.0 spec/koala/live_testing_data_helper.rb