Back to Repositories

Testing Melissa Street Geocoding Integration in geocoder

This test suite validates the Melissa Street geocoding service integration within the Geocoder gem, focusing on address parsing and error handling capabilities.

Test Coverage Overview

The test suite comprehensively covers address component parsing, accuracy levels, and API key validation for the Melissa Street geocoding service.

  • Address component extraction and validation
  • Coordinate accuracy verification
  • Low accuracy result handling
  • API key authentication testing

Implementation Analysis

The testing approach utilizes Ruby’s unit testing framework with the GeocoderTestCase base class. It implements a structured setup for API configuration and employs assertion-based validation patterns for geocoding responses.

  • Individual component testing methodology
  • Error condition handling verification
  • Configuration management testing

Technical Details

  • Ruby test framework implementation
  • GeocoderTestCase custom test class
  • Melissa Street API integration
  • Configuration-based setup
  • Exception handling verification

Best Practices Demonstrated

The test suite exhibits strong testing practices through isolated test cases, proper setup/teardown management, and comprehensive error handling verification.

  • Modular test case organization
  • Explicit assertion statements
  • Proper API configuration handling
  • Comprehensive error case coverage

alexreisner/geocoder

test/unit/lookups/melissa_street_test.rb

            
# encoding: utf-8
require 'test_helper'

class MelissaStreetTest < GeocoderTestCase

  def setup
    super
    Geocoder.configure(lookup: :melissa_street)
    set_api_key!(:melissa_street)
  end

  def test_result_components
    result = Geocoder.search("1 Frank H Ogawa Plz Fl 3").first
    assert_equal "1", result.number
    assert_equal "1 Frank H Ogawa Plz Fl 3", result.street_address
    assert_equal "Plz", result.suffix
    assert_equal "CA", result.state
    assert_equal "94612-1932", result.postal_code
    assert_equal "Oakland", result.city
    assert_equal "US", result.country_code
    assert_equal "United States of America", result.country
    assert_equal([37.805402, -122.272797], result.coordinates)
  end

  def test_low_accuracy
    result = Geocoder.search("low accuracy").first
    assert_equal "United States of America", result.country
  end

  def test_raises_api_key_exception
    Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey])
    assert_raises Geocoder::InvalidApiKey do
      Geocoder.search("invalid key")
    end
  end
end