Module: Airtable::ORM::Testing::StubHelpers
- Defined in:
- lib/airtable/orm/testing/stub_helpers.rb
Overview
Include into RSpec (config.include Airtable::ORM::Testing::StubHelpers, :airtable)
and call stub_airtable_http_client in a before hook — no HTTP leaves the process.
Instance Method Summary collapse
-
#stub_airtable_http_client ⇒ Object
Route every request through a Faraday test adapter (returned for stubbing) and bypass the API-key check in Http::Client.default with a real client instance so escape/other helpers keep working.
-
#stub_airtable_schema ⇒ Object
Stub schema fetch to use the fixture file instead of the /v0/meta API.
Instance Method Details
#stub_airtable_http_client ⇒ Object
Route every request through a Faraday test adapter (returned for stubbing) and bypass the API-key check in Http::Client.default with a real client instance so escape/other helpers keep working.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/airtable/orm/testing/stub_helpers.rb', line 33 def stub_airtable_http_client @stubs = Faraday::Adapter::Test::Stubs.new stub_connection = Faraday.new do |builder| builder.request :json builder.response :json builder.adapter :test, @stubs end fake_client = Airtable::ORM::Http::Client.new("test_api_key") allow(fake_client).to receive(:connection).and_return(stub_connection) allow(Airtable::ORM::Http::Client).to receive(:default).and_return(fake_client) stub_airtable_schema @stubs end |
#stub_airtable_schema ⇒ Object
Stub schema fetch to use the fixture file instead of the /v0/meta API. Returns the same schema data for all fetch calls, so tests work regardless of which base they're configured for.
20 21 22 23 24 25 26 27 28 |
# File 'lib/airtable/orm/testing/stub_helpers.rb', line 20 def stub_airtable_schema path = Testing.schema_fixture_path raise ArgumentError, "Set Airtable::ORM::Testing.schema_fixture_path first" unless path raw_schema = JSON.parse(File.read(path)) indexed_schema = Airtable::ORM::Schema.send(:indexed_schema, raw_schema) allow(Airtable::ORM::Schema).to receive(:fetch).and_return(indexed_schema) end |