Sinatra的RSpec始终在开发中运行

时间:2018-01-17 16:29:46

标签: rspec sinatra

我正在尝试让RSpec在一个简单的Sinatra应用程序中运行,但每次运行我的测试套件时,它都会以开发模式而不是测试模式运行。

根据我所读到的内容,我的spec_helper是正确的,但它仍然始终使用开发环境。

规格/ spec_helper.rb

# spec/spec_helper.rb
ENV['RACK_ENV'] = 'test'

require File.expand_path './../../app.rb', __FILE__
require 'rack/test'
require 'rspec'

module RSpecMixin
  include Rack::Test::Methods
  def app; App; end
end

RSpec.configure do |config|
  config.include RSpecMixin
end

我错过了什么?

1 个答案:

答案 0 :(得分:0)

根据此文档:http://sinatrarb.com/configuration.html#environment---configurationdeployment-environment

当没有设置RACK_ENV时,该值默认为:development。我猜测app(和配置)已经初始化ENV['RACK_ENV'] = 'test'中的spec/spec_helper.rb

您可以检查require File.expand_path './../../app.rb', __FILE__是否返回true。

相关问题