Testing API Name Resolution Capabilities in ruby-grape/grape
This test suite validates the naming functionality in Grape API, specifically focusing on endpoint identification and API class naming capabilities. It ensures proper handling of named API instances and verifies the ability to access API names at runtime.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
ruby-grape/grape
spec/grape/named_api_spec.rb
# frozen_string_literal: true
describe Grape::API do
subject(:api_name) { NamedAPI.endpoints.last.options[:for].to_s }
let(:api) do
Class.new(Grape::API) do
get 'test' do
'response'
end
end
end
let(:name) { 'NamedAPI' }
before { stub_const(name, api) }
it 'can access the name of the API' do
expect(api_name).to eq name
end
end