Module: DoSnapshot::RSpec::Environment
- Extended by:
- RSpec::Core::SharedContext
- Includes:
- ApiHelpers
- Defined in:
- lib/do_snapshot/rspec/environment.rb
Overview
rubocop:disable Style/Documentation
Instance Method Summary
collapse
Methods included from ApiHelpers
#stub_with_id, #stub_with_id_name, #stub_without_id, #url_with_event_id, #url_with_id, #url_with_id_name
Instance Method Details
#default_stub_api ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/do_snapshot/rspec/environment.rb', line 64
def default_stub_api
{
stub_event_done: stub_event_done(event_id),
stub_droplets: stub_droplets,
stub_image_destroy1: stub_image_destroy(image_id),
stub_image_destroy2: stub_image_destroy(image_id2)
}
end
|
#do_not_send_email ⇒ Object
9
10
11
|
# File 'lib/do_snapshot/rspec/environment.rb', line 9
def do_not_send_email
allow(Pony).to receive(:deliver) { |mail| mail }
end
|
#reset_api_keys ⇒ Object
87
88
89
90
91
|
# File 'lib/do_snapshot/rspec/environment.rb', line 87
def reset_api_keys
ENV['DIGITAL_OCEAN_API_KEY'] = nil
ENV['DIGITAL_OCEAN_CLIENT_ID'] = nil
ENV['DIGITAL_OCEAN_ACCESS_TOKEN'] = nil
end
|
#reset_singletons ⇒ Object
#set_api_keys ⇒ Object
93
94
95
96
97
|
# File 'lib/do_snapshot/rspec/environment.rb', line 93
def set_api_keys
ENV['DIGITAL_OCEAN_API_KEY'] = api_key
ENV['DIGITAL_OCEAN_CLIENT_ID'] = client_key
ENV['DIGITAL_OCEAN_ACCESS_TOKEN'] = access_token
end
|
#stub_all_api(droplets = nil, active = false) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/do_snapshot/rspec/environment.rb', line 44
def stub_all_api(droplets = nil, active = false)
drops = []
droplets ||= [droplet_id]
droplets.each do |droplet|
drops.push Hash[
stub_droplet: (active ? stub_droplet(droplet) : stub_droplet_inactive(droplet))
].merge(stub_droplet_api(droplet))
end
stubs = Hash[drops: drops]
@stubs = stubs.merge(default_stub_api)
end
|
#stub_cleanup ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/do_snapshot/rspec/environment.rb', line 73
def stub_cleanup
@stubs ||= {}
@stubs.each_pair do |_k, v|
remove_request_stub(v) if v.class == WebMock::RequestStub
next unless v.class == Array
v.each do |d|
d.each_pair do |_dk, dv|
remove_request_stub(dv) if v.class == WebMock::RequestStub
end
end
end
end
|
#stub_droplet_api(droplet) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/do_snapshot/rspec/environment.rb', line 56
def stub_droplet_api(droplet)
{
stub_droplet_stop: stub_droplet_stop(droplet),
stub_droplet_start: stub_droplet_start(droplet),
stub_droplet_snapshot: stub_droplet_snapshot(droplet, snapshot_name)
}
end
|