如何使rspec load config.ru?
我正在使用如何使rspec load config.ru?,rspec,Rspec,我正在使用rack contribgem从HTTP\u ACCEPT\u语言头设置区域设置,因此我的config.ru文件 puts 'Running config.ru' require 'rack' require 'rack/contrib/locale' use Rack::Locale 在开发模式下运行时,我看到消息running config.ru,但在运行rspec时,我看不到消息,因此rspec没有加载config.ru 在开发模式中,语言环境按预期由Rack::locale
rack contrib
gem从HTTP\u ACCEPT\u语言头设置区域设置,因此我的config.ru
文件
puts 'Running config.ru'
require 'rack'
require 'rack/contrib/locale'
use Rack::Locale
在开发模式下运行时,我看到消息running config.ru
,但在运行rspec时,我看不到消息,因此rspec没有加载config.ru
在开发模式中,语言环境按预期由Rack::locale
设置。当我运行这个测试文件时,rspec spec/requests/localization\u spec.rb
require 'rails_helper'
describe 'Localization' do
describe 'Setting from header' do
it 'should set the locale for french' do
header 'ACCEPT_LANGUAGE', 'fr'
gets '/'
expect(last_request.env['rack.locale']).to eq 'fr'
end
end
end
区域设置没有设置为
:fr
,我看不到正在运行config.ru
mesage。RSpec不加载config.ru
,因为它不知道它是什么。您需要模拟web服务器的功能。这近似于机架测试样式设置。将Rack::Test::API
包括在您的规范中,将允许您将Rack Test与机架文件一起使用
module Rack::Test::API
include Rack::Test::Methods
def app
@app ||= Rack::Builder.parse_file('path/to/config.ru').first
end
end
你能分享你的测试吗?rspec可能没有加载你的config.ru,所以它不知道