Skip to content

Commit

Permalink
dont pollute global state when testing client_setup_block
Browse files Browse the repository at this point in the history
  • Loading branch information
pcai committed Oct 1, 2022
1 parent f02232f commit 6e405fa
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions spec/httpi/httpi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
end

describe ".adapter_client_setup=" do
after do
HTTPI.adapter_client_setup = nil
end

it "sets the adapter client setup block" do
block = proc { }
HTTPI.adapter_client_setup = block
Expand Down Expand Up @@ -290,10 +294,16 @@
client.request(:custom, request, :httpclient)
end

it 'calls client setup block if one has been set' do
block = proc { |client| client.base_url = 'https://google.com' }
HTTPI::Adapter.client_setup_block = block
client.request(:get, request, :httpclient) { |client| expect(client.base_url).to eq('https://google.com') }
describe "client setup block present" do
around do |example|
HTTPI::Adapter.client_setup_block = proc { |client| client.base_url = 'https://google.com' }
example.run
HTTPI::Adapter.client_setup_block = nil
end

it 'calls client setup block' do
client.request(:get, request, :httpclient) { |client| expect(client.base_url).to eq('https://google.com') }
end
end
end

Expand Down

0 comments on commit 6e405fa

Please sign in to comment.