alexreisner/geocoder · error · ArgumentError

unknown stub request #

Error message

unknown stub request #{query_text}

What it means

Geocoder's Test lookup raises ArgumentError when results are requested for a query that has no stub registered and no default stub is set. It exists purely for test suites, so this means your test data does not cover that query.

Solutions

  1. Register the missing stub: Geocoder::Lookup::Test.add_stub('the query text', [result])
  2. Call Geocoder::Lookup::Test.set_default_stub([...]) for a catch-all
  3. Align the query string in the test with the one actually generated (URL-encoded text)
  4. Reset stubs between tests to avoid stale expectations

Example fix

// before
Geocoder.search('1600 amphitheatre parkway') # no stub
// after
Geocoder::Lookup::Test.add_stub('1600 amphitheatre parkway', [{'latitude' => 37.42, 'longitude' => -122.08}])
Geocoder.search('1600 amphitheatre parkway')
Defensive patterns

Strategy: validation

Validate before calling

raise 'no stub' unless Geocoder::Lookup::Test.stubs.key?(query_text) || Geocoder::Lookup::Test.instance_variable_get(:@default_stub)

Try / catch

begin
  results = Geocoder.search(address)
rescue ArgumentError => e
  raise "missing stub: #{e.message}"
end

Prevention

When it happens

Trigger: Calling Geocoder.search('some address') with lookup Test while only other query strings were stubbed via Geocoder::Lookup::Test.add_stub, and no set_default_stub was called.

Common situations: Test fixtures drifting from the addresses used in code under test; refactoring addresses/URL fragments without updating stubs; locale or normalization differences changing the query text.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of alexreisner/geocoder@c10bd70121 (2026-09-15). Data as JSON: /api/errors/9f5d34c0257033e4. Report an issue: GitHub.

Appendix: source

Thrown at lib/geocoder/lookups/test.rb:24

    class Test < Base

      def name
        "Test"
      end

      def self.add_stub(query_text, results)
        stubs[query_text] = results
      end

      def self.set_default_stub(results)
        @default_stub = results
      end

      def self.read_stub(query_text)
        @default_stub ||= nil
        stubs.fetch(query_text) {
          return @default_stub unless @default_stub.nil?
          raise ArgumentError, "unknown stub request #{query_text}"
        }
      end

      def self.stubs
        @stubs ||= {}
      end

      def self.delete_stub(query_text)
        stubs.delete(query_text)
      end

      def self.reset
        @stubs = {}
        @default_stub = nil
      end

      private

View on GitHub (pinned to c10bd70121)