导轨 6.0.0
红宝石 2.6.3
gem 'rspec-rails', '~> 3.8.2'
gem 'devise_token_auth', '~> 1.1.3' (默认设置)
除了我的 rspec 请求响应不包含access-token
.
检查时,我得到
[1] pry> response.headers
=> {"X-Frame-Options"=>"SAMEORIGIN",
"X-XSS-Protection"=>"1; mode=block",
"X-Content-Type-Options"=>"nosniff",
"X-Download-Options"=>"noopen",
"X-Permitted-Cross-Domain-Policies"=>"none",
"Referrer-Policy"=>"strict-origin-when-cross-origin",
"Content-Type"=>"application/json; charset=utf-8",
"access-token"=>" ",
"token-type"=>"Bearer",
"client"=>"Vy7BgunZKjUcPq_Qe5IXRQ",
"expiry"=>" ",
"uid"=>"example1@example.com",
"ETag"=>"W/\"1ecd5da9ea592fde4b83f7ae6b6906ff\"",
"Cache-Control"=>"max-age=0, private, must-revalidate",
"X-Request-Id"=>"6cbc675a-f50c-4bf7-be0f-07ebf120285b",
"X-Runtime"=>"0.042266",
"Vary"=>"Origin",
"Content-Length"=>"28"}
注意,access-token
标题只包含一个空格(也过期)。在开发环境中并非如此,一切似乎都按预期工作。所以,我觉得我在我的 RSpec 配置或 rails_helper 中遗漏了一些东西。
这样做的一个副作用是,我的 API 文档auth-token
在生成时只是省略了密钥(和到期)。
有任何想法吗?
样品规格
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Api::V1::Clients', type: :request do
let(:user) { FactoryBot.create(:user) }
let(:client) { FactoryBot.create(:client) }
let(:headers) do
{
'Content-Type': 'application/json',
'Accept': 'application/json'
}
end
describe 'GET /api/v1/clients' do
before { client }
it 'returns a 200 status code', :dox do
get api_v1_clients_path, headers: headers.merge!(user.create_new_auth_token)
expect(response).to have_http_status(200)
end
end
end