Skip to content

Commit ac193de

Browse files
fix: properly mock time in ruby ci tests
1 parent 508b031 commit ac193de

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

test/lithic/client_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,21 @@ def test_client_retry_after_seconds
107107
end
108108

109109
def test_client_retry_after_date
110+
time_now = Time.now
111+
110112
stub_request(:post, "http://localhost/v1/cards").to_return_json(
111113
status: 500,
112-
headers: {"retry-after" => (Time.now + 10).httpdate},
114+
headers: {"retry-after" => (time_now + 10).httpdate},
113115
body: {}
114116
)
115117

116118
lithic = Lithic::Client.new(base_url: "http://localhost", api_key: "My Lithic API Key", max_retries: 1)
117119

120+
Thread.current.thread_variable_set(:time_now, time_now)
118121
assert_raises(Lithic::Errors::InternalServerError) do
119-
Thread.current.thread_variable_set(:time_now, Time.now)
120122
lithic.cards.create(type: :VIRTUAL)
121-
Thread.current.thread_variable_set(:time_now, nil)
122123
end
124+
Thread.current.thread_variable_set(:time_now, nil)
123125

124126
assert_requested(:any, /./, times: 2)
125127
assert_in_delta(10, Thread.current.thread_variable_get(:mock_sleep).last, 1.0)

0 commit comments

Comments
 (0)