Skip to content

Commit f1f1650

Browse files
authored
chore: stub_const(ENV) was not having the desired affect when testing bin/datadog_backup (#138)
1 parent c9ea751 commit f1f1650

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

spec/datadog_backup_bin_spec.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55

66
describe 'bin/datadog_backup' do
77
# Contract Or[nil,String] => self
8-
def run_bin(args = '', input = nil)
8+
def run_bin(env = {}, args = '')
99
status = nil
1010
output = ''
1111
cmd = "bin/datadog_backup #{args}"
12-
Open3.popen2e(cmd) do |i, oe, t|
12+
Open3.popen2e(env, cmd) do |i, oe, t|
1313
pid = t.pid
1414

15-
if input
16-
i.puts input
17-
i.close
18-
end
19-
2015
Timeout.timeout(4.0) do
2116
oe.each do |v|
2217
output += v
@@ -43,15 +38,14 @@ def run_bin(args = '', input = nil)
4338

4439
required_vars.map do |v|
4540
it "dies unless given ENV[#{v}]" do
46-
stub_const('ENV', env.dup.tap { |h| h.delete(v) })
47-
_, status = run_bin('backup')
41+
myenv = env.dup.tap { |h| h.delete(v) }
42+
_, status = run_bin(myenv, 'backup')
4843
expect(status).not_to be_success
4944
end
5045
end
5146

5247
it 'supplies help' do
53-
stub_const('ENV', env)
54-
out_err, status = run_bin('--help')
48+
out_err, status = run_bin(env, '--help')
5549
expect(out_err).to match(/Usage: DD_API_KEY=/)
5650
expect(status).to be_success
5751
end

0 commit comments

Comments
 (0)