From 8dbc435c8c545168501e25fe10d42fea3f646fb7 Mon Sep 17 00:00:00 2001 From: Bobby McDonald Date: Mon, 11 Nov 2019 00:27:36 -0500 Subject: [PATCH] Reset config options in between tests The settings tests were causing tests in other files to fail depending on the order they were run in. We'll reset the config values after each expectation. --- spec/omniauth/builder_spec.rb | 42 ++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/spec/omniauth/builder_spec.rb b/spec/omniauth/builder_spec.rb index fe24eba..7e58770 100644 --- a/spec/omniauth/builder_spec.rb +++ b/spec/omniauth/builder_spec.rb @@ -9,9 +9,17 @@ describe OmniAuth::Builder do it 'calls original when rack 1.4' do allow(Rack).to receive(:release).and_return('1.4.0') - expect(builder).to receive(:new).with(app).and_call_original + expect(builder).to receive(:new).with(app, &prok).and_call_original - builder.new(app) + builder.new(app, &prok) + end + + it 'calls original when rack 2' do + allow(Rack).to receive(:release).and_return('2.0.0') + + expect(builder).to receive(:new).with(app, &prok).and_call_original + + builder.new(app, &prok) end end @@ -66,9 +74,11 @@ describe OmniAuth::Builder do it 'passes the block to the config' do prok = proc {} - OmniAuth::Builder.new(nil).on_failure(&prok) + with_config_reset(:on_failure) do + OmniAuth::Builder.new(nil).on_failure(&prok) - expect(OmniAuth.config.on_failure).to eq(prok) + expect(OmniAuth.config.on_failure).to eq(prok) + end end end @@ -76,9 +86,11 @@ describe OmniAuth::Builder do it 'passes the block to the config' do prok = proc {} - OmniAuth::Builder.new(nil).before_options_phase(&prok) + with_config_reset(:before_options_phase) do + OmniAuth::Builder.new(nil).before_options_phase(&prok) - expect(OmniAuth.config.before_options_phase).to eq(prok) + expect(OmniAuth.config.before_options_phase).to eq(prok) + end end end @@ -86,9 +98,11 @@ describe OmniAuth::Builder do it 'passes the block to the config' do prok = proc {} - OmniAuth::Builder.new(nil).before_request_phase(&prok) + with_config_reset(:before_request_phase) do + OmniAuth::Builder.new(nil).before_request_phase(&prok) - expect(OmniAuth.config.before_request_phase).to eq(prok) + expect(OmniAuth.config.before_request_phase).to eq(prok) + end end end @@ -96,9 +110,11 @@ describe OmniAuth::Builder do it 'passes the block to the config' do prok = proc {} - OmniAuth::Builder.new(nil).before_callback_phase(&prok) + with_config_reset(:before_callback_phase) do + OmniAuth::Builder.new(nil).before_callback_phase(&prok) - expect(OmniAuth.config.before_callback_phase).to eq(prok) + expect(OmniAuth.config.before_callback_phase).to eq(prok) + end end end @@ -127,4 +143,10 @@ describe OmniAuth::Builder do expect(app).to have_received(:call).with(env) end end + + def with_config_reset(option) + old_config = OmniAuth.config.send(option) + yield + OmniAuth.config.send("#{option}=", old_config) + end end