我正在玩 Jeremy Evans 的 RODA https://roda.jeremyevans.net/。但是,我在为我的 Test_Environment 设置环境变量时遇到问题。
config/initializers/contenful_model.rb
ContentfulModel.configure do |config|
config.space = ENV.fetch('CONTENTFUL_SPACE_ID')
config.access_token = ENV.fetch('CONTENTFUL_ACCESS_TOKEN')
config.environment = "master"
end
.env.rb
case ENV['RACK_ENV'] ||= 'development'
when 'test'
ENV['CONTENTFUL_SPACE_ID'] ='key-here'
ENV['CONTENTFUL_ACCESS_TOKEN'] =''
when 'production'
ENV['CONTENTFUL_SPACE_ID'] ='key-here'
ENV['CONTENTFUL_ACCESS_TOKEN'] ='key-here'
else
ENV['CONTENTFUL_SPACE_ID'] ='key-here'
ENV['CONTENTFUL_ACCESS_TOKEN'] ='key-here'
end
规范/spec_helper.rb
ENV["RACK_ENV"] = "test"
require_relative '../../models/recipe'
require_relative '../../config/initializers/contentful_model'
require_relative '../minitest_helper'
它适用于开发,但是,初始化程序中的配置在测试环境中不可用。我目前在spec/spec_helper.rb中对这些凭据进行硬编码,公开它们没有意义。我确实在我的.env.rb文件中为 Test RACK_ENV 设置了 ENV 变量,但我的测试环境无法访问它。如何获得可用于测试环境的环境变量?