<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/exceptional/handler.rb</filename>
    </added>
    <added>
      <filename>spec/handler_spec.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,20 +1,2 @@
 require 'exceptional'
-
-
-def to_stderr(s)
-  STDERR.puts &quot;** [Exceptional] &quot; + s
-end
-
-config_file = File.join(RAILS_ROOT,&quot;/config/exceptional.yml&quot;)
-
-begin
-  Exceptional::Config.load_config(config_file, RAILS_ENV, RAILS_ROOT)
-
-  if Exceptional::Config.enabled?
-    Exceptional.startup
-  end
-
-rescue Exception =&gt; e
-  to_stderr e
-  to_stderr &quot;Plugin disabled.&quot;
-end
+Exceptional.setup(RAILS_ENV, RAILS_ROOT)
\ No newline at end of file</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,126 +1,39 @@
 $:.unshift File.dirname(__FILE__)
 
-require 'json' unless defined? Rails
 
 require 'exceptional/exception_data'
 require 'exceptional/version'
 require 'exceptional/log'
 require 'exceptional/config'
 require 'exceptional/remote'
+require 'exceptional/handler'
 
 
 module Exceptional
 
   class &lt;&lt; self
-
+    include Exceptional::Config
+    include Exceptional::ExceptionalHandler
+    include Exceptional::Remote
+    include Exceptional::Log
+    
     # called from init.rb
-    def startup
-      Log.setup # need the log in place in case the authentication fails
-      
-      if Remote.authenticate
-        require File.join('exceptional', 'integration', 'rails')
-        Config.log_config_info
-      else
-        Log.log! &quot;Exceptional plugin not authenticated, check your API Key&quot;
-        Log.log! &quot;Disabling Exceptional Plugin.&quot;
-      end
-    end
-
-    # rescue any exceptions within the given block,
-    # send it to exceptional,
-    # then raise
-    def rescue(&amp;block)
+    def setup(environment, application_root)
       begin
-        block.call
+        setup_config(environment, File.join(application_root,&quot;config&quot;, &quot;exceptional.yml&quot;))
+        setup_log(File.join(application_root, &quot;log&quot;), log_level)
+
+        if enabled?
+          if authenticate
+            require File.join('exceptional', 'integration', 'rails')
+          else
+            STDERR.puts &quot;Exceptional plugin not authenticated, check your API Key&quot;
+          end
+        end        
       rescue Exception =&gt; e
-        self.catch(e)
-        raise(e)
-      end
-    end
-
-    # parse an exception into an ExceptionData object
-    def parse(exception)
-      exception_data = ExceptionData.new
-      exception_data.exception_backtrace = exception.backtrace
-      exception_data.exception_message = exception.message
-      exception_data.exception_class = exception.class.to_s
-      exception_data
-    end
-
-    # post the given exception data to getexceptional.com
-    def post(exception_data)
-      hash = exception_data.to_hash
-      if hash[:session]
-        hash[:session].delete(&quot;initialization_options&quot;)
-        hash[:session].delete(&quot;request&quot;)
-      end
-
-      Remote.post_exception(hash.to_json)
-    end
-
-    # given a regular ruby Exception class, will parse into an ExceptionData
-    # object and post to getexceptional.com
-    def catch(exception)
-      exception_data = parse(exception)
-      exception_data.controller_name = File.basename($0)
-      post(exception_data)
-    end
-
-    # used with Rails, takes an exception, controller, request and parameters
-    # creates an ExceptionData object
-    # if Exceptional is running in :direct mode, will post to getexceptional.com
-    def handle(exception, controller, request, params)
-      Log.log! &quot;Handling #{exception.message}&quot;, 'info'
-      begin
-        e = parse(exception)
-        # Additional data for Rails Exceptions
-        e.framework = &quot;rails&quot;
-        e.controller_name = controller.controller_name
-        e.action_name = controller.action_name
-        e.application_root = Config.application_root
-        e.occurred_at = Time.now.strftime(&quot;%Y%m%d %H:%M:%S %Z&quot;)
-        e.environment = request.env.to_hash
-        e.url = &quot;#{request.protocol}#{request.host}#{request.request_uri}&quot;
-        e.environment = safe_environment(request)
-        e.session = safe_session(request.session)
-        e.parameters = params.to_hash
-
-        post(e)
-      rescue Exception =&gt; exception
-        Log.log! &quot;Error preparing exception data.&quot;
-        Log.log! exception.message
-        Log.log! exception.backtrace.join(&quot;\n&quot;), 'debug'
+        STDERR.puts e
+        STDERR.puts &quot;Exceptional Plugin disabled.&quot;
       end
     end
-
-    protected
-
-    def safe_environment(request)
-      safe_environment = request.env.to_hash
-      # From Rails 2.3 these objects that cause a circular reference error on .to_json need removed
-      # TODO potentially remove this case, should be covered by sanitize_hash
-      safe_environment.delete_if { |k,v| k =~ /rack/ || k =~ /action_controller/ || k == &quot;_&quot; }
-      # needed to add a filter for the hash for &quot;_&quot;, causing invalid xml.
-      sanitize_hash(safe_environment)
-    end
-
-    def safe_session(session)
-      result = {}
-      session.instance_variables.each do |v|
-        next if v =~ /cgi/ || v =~ /db/ || v =~ /env/
-        var = v.sub(&quot;@&quot;,&quot;&quot;) # remove prepended @'s
-        result[var] = session.instance_variable_get(v)
-      end
-      sanitize_hash(result)
-    end
-
-    private
-
-    # This (ironic) method sanitizes a hash by removing un-json-able objects from the passed in hash.
-    #   needed as active_support's fails in some cases with a cyclical reference error.
-    def sanitize_hash(hash)
-      return {} if hash.nil?
-      Hash.from_xml(hash.to_xml)['hash']
-    end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/exceptional.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,64 +13,62 @@ module Exceptional
 
     class ConfigurationException &lt; StandardError; end
 
