Skip to content

example_mode: :none leaks response descriptions depending on test execution order #318

@K4sku

Description

@K4sku

Problem

When example_mode: :none is set on a test, it correctly prevents recording examples to the OpenAPI output, but it does not prevent overwriting the response description. Since RSpec runs tests in random order, a test marked with example_mode: :none can run last for a given endpoint+status code and its description (derived from describe/context/it blocks) overwrites the description from a documented test.

Steps to reproduce

  1. Have two tests for the same endpoint — one documented (default or :single/:multiple) and one with example_mode: :none
  2. Run the suite multiple times with different random seeds
  3. Observe that the response description in the generated YAML changes depending on which test runs last
describe 'GET /api/events', openapi: { example_mode: :multiple } do
  it 'returns the owner\'s events' do
    get '/api/events'
    expect(response.status).to eq(200)
  end
end

describe 'GET /api/events', openapi: { example_mode: :none } do
  it 'paginates results' do
    get '/api/events', params: { page: 2 }
    expect(response.status).to eq(200)
  end
end

Expected description: "Returns the owner's events"
Actual description (when the :none test runs last): "Paginates results"

Expected behavior

example_mode: :none should prevent the test from overwriting an existing response description, just as it prevents recording examples. The description should still be recorded if the :none test is the first or only test for that endpoint (since description is a required field in the OpenAPI Response Object).

Environment

  • rspec-openapi 0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions