【问题标题】:RSpec test health endpoint without controller or action没有控制器或操作的 RSpec 测试健康端点
【发布时间】:2020-05-19 19:10:08
【问题描述】:

我的routes.rb 中有类似这样的代码

get '/health', to: proc { [200, {}, ['']] }

我需要编写 RSpec 测试。

我只有这一行没有任何定义的控制器或动作,是否可以创建这样的规范?

【问题讨论】:

    标签: ruby-on-rails rspec


    【解决方案1】:

    简单的请求规范呢?也许是这样的:

    require "rails_helper"
    
    RSpec.describe "Health check", type: :request do
      it "does return 200 status" do
        get "/health"
        expect(response.status).to eq 200
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多