spec/support/koala_test.rb in koala-1.2.0beta3 vs spec/support/koala_test.rb in koala-1.2.0beta4

- old
+ new

@@ -1,11 +1,11 @@ # small helper method for live testing module KoalaTest class << self attr_accessor :oauth_token, :app_id, :secret, :app_access_token, :code, :session_key - attr_accessor :oauth_test_data, :subscription_test_data + attr_accessor :oauth_test_data, :subscription_test_data, :search_time end # Test setup def self.setup_test_environment! @@ -82,10 +82,13 @@ self.app_id = data["oauth_test_data"]["app_id"] self.app_access_token = data["oauth_test_data"]["app_access_token"] self.secret = data["oauth_test_data"]["secret"] self.code = data["oauth_test_data"]["code"] self.session_key = data["oauth_test_data"]["session_key"] + + # fix the search time so it can be used in the mock responses + self.search_time = data["search_time"] || (Time.now - 3600).to_s end def self.testing_permissions "read_stream, publish_stream, user_photos, user_videos, read_insights" end @@ -95,16 +98,35 @@ # 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) - # create two test users with specific names and befriend them - @live_testing_user = @test_user_api.create(true, testing_permissions, :name => user1_name) - @live_testing_friend = @test_user_api.create(true, testing_permissions, :name => user2_name) - @test_user_api.befriend(@live_testing_user, @live_testing_friend) - self.oauth_token = @live_testing_user["access_token"] + RSpec.configure do |config| + config.before :all do + # before each test module, create two test users with specific names and befriend them + KoalaTest.create_test_users + end + + config.after :all 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"] + 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) + end end def self.validate_user_info(token) print "Validating permissions for live testing..." # make sure we have the necessary permissions