| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- # test/support/stubs.rb
- #
- # Lightweight stubs for DB and Http so that lib/geocode.rb can be loaded in
- # unit tests without a real database connection or network access.
- #
- # Usage — require this file BEFORE requiring any lib that depends on DB or Http:
- #
- # require_relative "support/stubs"
- # require_relative "../../lib/geocode"
- # Stub DB module — pure validation logic is implemented here so that
- # validate_table_name! can be tested directly.
- module DB
- SAFE_TABLE_NAME_RE = /\Ada_[a-z0-9_]+\z/
- def self.validate_table_name!(name)
- unless name.to_s.match?(SAFE_TABLE_NAME_RE)
- raise ArgumentError, "Unsafe table name: #{name.inspect} — must match #{SAFE_TABLE_NAME_RE}"
- end
- name
- end
- def self.client
- raise NotImplementedError, "DB.client is not available in unit tests"
- end
- end
- # Stub Http module — no network calls in unit tests
- module Http
- def self.get(*)
- raise NotImplementedError, "Http.get is not available in unit tests"
- end
- end
- # Prevent require_relative inside lib files from loading the real db.rb / http.rb,
- # which would overwrite the stubs above and pull in the mysql2 gem.
- # Use File.dirname so expand_path treats the base as a directory, not a file.
- _test_support_dir = File.dirname(File.expand_path(__FILE__))
- $LOADED_FEATURES << File.expand_path("../../lib/db.rb", _test_support_dir)
- $LOADED_FEATURES << File.expand_path("../../lib/http.rb", _test_support_dir)
|