spec/support/koala_test.rb in koala-1.2.0 vs spec/support/koala_test.rb in koala-1.2.1

- old
+ new

@@ -55,20 +55,20 @@ @token = KoalaTest.oauth_token Koala::Utils.stub(:deprecate) # never fire deprecation warnings end config.after :each do - # clean up any objects posted to Facebook - if @temporary_object_id && !KoalaTest.mock_interface? - api = @api || (@test_users ? @test_users.graph_api : nil) - raise "Unable to locate API when passed temporary object to delete!" unless api + # if we're working with a real user, clean up any objects posted to Facebook + # no need to do so for test users, since they get deleted at the end + if @temporary_object_id && KoalaTest.real_user? + raise "Unable to locate API when passed temporary object to delete!" unless @api # wait 10ms to allow Facebook to propagate data so we can delete it sleep(0.01) # clean up any objects we've posted - result = (api.delete_object(@temporary_object_id) rescue false) + result = (@api.delete_object(@temporary_object_id) rescue false) # if we errored out or Facebook returned false, track that puts "Unable to delete #{@temporary_object_id}: #{result} (probably a photo or video, which can't be deleted through the API)" unless result end end end @@ -92,36 +92,38 @@ def self.testing_permissions "read_stream, publish_stream, user_photos, user_videos, read_insights" end def self.setup_test_users - # note: we don't have to delete the two test users explicitly, since the test user specs do that for us - # technically, this is a point of brittleness and would break if the tests were run out of order - # however, for now we can live with it since it would slow tests way too much to constantly recreate our test users print "Setting up test users..." @test_user_api = Koala::Facebook::TestUsers.new(:app_id => self.app_id, :secret => self.secret) RSpec.configure do |config| - config.before :all do + config.before :suite do # before each test module, create two test users with specific names and befriend them KoalaTest.create_test_users end - config.after :all do + config.after :suite do # after each test module, delete the test users to avoid cluttering up the application KoalaTest.destroy_test_users end end puts "done." end def self.create_test_users - @live_testing_user = @test_user_api.create(true, KoalaTest.testing_permissions, :name => KoalaTest.user1_name) - @live_testing_friend = @test_user_api.create(true, KoalaTest.testing_permissions, :name => KoalaTest.user2_name) - @test_user_api.befriend(@live_testing_user, @live_testing_friend) - self.oauth_token = @live_testing_user["access_token"] + begin + @live_testing_user = @test_user_api.create(true, KoalaTest.testing_permissions, :name => KoalaTest.user1_name) + @live_testing_friend = @test_user_api.create(true, KoalaTest.testing_permissions, :name => KoalaTest.user2_name) + @test_user_api.befriend(@live_testing_user, @live_testing_friend) + self.oauth_token = @live_testing_user["access_token"] + rescue Exception => e + Kernel.warn("Problem creating test users! #{e.message}") + raise + end end def self.destroy_test_users [@live_testing_user, @live_testing_friend].each do |u| puts "Unable to delete test user #{u.inspect}" if u && !(@test_user_api.delete(u) rescue false) @@ -142,10 +144,10 @@ puts "done!" end # Info about the testing environment def self.real_user? - !(mock_interface? || @test_user) + !(mock_interface? || @test_user_api) end def self.test_user? !!@test_user_api end