Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined method for config.swagger_root for Rspec core

I have used rswag before, with exactly the same setup. But for some reason i can not run my rspec or rake rswag:specs:swaggerize; i always get the error the method 'swagger-root=' undefined. I can't find out why.

I already tried to install all the rswag files again; rails g rswag:api:install rswag:ui:install RAILS_ENV=test rails g rswag:specs:install i also tried to install rspec again.

""An error occurred while loading ./spec/integration/translations_spec.rb. Failure/Error: config.swagger_root = Rails.root.to_s + '/swagger'

NoMethodError: undefined method `swagger_root=' for #""

/spec/swagger_helper.rb

require 'rails_helper'

RSpec.configure do |config|

  config.swagger_root = Rails.root.to_s + '/swagger'

  config.swagger_docs = {
    'v1/swagger.json' => {
      swagger: '2.0',
      info: {
        title: 'API V1',
        version: 'v1'
      },
      paths: {}
    }
  }
end
like image 888
Anne Avatar asked Oct 28 '25 07:10

Anne


1 Answers

After trying a lot of things, this eventually seemed the answer: changing two lines in the spec_helper file. From this:

root = File.expand_path('../', File.dirname(__FILE__))
Dir[File.join(root,'lib/**/*.rb')].each { |f| require f }

To this:

require File.expand_path("../../config/environment", __FILE__)

Probably the word 'root' should not be used here..

like image 102
Anne Avatar answered Oct 31 '25 01:10

Anne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!