我想将在其他文件中定义的基本http auth添加到我的规格中。我想使用来自secret.yml的ENV凭据。我想我必须在端点中添加一行,但这是我的问题。
index_spec.rb
describe API::V1::Inquiries::ExportsData::Index, type: :request do
subject(:call) { get endpoint, params: params }
let(:endpoint) { "/api/v1/inquiries/export_data?shop_code=#{shop.code}" }
let(:params) { { shop_code: '98918081' } }
# several `let` with expected_data let either
it 'returns expected value' do
call
expect(data).to match_array(expected_data)
end
end
base.rb
class Base < Grape::API
mount Inquiries::ExportsData::Index
before do
authenticate!
end
helpers do
def authenticate!
authenticate_or_request_with_http_basic do |username, password|
username == Rails.applications.secrets.ENV['EXPORT_API_USERNAME'] &&
password == Rails.applications.secrets.ENV['EXPORT_API_PASSWORD']
end
end
end
end