spec/sitehub/middleware/config_loader_spec.rb in sitehub-0.5.0.alpha8 vs spec/sitehub/middleware/config_loader_spec.rb in sitehub-0.5.0.alpha10
- old
+ new
@@ -1,5 +1,6 @@
+require 'timecop'
class SiteHub
module Middleware
describe ConfigLoader do
let(:server_url) { 'http://www.server.url' }
@@ -24,19 +25,18 @@
before do
stub_request(:get, server_url).to_return(body: config.to_json)
end
- let(:no_caching) { { force: true } }
+ let(:cache_settings) { { expires_in: 1 } }
subject do
- described_class.new(:app, server_url, caching_options: no_caching)
+ described_class.new(:app, server_url, caching_options: cache_settings)
end
describe '#load_config' do
subject do
- caching_enabled = { expires_in: 30 }
- described_class.new(:app, server_url, caching_options: caching_enabled)
+ described_class.new(:app, server_url, caching_options: cache_settings)
end
let(:expected_core) do
Core.new do
sitehub_cookie_name 'sitehub.recorded_route'
@@ -99,11 +99,11 @@
end
end
context 'config previously loaded' do
subject do
- described_class.new(:app, server_url, caching_options: no_caching)
+ described_class.new(:app, server_url, caching_options: cache_settings)
end
let(:response) { [200, {}, []] }
before do
app = proc do |_env|
@@ -111,9 +111,10 @@
end
expect(config_server).to receive(:get).and_return(config)
expect(Core).to receive(:from_hash).with(config).and_return(double(build: app))
subject.call(env)
+ Timecop.travel(2)
end
it 'retains the original config' do
expect(config_server).to receive(:get).and_raise(ConfigServer::Error)
expect(subject.call(env)).to eq(response)