当测试 运行 时,是否有日志可以查看 rspec 实际在做什么?

Is there a log to see what rspec is actually doing when test are being run?

所以我正在尝试为我的 API

编写一些测试

我有这个url /v1/users?api_key=1:--XsF99m7wcvFFzTt-Js

如果我在浏览器中访问它,它工作正常并且会返回一些 JSON。

不过,在我的测试中是

require 'rails_helper'
RSpec.describe "GET /users/index" do

  it 'returns a 200' do
    get "/v1/users?api_key=1:--XsF99m7wcvFFzTt-Js"
    expect(response.status).to eq(200)
  end
 end

当我 运行 RSpec 它给我这个错误

ActionView::MissingTemplate:
   Missing template v1/users/index, api_v1/index, application/index with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}. Searched in:

我不明白为什么好像我将 url 粘贴到浏览器中它工作正常。

那么首先那个respec测试有什么问题吗? 同样在调试方面,您打算如何调试?因为我看不到任何日志文件,如果您通过浏览器执行它会看到 development.log 填满

  1. render_views 添加到您的描述块。
  2. 您可以跟踪或查看位于 /log/ 文件夹中的 test.log

根据我收集到的信息,您正在尝试测试 JSON 对 API 的响应。但是,您似乎在 GET 请求中请求 HTML 格式。

您对 users/index 的看法是 JSON 吗?如果是这样,那就是错误的根源,在 GET 请求中指定 format: :json 应该可以解决问题。您还可以使用

为所有操作指定 json 类型
before do
   request.accept = "application/json"
end

在描述操作开始时。

根据您最初的问题,RSpec 测试记录在 log/test.log