Module: OpenapiRuby::Adapters::RSpec

Defined in:
lib/openapi_ruby/adapters/rspec.rb

Defined Under Namespace

Modules: ExampleGroupHelpers, ExampleHelpers

Class Method Summary collapse

Class Method Details

.install!Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/openapi_ruby/adapters/rspec.rb', line 271

def self.install!
  ::RSpec.configure do |config|
    config.extend ExampleGroupHelpers, type: :openapi
    config.include ExampleHelpers, type: :openapi

    if defined?(::RSpec::Rails)
      config.include ::RSpec::Rails::RequestExampleGroup, type: :openapi
    end

    config.after(:suite) do
      OpenapiRuby::Generator::SchemaWriter.generate_all!
    rescue => e
      warn "[openapi_ruby] Schema generation failed: #{e.message}"
    end

    # RSpec's --dry-run mode does not fire after(:suite) hooks.
    # Describe/context blocks are still evaluated (registering DSL contexts),
    # but the hook that writes schemas never runs. Use at_exit as a fallback.
    if config.dry_run?
      at_exit do
        OpenapiRuby::Generator::SchemaWriter.generate_all!
      rescue => e
        warn "[openapi_ruby] Schema generation failed: #{e.message}"
      end
    end
  end
end