Sha256: fccb5a7d1315d1c634696ff093af53573bea250a073e9dd48421ddd30d001914

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rubygems'

require 'geo_certs'

require 'test/unit'
require 'uri'
require 'shoulda'
require 'factory_girl'
require 'factories'
require 'mocha'

# Load any initializers for testing.
Dir[File.dirname(__FILE__) + '/config/initializers/**/*.rb'].sort.each do |initializer|
  require initializer
end

class Test::Unit::TestCase
  
  def managed_server_request(method, path, options = {}, &block)
    case path
    when String
      uri           = URI.parse(GeoCerts::API::ENDPOINT.gsub(':version', '1') + path)
      uri.user      = GeoCerts.partner_id
      uri.password  = GeoCerts.api_token
      FakeWeb.register_uri(method, uri.to_s, options)
    when Regexp
      FakeWeb.register_uri(method, path, options)
    end unless use_remote_server?
    
    yield
  ensure
    FakeWeb.clean_registry
  end
  
  def exclusively_mocked_request(method, url, options = {}, &block)
    managed_server_request(method, url, options, &block) unless use_remote_server?
  end
  
  def assert_responds_with_exception(exception, *error_codes, &block)
    raised = false
    begin
      yield
    rescue exception => e
      return unless e.respond_to?(:errors)
      error_codes.each do |code|
        assert e.errors.any? { |error| error.code == code }, "No error was returned with Code #{code}\n#{e.errors.inspect}"
      end
      raised = true
    rescue Exception => e
      flunk "A #{e} exception was thrown, rather than the #{exception} exception expected"
    end
    flunk "A #{exception} exception failed to be thrown" unless raised
  end
  
  def assert_responds_without_exception(exception, *error_codes, &block)
    begin
      yield
      assert true # no exceptions were raised
    rescue exception => e
      flunk "A #{exception} exception was unexpectedly raised"
    rescue Exception
      assert true # it wasn't the watched for exception.
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geocerts-0.0.11 test/test_helper.rb