forked from aws/aws-sdk-ruby
/
shared_spec_helper.rb
43 lines (36 loc) · 1.64 KB
/
shared_spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
$LOAD_PATH.unshift(File.expand_path('../../../aws-sigv2/lib', __FILE__))
$LOAD_PATH.unshift(File.expand_path('../../../aws-sigv4/lib', __FILE__))
$LOAD_PATH.unshift(File.expand_path('../../../aws-eventstream/lib', __FILE__))
$LOAD_PATH.unshift(File.expand_path('../../../aws-partitions/lib', __FILE__))
require 'webmock/rspec'
# Prevent the SDK unit tests from loading actual credentials while under test.
# By default the SDK attempts to load credentials from:
#
# * ENV, e.g. ENV['AWS_ACCESS_KEY_ID']
# * Shared credentials file, e.g. ~/.aws/credentials
# * EC2 instance metadata server running at 169.254.169.254
#
RSpec.configure do |config|
config.before(:each) do
# disable loading credentials from shared file
allow(Dir).to receive(:home).and_raise(ArgumentError)
# disable instance profile credentials
token_path = '/latest/api/token'
path = '/latest/meta-data/iam/security-credentials/'
stub_request(:get, "http://169.254.169.254#{path}").to_raise(SocketError)
stub_request(:put, "http://169.254.169.254#{token_path}").to_raise(SocketError)
Aws.shared_config.fresh
end
# Thread.report_on_exception was set to default true in Ruby 2.5
# When testing code that intentionally has threads that raise exceptions
# disable printing of those exceptions.
config.around(:each, thread_report_on_exception: false) do |example|
if Thread.respond_to?(:report_on_exception)
current_value = Thread.report_on_exception
Thread.report_on_exception = false
end
example.call
Thread.report_on_exception = current_value if current_value
end
end