-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract endpoints into config file #27
Changes from all commits
f011596
4ea2077
7c0e1e2
16d225e
03e84e0
b59bd46
38b3092
2fa6076
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,40 @@ | |
end | ||
end | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @willzoltan thank you for these! I think the specs need to be updated to not reference There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry I forgot to commit all my changes... Fixed! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed again. Sorry I don't have the test suite set up on my computer |
||
cronitor.monitor_url = cronitor.default_monitor_url | ||
end | ||
end | ||
|
||
context 'when custom CRONITOR_PING_URL and CRONITOR_MONITOR_URL ENV variables are set' do | ||
let(:env_vars) do | ||
ENV.to_hash.merge( | ||
'CRONITOR_PING_URL' => 'https://ping.com', | ||
'CRONITOR_MONITOR_URL' => 'https://monitor.com' | ||
) | ||
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 | ||
before(:all) do | ||
Cronitor.configure do |cronitor| | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kinda nit-picky on my part, so take it with a grain of salt, but since it's reading from the ENV var, these aren't really "defaults". Could we keep setting these the same as before, and then in the test set up where these methods are used just set the defaults correctly there?
Or, if you want to keep these methods, just have them return the string only instead of calling ENV.fetch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't originally going to add these methods, but basically we need a method to reset the ping_url and the monitor_url from the test suite. This is because
Crontior
is like a god object, so when the first test sets the values of ping_url and the monitor_url, the second test retains the previous values. There is no way to flush or reload theCronitor
class.But we need to load a fresh
Cronitor
class twice for the test suite. Once for when there are no ENV vars. And then again when there are ENV vars.So these
default_*
methods allow me to callself.ping_url = default_ping_url
before each test, just like they are called when theCronitor
class loads, so that when we change the ENV vars for the second test, the tests then behave properly and actually read the ENV vars instead of retaining the values from the first test.We could copy the code which sets the initial ping_url and monitor_url values into the test suite and have something like below in the spec instead.
In my view this is worse, because it is not DRY and if the code in
lib/cronitor/config.rb
changes, then we are not testing theCronitor
class, but testing the code that is in thebefore
block.Would changing the name of the methods from
default_*
toinitial_*
be better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aflanagan