-    class &lt;&lt; self
-
-      attr_accessor :api_key, :application_root      
-      attr_writer :remote_host, :remote_port, :ssl_enabled
-
-      def load_config(file, environment, application_root)
-        begin
-          config = YAML::load(File.open(file))[environment]
-          @api_key = config['api-key'] unless config['api-key'].nil?
-          @ssl_enabled = config['ssl'] unless config['ssl'].nil?
-          @log_level = config['log-level'] unless config['log-level'].nil?
-          @enabled = config['enabled'] unless config['enabled'].nil?
-          @remote_port = config['remote-port'].to_i unless config['remote-port'].nil?
-          @remote_host = config['remote-host'] unless config['remote-host'].nil?
-          @applicaton_root = application_root
-        rescue Exception =&gt; e
-          raise ConfigurationException.new(&quot;Unable to load configuration file:#{file} for environment:#{environment}&quot;)
-        end
-      end
-
-      def application_root
-        @applicaton_root || (File.dirname(__FILE__) + '/../..')
+    attr_reader :api_key
+    attr_writer :ssl_enabled, :remote_host, :remote_port, :api_key
+
+    def setup_config(environment, config_file)
+      begin
+        config = YAML::load(File.open(config_file))[environment]
+        @api_key = config['api-key'] unless config['api-key'].nil?
+        @ssl_enabled = config['ssl'] unless config['ssl'].nil?
+        @log_level = config['log-level'] unless config['log-level'].nil?
+        @enabled = config['enabled'] unless config['enabled'].nil?
+        @remote_port = config['remote-port'].to_i unless config['remote-port'].nil?
+        @remote_host = config['remote-host'] unless config['remote-host'].nil?
+        @applicaton_root = application_root
+
+        log_config_info
+      rescue Exception =&gt; e
+        raise ConfigurationException.new(&quot;Unable to load configuration #{config_file} for environment #{environment} : #{e.message}&quot;)
       end
+    end
 
-      def remote_host
-        @remote_host || REMOTE_HOST
-      end
+    def application_root
+      @applicaton_root || (File.dirname(__FILE__) + '/../..')
+    end
 
-      def remote_port
-        @remote_port || default_port
-      end
+    def remote_host
+      @remote_host || REMOTE_HOST
+    end
 
-      def log_level
-        @log_level || LOG_LEVEL
-      end
+    def remote_port
+      @remote_port || default_port
+    end
 
-      def default_port
-        ssl_enabled? ? REMOTE_SSL_PORT : REMOTE_PORT
-      end
+    def log_level
+      @log_level || LOG_LEVEL
+    end
 
-      def ssl_enabled?
-        @ssl_enabled || SSL
-      end
+    def default_port
+      ssl_enabled? ? REMOTE_SSL_PORT : REMOTE_PORT
+    end
 
-      def enabled?
-        @enabled || false
-      end
+    def ssl_enabled?
+      @ssl_enabled || SSL
+    end
 
-      def valid_api_key?
-        @api_key &amp;&amp; @api_key.length == 40 ? true : false
-      end
+    def enabled?
+      @enabled || false
+    end
 
-      def log_config_info
-        Log.to_log('debug', &quot;API Key: #{api_key}&quot;)
-        Log.to_log('debug', &quot;Remote Host: #{remote_host}:#{remote_port}&quot;)
-        Log.to_log('debug', &quot;Log level: #{log_level}&quot;)
-      end
+    def valid_api_key?
+      @api_key &amp;&amp; @api_key.length == 40 ? true : false
+    end
 
+    def log_config_info
+      Exceptional.to_log('debug', &quot;API Key: #{api_key}&quot;)
+      Exceptional.to_log('debug', &quot;Remote Host: #{remote_host}:#{remote_port}&quot;)
+      Exceptional.to_log('debug', &quot;Log level: #{log_level}&quot;)
     end
   end
-end
+end
\ No newline at end of file</diff>
      <filename>lib/exceptional/config.rb</filename>
    </modified>
    <modified>
      <diff>@@ -32,15 +32,13 @@ module Exceptional
       hash = {}
       ::ATTRS.each do |attribute|
         value = send(attribute)
-        hash[attribute] = value unless (value.nil? || value.empty? || attribute.is_a?(TCPSocket) || attribute.is_a?(TCPServer))
+        hash[attribute] = value unless (value.nil? || value.empty? || attribute.is_a?(TCPSocket) || attribute.is_a?(TCPServer)) 
       end
       hash
     end
     
     def to_json
       self.to_hash.to_json
-    end
-    
+    end    
   end
-  
-end
+end
\ No newline at end of file</diff>
      <filename>lib/exceptional/exception_data.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,47 +3,45 @@ require 'logger'
 module Exceptional
   module Log
 
-    class &lt;&lt;self
-      attr_accessor :log, :log_path, :log_level
-
-      def setup
-        begin
-          log_dir = File.join(Config.application_root, &quot;log&quot;)
-          Dir.mkdir(log_dir) unless File.directory?(log_dir)
-          self.log_path = File.join(log_dir, &quot;/exceptional.log&quot;)
-
-          log = Logger.new log_path
-          log.level = Logger::INFO
-
-          allowed_log_levels = ['debug', 'info', 'warn', 'error', 'fatal']
-          if log_level &amp;&amp; allowed_log_levels.include?(log_level)
-            log.level = eval(&quot;Logger::#{log_level.upcase}&quot;)
-          end
-
-          self.log = log
-        rescue Exception =&gt; e
-          raise Config::ConfigurationException.new(&quot;Unable to create log file #{log_path}&quot;)
+    attr_reader :log
+    
+    def setup_log(log_dir, log_level = Logger::INFO)
+      begin
+        Dir.mkdir(log_dir) unless File.directory?(log_dir)
+
+        log = Logger.new File.join(log_dir, &quot;/exceptional.log&quot;)
+        log.level = log_level
+
+        allowed_log_levels = ['debug', 'info', 'warn', 'error', 'fatal']
+        if log_level &amp;&amp; allowed_log_levels.include?(log_level)
+          log.level = eval(&quot;Logger::#{log_level.upcase}&quot;)
         end
 
+        @log = log
+      rescue Exception =&gt; e
+        raise Exceptional::Config::ConfigurationException.new(&quot;Unable to create log file #{log_path} &quot;, e)
       end
-            
-      def format_log_message(msg)
-        &quot;** [Exceptional] &quot; + msg 
-      end
+    end
 
-      def to_stderr(msg)
-        STDERR.puts format_log_message(msg)
-      end
+    def log!(msg, level = 'info')
+      to_log level, msg
+      to_stderr msg
+    end
 
-      def log!(msg, level = 'info')
-        to_stderr msg
-        to_log level, msg
-      end
+    def to_stderr(msg)
+      STDERR.puts format_log_message(msg)
+    end
 
-      def to_log(level, msg)
-        log.send level, msg if log
-      end
+    protected
+
+    def to_log(level, msg)
+      @log.send level, msg if @log
+    end
+
+    private
 
+    def format_log_message(msg)
+      &quot;** [Exceptional] &quot; + msg
     end
   end
-end
+end
\ No newline at end of file</diff>
      <filename>lib/exceptional/log.rb</filename>
    </modified>
    <modified>
      <diff>@@ -9,69 +9,67 @@ module Exceptional
 
     ::PROTOCOL_VERSION = 3
 
-    class &lt;&lt; self
+    # authenticate with getexceptional.com
+    # returns true if the configured api_key is registered and can send data
+    # otherwise false
+    def authenticate
 
-      # authenticate with getexceptional.com
-      # returns true if the configured api_key is registered and can send data
-      # otherwise false
-      def authenticate
-        return @authenticated if @authenticated
-        
-        if Config.api_key.nil?
-          raise Exceptional::Config::ConfigurationException.new(&quot;API Key must be configured&quot;)
-        end
+      return @authenticated if @authenticated
 
-        begin
-          # TODO No data required to authenticate, send a nil string? hacky
-          # TODO should retry if a http connection failed
-          authenticated = call_remote(:authenticate, &quot;&quot;)
-          @authenticated = authenticated =~ /true/ ? true : false
-        rescue
-          @authenticated = false
-        ensure
-          return @authenticated
-        end
+      if Exceptional.api_key.nil?
+        raise Exceptional::Config::ConfigurationException.new(&quot;API Key must be configured&quot;)
       end
 
-      def authenticated?
-        @authenticated || false
+      begin
+        # TODO No data required to authenticate, send a nil string? hacky
+        # TODO should retry if a http connection failed
+        authenticated = call_remote(:authenticate, &quot;&quot;)
+        
+        @authenticated = authenticated =~ /true/ ? true : false
+      rescue
+        @authenticated = false
+      ensure
+        return @authenticated
       end
+    end
 
-      def post_exception(data)
-        if !authenticated?
-          raise RemoteException.new(&quot;Not Authenticated&quot;)
-        end
+    def authenticated?
+      @authenticated || false
+    end
 
-        call_remote(:errors, data)
+    def post_exception(data)
+      if !authenticated?
+        authenticate
       end
 
-      protected
-
-      def call_remote(method, data)
+      call_remote(:errors, data)
+    end
 
-        begin
-          http = Net::HTTP.new(Config.remote_host, Config.remote_port)
-          http.use_ssl = true if Config.ssl_enabled?
-          uri = &quot;/#{method.to_s}?&amp;api_key=#{Config.api_key}&amp;protocol_version=#{::PROTOCOL_VERSION}&quot;
-          headers = method.to_s == 'errors' ? { 'Content-Type' =&gt; 'application/x-gzip', 'Accept' =&gt; 'application/x-gzip' } : {}
+    protected
 
-          compressed_data = CGI::escape(Zlib::Deflate.deflate(data, Zlib::BEST_SPEED))
-          response = http.start do |http|
-            http.post(uri, compressed_data, headers)
-          end
+    def call_remote(method, data)
+      begin
+        http = Net::HTTP.new(Exceptional.remote_host, Exceptional.remote_port)
+        http.use_ssl = true if Exceptional.ssl_enabled?
+        uri = &quot;/#{method.to_s}?&amp;api_key=#{Exceptional.api_key}&amp;protocol_version=#{::PROTOCOL_VERSION}&quot;
+        headers = method.to_s == 'errors' ? { 'Content-Type' =&gt; 'application/x-gzip', 'Accept' =&gt; 'application/x-gzip' } : {}
 
-          if response.kind_of? Net::HTTPSuccess
-            return response.body
-          else
-            raise RemoteException.new(&quot;#{response.code}: #{response.message}&quot;)
-          end
+        compressed_data = CGI::escape(Zlib::Deflate.deflate(data, Zlib::BEST_SPEED))
+        response = http.start do |http|
+          http.post(uri, compressed_data, headers)
+        end
 
-        rescue Exception =&gt; e
-          Exceptional::Log.log! &quot;Error contacting Exceptional: #{e}&quot;, 'info'
-          Exceptional::Log.log! e.backtrace.join(&quot;\n&quot;), 'debug'
-          raise e
+        if response.kind_of? Net::HTTPSuccess
+          return response.body
+        else
+          raise RemoteException.new(&quot;#{response.code}: #{response.message}&quot;)
         end
+
+      rescue Exception =&gt; e
+        Exceptional.log! &quot;Error contacting Exceptional: #{e}&quot;, 'info'
+        Exceptional.log! e.backtrace.join(&quot;\n&quot;), 'debug'
+        raise e
       end
     end
   end
-end
+end
\ No newline at end of file</diff>
      <filename>lib/exceptional/remote.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,9 +4,8 @@ require File.dirname(__FILE__) + '/spec_helper'
 describe Exceptional::Config do
   
   before(:all) do
-    config = Exceptional::Config
 
-    def config.reset_state
+    def Exceptional.reset_state
       @api_key = nil
       @ssl_enabled = nil
       @log_level = nil
@@ -18,95 +17,87 @@ describe Exceptional::Config do
   end
 
   after(:each) do
-    Exceptional::Config.reset_state
+    Exceptional.reset_state
   end
   
   describe &quot;default configuration&quot; do
     it &quot;should use port 80 by default if ssl not enabled&quot; do
-      Exceptional::Config.ssl_enabled?.should be_false
-      Exceptional::Config.remote_port.should == 80
+      Exceptional.ssl_enabled?.should be_false
+      Exceptional.remote_port.should == 80
     end
 
     it &quot;should use port 443 if ssl enabled&quot; do
-      Exceptional::Config.ssl_enabled= true
-      Exceptional::Config.remote_port.should == 443
-      Exceptional::Config.ssl_enabled= false
+      Exceptional.ssl_enabled= true
+      Exceptional.remote_port.should == 443
+      Exceptional.ssl_enabled= false
     end
 
     it &quot;should use log level of info by default&quot; do
-      Exceptional::Config.log_level.should == &quot;info&quot;
+      Exceptional.log_level.should == &quot;info&quot;
     end
 
     it &quot;should not be enabled by default&quot; do
-      Exceptional::Config.enabled?.should be_false
+      Exceptional.enabled?.should be_false
     end
 
     it &quot;should overwrite default host&quot; do
-      Exceptional::Config.remote_host.should == &quot;getexceptional.com&quot;
-      Exceptional::Config.remote_host = &quot;localhost&quot;
-      Exceptional::Config.remote_host.should == &quot;localhost&quot;
+      Exceptional.remote_host.should == &quot;getexceptional.com&quot;
+      Exceptional.remote_host = &quot;localhost&quot;
+      Exceptional.remote_host.should == &quot;localhost&quot;
     end
 
     it &quot;should overwrite default port&quot; do
-      Exceptional::Config.remote_port.should == 80
+      Exceptional.remote_port.should == 80
 
-      Exceptional::Config.remote_port = 3000
-      Exceptional::Config.remote_port.should == 3000
-      Exceptional::Config.remote_port = nil
+      Exceptional.remote_port = 3000
+      Exceptional.remote_port.should == 3000
+      Exceptional.remote_port = nil
     end
     
     it &quot;api_key should by default be in-valid&quot; do
-      Exceptional::Config.valid_api_key?.should be_false
-    end
-    
+      Exceptional.valid_api_key?.should be_false
+    end    
   end
 
   describe &quot;load config&quot; do
 
     it &quot;error during config file loading raises configuration exception&quot; do
       File.should_receive(:open).once.and_raise(IOError)
-
-      config_file = File.expand_path(&quot;exceptional.yml&quot;)
-      lambda{Exceptional::Config.load_config(config_file, &quot;development&quot;, File.dirname(__FILE__))}.should raise_error(Exceptional::Config::ConfigurationException)
+      
+      lambda{Exceptional.setup_config(&quot;development&quot;, File.dirname(__FILE__))}.should raise_error(Exceptional::Config::ConfigurationException)
     end
 
     it &quot;is enabled for production environment&quot; do
-      Exceptional::Config.enabled?.should be_false
+      Exceptional.enabled?.should be_false
 
-      config_file = File.join(File.dirname(__FILE__),&quot;../exceptional.yml&quot;)
-      Exceptional::Config.load_config config_file, &quot;production&quot;, File.dirname(__FILE__)
-      Exceptional::Config.enabled?.should be_true
+      Exceptional.setup_config &quot;production&quot;, File.join(File.dirname(__FILE__), &quot;/../exceptional.yml&quot;)
+      Exceptional.enabled?.should be_true
     end
 
     it &quot;is enabled by default for production and staging environments&quot; do
-      Exceptional::Config.enabled?.should be_false
-
-      config_file = File.join(File.dirname(__FILE__),&quot;../exceptional.yml&quot;)
+      Exceptional.enabled?.should be_false
 
-      Exceptional::Config.load_config config_file, &quot;production&quot;, File.dirname(__FILE__)
-      Exceptional::Config.enabled?.should be_true
+      Exceptional.setup_config &quot;production&quot;, File.join(File.dirname(__FILE__), &quot;/../exceptional.yml&quot;)
+      Exceptional.enabled?.should be_true
 
-      Exceptional::Config.reset_state
-      Exceptional::Config.enabled?.should be_false
+      Exceptional.reset_state
+      Exceptional.enabled?.should be_false
 
-      config_file = File.join(File.dirname(__FILE__),&quot;../exceptional.yml&quot;)
-      Exceptional::Config.load_config config_file, &quot;staging&quot;, File.dirname(__FILE__)
-      Exceptional::Config.enabled?.should be_true
+      Exceptional.setup_config &quot;staging&quot;, File.join(File.dirname(__FILE__), &quot;/../exceptional.yml&quot;)
+      Exceptional.enabled?.should be_true
     end
 
     it &quot;is disabled by default for development &amp; test environments&quot; do
-      Exceptional::Config.enabled?.should be_false
+      Exceptional.enabled?.should be_false
 
-      config_file = File.join(File.dirname(__FILE__),&quot;../exceptional.yml&quot;)
-      Exceptional::Config.load_config config_file, &quot;development&quot;, File.dirname(__FILE__)
-      Exceptional::Config.enabled?.should be_false
+      Exceptional.setup_config &quot;development&quot;, File.join(File.dirname(__FILE__), &quot;/../exceptional.yml&quot;)
+      Exceptional.enabled?.should be_false
 
-      Exceptional::Config.reset_state
-      Exceptional::Config.enabled?.should be_false
+      Exceptional.reset_state
+      Exceptional.enabled?.should be_false
 
-      config_file = File.join(File.dirname(__FILE__),&quot;../exceptional.yml&quot;)
-      Exceptional::Config.load_config config_file, &quot;test&quot;, File.dirname(__FILE__)
-      Exceptional::Config.enabled?.should be_false
+      Exceptional.setup_config &quot;test&quot;, File.join(File.dirname(__FILE__), &quot;/../exceptional.yml&quot;)
+      Exceptional.enabled?.should be_false
     end            
   end
-end
+end
\ No newline at end of file</diff>
      <filename>spec/config_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,44 +1,11 @@
 require File.dirname(__FILE__) + '/spec_helper'
 
+
 describe Exceptional do
 
   describe &quot;with no configuration&quot; do
     before(:each) do
-    Exceptional.stub!(:to_stderr) # Don't print error when testing
-    end
-
-    it &quot;should parse exception into exception data object&quot; do
-      exception = mock(Exception, :message =&gt; &quot;Something bad has happened&quot;,
-      :backtrace =&gt; [&quot;/app/controllers/buggy_controller.rb:29:in `index'&quot;])
-      exception_data = Exceptional.parse(exception)
-      exception_data.kind_of?(Exceptional::ExceptionData).should be_true
-      exception_data.exception_message.should == exception.message
-      exception_data.exception_backtrace.should == exception.backtrace
-      exception_data.exception_class.should == exception.class.to_s
-    end
-
-    it &quot;should post exception&quot; do
-      exception_data = mock(Exceptional::ExceptionData,
-      :message =&gt; &quot;Something bad has happened&quot;,
-      :backtrace =&gt; [&quot;/app/controllers/buggy_controller.rb:29:in `index'&quot;],
-      :class =&gt; Exception, :to_hash =&gt; { :message =&gt; &quot;Something bad has happened&quot; })
-      Exceptional::Remote.should_receive(:authenticated?).once.and_return(true)
-      Exceptional::Remote.should_receive(:call_remote, :with =&gt; [:errors, exception_data])
-
-      Exceptional.post(exception_data)
-    end
-
-    it &quot;should catch exception&quot; do
-      exception = mock(Exception, :message =&gt; &quot;Something bad has happened&quot;,
-      :backtrace =&gt; [&quot;/app/controllers/buggy_controller.rb:29:in `index'&quot;])
-      exception_data = mock(Exceptional::ExceptionData,
-      :message =&gt; &quot;Something bad has happened&quot;,
-      :backtrace =&gt; [&quot;/app/controllers/buggy_controller.rb:29:in `index'&quot;],
-      :class =&gt; Exception, :to_hash =&gt; { :message =&gt; &quot;Something bad has happened&quot; })
-      exception_data.should_receive(:controller_name=).with(File.basename($0))
-      Exceptional.should_receive(:parse, :with =&gt; [exception]).and_return(exception_data)
-      Exceptional.should_receive(:post, :with =&gt; [exception_data])
-      Exceptional.catch(exception)
+      Exceptional.stub!(:to_stderr) # Don't print error when testing
     end
 
     it &quot;should raise a remoting exception if not authenticated&quot; do
@@ -48,93 +15,62 @@ describe Exceptional do
       :class =&gt; Exception,
       :to_hash =&gt; { :message =&gt; &quot;Something bad has happened&quot; })
 
-      Exceptional::Config.api_key.should == nil
-      Exceptional::Remote.should_receive(:authenticated?).once.and_return(false)
+      Exceptional.api_key.should == nil
+      Exceptional.should_receive(:authenticated?).once.and_return(false)
 
-      lambda { Exceptional.post(exception_data) }.should raise_error(Exceptional::Remote::RemoteException)
+      lambda { Exceptional.post_exception(exception_data) }.should raise_error(Exceptional::Config::ConfigurationException)
     end
-
   end
-
-  describe &quot;with helper methods&quot; do
-
-    it &quot;safe_environment() should delete all rack related stuff from environment&quot; do
-      request = mock(request, :env =&gt; { 'rack_var' =&gt; 'value', 'non_ack' =&gt; 'value2' })
-      Exceptional.send(:safe_environment, request).should == { 'non_ack' =&gt; 'value2' }
+  
+  describe &quot;setup&quot; do
+    
+    TEST_ENVIRONMENT= &quot;development&quot;
+    
+    it &quot;should initialize the config and log&quot; do
+      Exceptional.should_receive(:setup_config)
+      Exceptional.should_receive(:setup_log)
+      
+      Exceptional.setup(TEST_ENVIRONMENT, File.dirname(__FILE__))
     end
-
-    it &quot;safe_session() should filter all /db/, /cgi/ variables and sub @ for blank&quot; do
-      class SessionHelper
-        def initialize
-          @some_var = 1
-          @cgi_var = 2
-          @x_db = 3
-        end
-      end
-
-      session = SessionHelper.new
-      Exceptional.send(:safe_session, session).should == { 'some_var' =&gt; 1 }
+    
+    it &quot;should authenticate if enabled&quot; do
+      Exceptional.should_receive(:setup_config)
+      Exceptional.should_receive(:setup_log)
+      Exceptional.should_receive(:enabled?).and_return(true)
+      Exceptional.should_receive(:authenticate).and_return(true)
+      STDERR.should_not_receive(:puts) #Should be no errors to report
+      
+      Exceptional.setup(TEST_ENVIRONMENT, File.dirname(__FILE__))
     end
-
-    it &quot;sanitize_hash() should sanitize cyclic problem for to_json&quot; do
-      class MyClass
-        def initialize
-          @test = self
-        end
-
-        def to_hash
-          { :test =&gt; self }
-        end
-      end
-      my_class = MyClass.new
-
-      lambda { my_class.to_json }.should raise_error(ActiveSupport::JSON::CircularReferenceError)
-      Exceptional.send(:sanitize_hash, my_class.to_hash).to_json.should be_kind_of(String)
+    
+    it &quot;should not authenticate if not enabled&quot; do
+      Exceptional.should_receive(:setup_config)
+      Exceptional.should_receive(:setup_log)
+      Exceptional.should_receive(:enabled?).and_return(false)
+      Exceptional.should_not_receive(:authenticate)
+      STDERR.should_not_receive(:puts) # Will silently not enable itself 
+
+      
+      Exceptional.setup(TEST_ENVIRONMENT, File.dirname(__FILE__))
     end
-
-  end
-
-
-  describe &quot;rescue&quot; do
-
-    it &quot;should send exception data onto catch&quot; do
-      Exceptional.should_receive(:catch)
-      lambda{ Exceptional.rescue do
-        raise IOError
-      end}.should raise_error(IOError)
-
+    
+    it &quot;should report to STDERR if authentication fails&quot; do
+      Exceptional.should_receive(:setup_config)
+      Exceptional.should_receive(:setup_log)
+      Exceptional.should_receive(:enabled?).and_return(true)
+      Exceptional.should_receive(:authenticate).and_return(false)
+      STDERR.should_receive(:puts) #Should be no errors to report
+      
+      Exceptional.setup(TEST_ENVIRONMENT, File.dirname(__FILE__))
     end
-  end
-
-  describe &quot;startup&quot; do
-
-    before(:all) do
-      log = Exceptional::Log
-
-      def log.reset_state
-        @log = nil
-      end
+    
+    it &quot;should report to STDERR if error during config initialization&quot; do
+      Exceptional.should_receive(:setup_config).and_raise(Exceptional::Config::ConfigurationException)
+      Exceptional.should_not_receive(:setup_log)
+      Exceptional.should_not_receive(:authenticate).and_return(false)
+      STDERR.should_receive(:puts).twice() #Should be no errors to report
+      
+      Exceptional.setup(TEST_ENVIRONMENT, File.dirname(__FILE__))
     end
-
-    after(:each) do
-      Exceptional::Log.reset_state
-    end
-
-    it &quot;should authenticate and initialize log&quot; do
-
-      Exceptional::Log.should_receive(:setup)
-      Exceptional::Remote.should_receive(:authenticate).once.and_return(true)
-
-      Exceptional.startup
-    end
-
-    it &quot;should initialize log if authentication fails&quot; do
-
-      Exceptional::Log.should_receive(:setup)
-      Exceptional::Remote.should_receive(:authenticate).once.and_return(false)
-
-      Exceptional.startup
-    end
-
   end
-end
+end
\ No newline at end of file</diff>
      <filename>spec/exceptional_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,51 +4,20 @@ describe Exceptional::Log do
 
   TEST_LOG_MESSAGE = &quot;Test-log-message&quot;
 
-  before(:all) do
-    log = Exceptional::Log
-
-    def log.reset_state
-      @log = nil
-    end
-  end
-
-  after(:each) do
-    Exceptional::Log.reset_state
-  end
-
-
-  it &quot;setup should initialize the log &quot; do
-    Exceptional::Log.log.should be_nil
-    Exceptional::Log.setup
-    Exceptional::Log.log.should_not be_nil
-  end
-
-  it &quot;setup should raise Configuration Exception if unable to initialize the log&quot; do
-    Exceptional::Log.log.should be_nil
-
-    File.should_receive(:join).once.and_raise(IOError)
-
-    lambda{Exceptional::Log.setup}.should raise_error(Exceptional::Config::ConfigurationException)
-
-    Exceptional::Log.log.should be_nil
-  end
-
-  it &quot;should default to logging to 'info'&quot; do
-    Exceptional::Log.setup
-    Exceptional::Log.log.should_not be_nil
-
-    Exceptional::Log.log.should_receive(:send).with(&quot;info&quot;, TEST_LOG_MESSAGE)
-    Exceptional::Log.log! TEST_LOG_MESSAGE
+  it &quot;uninitialized should only log to STDERR&quot; do
+    
+    STDERR.should_receive(:puts)
+    Logger.should_not_receive(:send)
+    Exceptional.log! TEST_LOG_MESSAGE
   end
 
-  it &quot;should log to both STDERR and log file&quot; do
-    Exceptional::Log.setup
-    Exceptional::Log.log.should_not be_nil
-
-    Exceptional::Log.log.should_receive(:send).with(&quot;info&quot;, TEST_LOG_MESSAGE)
+  it &quot;initialized should log to both STDERR and log file&quot; do
+    
+    Exceptional.setup_log File.dirname(File.join(File.dirname(__FILE__), &quot;..&quot;))
+    
+    Exceptional.log.should_receive(:send).with(&quot;info&quot;, TEST_LOG_MESSAGE)
     STDERR.should_receive(:puts)
 
-    Exceptional::Log.log! TEST_LOG_MESSAGE
+    Exceptional.log! TEST_LOG_MESSAGE
   end
-
 end</diff>
      <filename>spec/log_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,9 +6,7 @@ describe Exceptional::Remote do
   TEST_API_KEY = &quot;TEST_API_KEY&quot;
 
   before(:all) do
-    config = Exceptional::Config
-
-    def config.reset_state
+    def Exceptional.reset_state
       @api_key = nil
       @ssl_enabled = nil
       @log_level = nil
@@ -18,57 +16,55 @@ describe Exceptional::Remote do
       @applicaton_root = nil
     end
 
-    remoting = Exceptional::Remote
-
-    def remoting.reset_authentication
+    def Exceptional.reset_authentication
       @authenticated = false
     end
   end
 
   after(:each) do
-    Exceptional::Config.reset_state
-    Exceptional::Remote.reset_authentication
+    Exceptional.reset_state
+    Exceptional.reset_authentication
   end
 
   describe &quot;authentication&quot; do
 
     it &quot;should not be authenticated if API authentication unsuccessful&quot; do
-      Exceptional::Config.api_key = TEST_API_KEY
+      Exceptional.api_key = TEST_API_KEY
 
-      Exceptional::Remote.authenticated?.should be_false
-      Exceptional::Remote.should_receive(:call_remote, {:method =&gt; &quot;authenticate&quot;, :data =&gt; &quot;&quot;}).once.and_return(&quot;false&quot;)
-      Exceptional::Remote.authenticate.should be_false
-      Exceptional::Remote.authenticated?.should be_false
+      Exceptional.authenticated?.should be_false
+      Exceptional.should_receive(:call_remote, {:method =&gt; &quot;authenticate&quot;, :data =&gt; &quot;&quot;}).once.and_return(&quot;false&quot;)
+      Exceptional.authenticate.should be_false
+      Exceptional.authenticated?.should be_false
     end
 
     it &quot;should not be authenticated if error during API authenticate&quot; do
-      Exceptional::Config.api_key = TEST_API_KEY
+      Exceptional.api_key = TEST_API_KEY
 
-      Exceptional::Remote.authenticated?.should be_false
-      Exceptional::Remote.should_receive(:call_remote, {:method =&gt; &quot;authenticate&quot;, :data =&gt; &quot;&quot;}).once.and_raise(IOError)
+      Exceptional.authenticated?.should be_false
+      Exceptional.should_receive(:call_remote, {:method =&gt; &quot;authenticate&quot;, :data =&gt; &quot;&quot;}).once.and_raise(IOError)
 
-      Exceptional::Remote.authenticate.should be_false
-      Exceptional::Remote.authenticated?.should be_false
+      Exceptional.authenticate.should be_false
+      Exceptional.authenticated?.should be_false
     end
 
-    it &quot;should not re-authenticate subsequently if authenitcation successful &quot; do
-      Exceptional::Config.api_key = TEST_API_KEY
+    it &quot;should not re-authenticate subsequently if 1 successful &quot; do
+      Exceptional.api_key = TEST_API_KEY
 
-      Exceptional::Remote.authenticated?.should be_false
-      Exceptional::Remote.should_receive(:call_remote, {:method =&gt; &quot;authenticate&quot;, :data =&gt; &quot;&quot;}).once.and_return(&quot;true&quot;)
+      Exceptional.authenticated?.should be_false
+      Exceptional.should_receive(:call_remote, {:method =&gt; &quot;authenticate&quot;, :data =&gt; &quot;&quot;}).once.and_return(&quot;true&quot;)
       # If authentication is successful, authenticate called only once
 
-      Exceptional::Remote.authenticate.should be_true
-      Exceptional::Remote.authenticated?.should be_true
+      Exceptional.authenticate.should be_true
+      Exceptional.authenticated?.should be_true
 
-      Exceptional::Remote.authenticate.should be_true
-      Exceptional::Remote.authenticated?.should be_true
+      Exceptional.authenticate.should be_true
+      Exceptional.authenticated?.should be_true
     end
 
     it &quot;with no API Key set throws Configuration Exception&quot; do
-      Exceptional::Remote.authenticated?.should be_false
+      Exceptional.authenticated?.should be_false
 
-      lambda {Exceptional::Remote.authenticate}.should raise_error(Exceptional::Config::ConfigurationException)
+      lambda {Exceptional.authenticate}.should raise_error(Exceptional::Config::ConfigurationException)
     end
   end
 
@@ -78,10 +74,10 @@ describe Exceptional::Remote do
 
       OK_RESPONSE_BODY = &quot;OK-RESP-BODY&quot;
       
-      Exceptional::Config.api_key = TEST_API_KEY
-      Exceptional::Remote.authenticated?.should be_false
+      Exceptional.api_key = TEST_API_KEY
+      Exceptional.authenticated?.should be_false
 
-      Exceptional::Remote.should_receive(:authenticated?).once.and_return(true)
+      Exceptional.should_receive(:authenticated?).once.and_return(true)
 
       mock_http = mock(Net::HTTP)
       Net::HTTP.should_receive(:new).with(&quot;getexceptional.com&quot;, 80).once.and_return(mock_http)
@@ -92,15 +88,15 @@ describe Exceptional::Remote do
 
       mock_http.should_receive(:start).once.and_return(mock_http_response)
 
-      Exceptional::Remote.post_exception(&quot;data&quot;).should == OK_RESPONSE_BODY
+      Exceptional.post_exception(&quot;data&quot;).should == OK_RESPONSE_BODY
     end
     
     it &quot;should raise error if network problem during sending exception&quot; do
 
-      Exceptional::Config.api_key = TEST_API_KEY
-      Exceptional::Remote.authenticated?.should be_false
+      Exceptional.api_key = TEST_API_KEY
+      Exceptional.authenticated?.should be_false
 
-      Exceptional::Remote.should_receive(:authenticated?).once.and_return(true)
+      Exceptional.should_receive(:authenticated?).once.and_return(true)
 
       mock_http = mock(Net::HTTP)
       Net::HTTP.should_receive(:new).with(&quot;getexceptional.com&quot;, 80).once.and_return(mock_http)
@@ -110,17 +106,17 @@ describe Exceptional::Remote do
       mock_http.should_receive(:start).once.and_raise(IOError)
 
       #surpress the logging of the exception
-      Exceptional::Log.should_receive(:log!).twice
+      Exceptional.should_receive(:log!).twice
 
-      lambda{Exceptional::Remote.post_exception(&quot;data&quot;)}.should raise_error(IOError) 
+      lambda{Exceptional.post_exception(&quot;data&quot;)}.should raise_error(IOError) 
     end
 
     it &quot;should raise Exception if sending exception unsuccessful&quot; do
 
-      Exceptional::Config.api_key = TEST_API_KEY
-      Exceptional::Remote.authenticated?.should be_false
+      Exceptional.api_key = TEST_API_KEY
+      Exceptional.authenticated?.should be_false
 
-      Exceptional::Remote.should_receive(:authenticated?).once.and_return(true)
+      Exceptional.should_receive(:authenticated?).once.and_return(true)
 
       mock_http = mock(Net::HTTP)
       Net::HTTP.should_receive(:new).with(&quot;getexceptional.com&quot;, 80).once.and_return(mock_http)
@@ -133,9 +129,9 @@ describe Exceptional::Remote do
       mock_http.should_receive(:start).once.and_return(mock_http_response)
 
       #surpress the logging of the exception
-      Exceptional::Log.should_receive(:log!).twice
+      Exceptional.should_receive(:log!).twice
 
-      lambda{Exceptional::Remote.post_exception(&quot;data&quot;)}.should raise_error(Exceptional::Remote::RemoteException) 
+      lambda{Exceptional.post_exception(&quot;data&quot;)}.should raise_error(Exceptional::Remote::RemoteException) 
     end    
   end
 end</diff>
      <filename>spec/remote_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,7 @@ else
 end
 
 # TODO couple of different ways to test parts of exceptional with Rails (or a mock), reconcile them.
-# require 'active_support'
+#require 'active_support'
 # module Rails; end # Rails faker
 
 require File.dirname(__FILE__) + '/../lib/exceptional'</diff>
      <filename>spec/spec_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>51c601e4fc5ba36d7178b94cdcb97a0fc3c31dc2</id>
    </parent>
  </parents>
  <author>
    <name>wal</name>
    <email>walter.mcconnell@gmail.com</email>
  </author>
  <url>http://github.com/contrast/exceptional/commit/ad37322f8d8c7a4b7fc2ef0dbfa2c5ec8fdee33c</url>
  <id>ad37322f8d8c7a4b7fc2ef0dbfa2c5ec8fdee33c</id>
  <committed-date>2009-03-22T07:15:00-07:00</committed-date>
  <authored-date>2009-03-22T07:15:00-07:00</authored-date>
  <message>second phase plugin refactor</message>
  <tree>dbc01a1db26ce16e71c12980da238f600e8e6c7c</tree>
  <committer>
    <name>wal</name>
    <email>walter.mcconnell@gmail.com</email>
  </committer>
</commit>
