To use RSpec::RequestDescriber, include the module in your RSpec configuration (typically in rails_helper.rb or spec_helper.rb).
When included, the module automatically sets up a subject that executes send_request. It also provides several let helpers that you can override in your request specs to define the request behavior:
headers: A hash of HTTP headers. The plugin automatically transforms these into the appropriate Rack env format (e.g., Content-Type becomes CONTENT_TYPE, while reserved names like host are handled specifically).params: A hash of request parameters. If the Content-Type header is set to application/json, these params will be automatically converted to a JSON string.request_body: An internal helper used to determine the body sent to the request based on the params and headers configuration.
Important Requirement: Your describe or context blocks must follow a specific naming convention to define the HTTP method and path. The format must be "METHOD /path" (e.g., describe 'GET /users').
# In your spec file
RSpec::RequestDescriber.included do
# The module provides these helpers for you to override
let(:headers) { { 'Authorization' => 'Bearer token' } }
let(:params) { { id: 1 } }
end
# The describe block MUST follow the 'METHOD /path' pattern
describe 'GET /users/:id' do
# You can define methods for path parameters here
def id
'123'
end
it 'returns success' do
expect(subject.status).to eq(200)
end
end