Skip to content

Commit

Permalink
Fix Cronitor leaking global values in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
willzoltan committed Feb 4, 2024
1 parent 03e84e0 commit b59bd46
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions spec/cronitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,28 @@
RSpec.describe Cronitor do

describe '#configure' do
it 'sets the api_key, api_version, env, ping_url and monitor_url' do
it 'sets the api_key, api_version, and env' do
Cronitor.configure do |cronitor|
cronitor.api_key = 'foo'
cronitor.api_version = 'bar'
cronitor.environment = 'baz'
cronitor.ping_url = 'https://foo.com'
cronitor.monitor_url = 'https://bar.com'
end

expect(Cronitor.api_key).to eq('foo')
expect(Cronitor.api_version).to eq('bar')
expect(Cronitor.environment).to eq('baz')
expect(Cronitor.ping_url).to eq('https://foo.com')
expect(Cronitor.monitor_url).to eq('https://bar.com')
end
end

context 'when no CRONITOR_PING_URL or CRONITOR_MONITOR_URL ENV variables are set' do
it 'returns the default Cronitor URLs' do
expect(Cronitor.ping_url).to eq('https://cronitor.link')
expect(Cronitor.monitor_url).to eq('ttps://cronitor.io')
describe '#ping_url and #monitor_url' do
let(:env_vars) { ENV }

before do
stub_const('ENV', env_vars)
# We need to reset the ping_url and monitor_url since the previous spec sets them globally
Cronitor.configure do |cronitor|
cronitor.ping_url = cronitor.default_ping_url
cronitor.monitor_url = cronitor.default_monitor_url
end
end

Expand All @@ -53,15 +55,18 @@
)
end

before do
stub_const('ENV', env_vars)
end

it 'returns the custom Cronitor URLs' do
expect(Cronitor.ping_url).to eq('https://ping.com')
expect(Cronitor.monitor_url).to eq('https://monitor.com')
end
end

context 'when no CRONITOR_PING_URL or CRONITOR_MONITOR_URL ENV variables are set' do
it 'returns the default Cronitor URLs' do
expect(Cronitor.ping_url).to eq('https://cronitor.link')
expect(Cronitor.monitor_url).to eq('https://cronitor.io')
end
end
end

describe 'YAML configuration' do
Expand Down

0 comments on commit b59bd46

Please sign in to comment.