Skip to content

Commit 7cfd820

Browse files
fix: properly mock time in ruby ci tests
1 parent 36a2a37 commit 7cfd820

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

test/cloudpayments_ruby/client_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ def test_client_retry_after_seconds
150150
end
151151

152152
def test_client_retry_after_date
153+
time_now = Time.now
154+
153155
stub_request(:post, "http://localhost/payments/cards/charge").to_return_json(
154156
status: 500,
155-
headers: {"retry-after" => (Time.now + 10).httpdate},
157+
headers: {"retry-after" => (time_now + 10).httpdate},
156158
body: {}
157159
)
158160

@@ -164,15 +166,15 @@ def test_client_retry_after_date
164166
max_retries: 1
165167
)
166168

169+
Thread.current.thread_variable_set(:time_now, time_now)
167170
assert_raises(CloudpaymentsRuby::Errors::InternalServerError) do
168-
Thread.current.thread_variable_set(:time_now, Time.now)
169171
cloudpayments.payments.charge(
170172
amount: 0,
171173
card_cryptogram_packet: "CardCryptogramPacket",
172174
ip_address: "IpAddress"
173175
)
174-
Thread.current.thread_variable_set(:time_now, nil)
175176
end
177+
Thread.current.thread_variable_set(:time_now, nil)
176178

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

0 commit comments

Comments
 (0)