lib/testingbot.rb in testingbot-0.0.8 vs lib/testingbot.rb in testingbot-0.0.9

- old
+ new

@@ -1,41 +1,17 @@ require "testingbot/version" +require "testingbot/config" # if selenium RC, add testingbot credentials to request if defined?(Selenium) && defined?(Selenium::Client) && defined?(Selenium::Client::Protocol) module Selenium module Client module Protocol - attr_writer :client_key, :client_secret - - def client_key - if @client_key.nil? - @client_key, @client_secret = get_testingbot_credentials - end - @client_key - end - - def client_secret - if @client_secret.nil? - @client_key, @client_secret = get_testingbot_credentials - end - @client_secret - end - - def get_testingbot_credentials - if File.exists?(File.expand_path("~/.testingbot")) - str = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp - str.split(':') - else - raise "Please run the testingbot install tool first" - end - end - # add custom parameters for testingbot.com def http_request_for_testingbot(verb, args) data = http_request_for_original(verb, args) - data << "&client_key=#{client_key}&client_secret=#{client_secret}" + data << "&client_key=#{TestingBot.get_config[:client_key]}&client_secret=#{TestingBot.get_config[:client_secret]}" end begin alias http_request_for_original http_request_for alias http_request_for http_request_for_testingbot @@ -105,13 +81,14 @@ begin require 'spec' require "selenium/rspec/spec_helper" Spec::Runner.configure do |config| config.prepend_after(:each) do - if File.exists?(File.expand_path("~/.testingbot")) - str = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp - client_key, client_secret = str.split(':') + client_key = TestingBot.get_config[:client_key] + client_secret = TestingBot.get_config[:client_secret] + + if !client_key.nil? session_id = nil if !@selenium_driver.nil? session_id = @selenium_driver.session_id_backup @@ -150,14 +127,15 @@ # rspec 2 begin require 'rspec' ::RSpec.configuration.after :each do - if File.exists?(File.expand_path("~/.testingbot")) - str = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp - client_key, client_secret = str.split(':') + client_key = TestingBot.get_config[:client_key] + client_secret = TestingBot.get_config[:client_secret] + + if !client_key.nil? test_name = "" if example.metadata && example.metadata[:example_group] if example.metadata[:example_group][:description_args] test_name = example.metadata[:example_group][:description_args].join(" ") end @@ -206,20 +184,22 @@ end end rescue LoadError end -if defined?(Test::Unit::TestCase) +if defined?(Test::Unit::TestCase) && (Test::Unit::TestCase.respond_to?('run_teardown')) module TestingBot class TestingBot::TestCase < Test::Unit::TestCase alias :run_teardown_old :run_teardown alias :handle_exception_old :handle_exception attr_accessor :exception def run_teardown - client_key, client_secret = get_testingbot_credentials + client_key = TestingBot.get_config[:client_key] + client_secret = TestingBot.get_config[:client_secret] + params = { "session_id" => browser.session_id, "client_key" => client_key, "client_secret" => client_secret, "status_message" => @exception, @@ -236,18 +216,9 @@ end def handle_exception(e) @exception = e.to_s handle_exception_old(e) - end - - def get_testingbot_credentials - if File.exists?(File.expand_path("~/.testingbot")) - str = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp - str.split(':') - else - raise "Please run the testingbot install tool first" - end end end end end \ No newline at end of file