2

运行 rspec 测试用例时出现此错误。

swagger doc 正在正确创建。我想我缺少一些与 rspec 相关的配置更改路由。

我正在分享我的规范文件以供参考,请检查。如果您需要任何其他详细信息,请告诉我。

Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
       No route matches [POST] "/api/v1/orders"

describe 'Orders API' do
  path '/orders' do
    post 'Get menu for new business order' do
      tags 'Business Orders'
      parameter name: :business_order, in: :body, schema: {
        type: :object,
        properties: {
          latitude: { type: :string },
          longitude: { type: :string }
        },
        required: ['latitude', 'longitude' ]
      }
      response '200', 'success' do
        let(:business_order) { {latitude: 0.000,longitude: 0.00 } }
        run_test!
      end
    end
  end
end
4

1 回答 1

6

现在回答已经很晚了,但是我在将 Rswag 添加到我在 Rails 4.2 上的应用程序时遇到了类似的问题

将以下行添加到 spec_helper.rb 文件将全局设置所有请求规范的主机并解决 RoutingError。

RSpec.configure do |config|
  config.before(:each, type: :request) do
    host! "api.lvh.me"
  end
end
于 2020-08-14T11:45:32.960 回答