spec/support/test_app.rb in ably-0.7.1 vs spec/support/test_app.rb in ably-0.7.2

- old
+ new

@@ -25,21 +25,24 @@ } # If an app has already been created and we need a new app, create a new test app # This is sometimes needed when a test needs to be isolated from any other tests def self.reload - instance.create_test_app if instance_variable_get('@singleton__instance__') + if instance_variable_get('@singleton__instance__') + instance.delete + instance.create_test_app + end end include Singleton def initialize create_test_app end def app_id - @attributes["id"] + @attributes["appId"] end def key @attributes["keys"].first end @@ -63,10 +66,12 @@ def restricted_api_key "#{app_id}.#{restricted_key['id']}:#{restricted_key['value']}" end def delete + return unless TestApp.instance_variable_get('@singleton__instance__') + url = "#{sandbox_client.endpoint}/apps/#{app_id}" basic_auth = Base64.encode64(api_key).chomp headers = { "Authorization" => "Basic #{basic_auth}" } @@ -83,20 +88,23 @@ headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } - response = Faraday.post(url, APP_SPEC.to_json, headers) - - @attributes = JSON.parse(response.body) + @attributes = JSON.parse(Faraday.post(url, APP_SPEC.to_json, headers).body) end def host sandbox_client.endpoint.host end def realtime_host host.gsub(/rest/, 'realtime') + end + + def create_test_stats(stats) + client = Ably::Rest::Client.new(api_key: api_key, environment: environment) + client.post('/stats', stats) end private def sandbox_client @sandbox_client ||= Ably::Rest::Client.new(api_key: 'app.key:secret', tls: true, environment: environment)