-
Notifications
You must be signed in to change notification settings - Fork 39
/
spec_helper.rb
84 lines (69 loc) · 2.18 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# frozen_string_literal: true
require 'bundler/setup'
require 'timecop'
require 'webmock/rspec'
require 'semantic_logger'
require 'rspec/json_expectations'
# Configure Rails dummary app if Rails is in context
if Gem.loaded_specs.key?('rails')
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('dummy/config/environment.rb', __dir__)
require 'rspec/rails'
end
# Require main library (after Rails has done so)
require 'cloudtasker'
require 'cloudtasker/testing'
require 'cloudtasker/unique_job'
require 'cloudtasker/cron'
require 'cloudtasker/batch'
require 'cloudtasker/storable'
# Require supporting files
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
Dir['./spec/shared/**/*.rb'].sort.each { |f| require f }
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = '.rspec_status'
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :rspec do |c|
c.syntax = :expect
end
# Ensure cache is clean before each test
config.before do
Cloudtasker.config.client_middleware.clear
Cloudtasker.config.server_middleware.clear
# Flush redis keys
Cloudtasker::RedisClient.new.clear
end
# NOTE: Retriable is configured in a conditional before
# block to avoid requiring the gem in the spec helper. This
# ensures that classes have defined the proper requires.
config.before(:all) do
if defined?(Retriable)
# Do not wait between retries
Retriable.configure do |c|
c.multiplier = 1.0
c.rand_factor = 0.0
c.base_interval = 0
end
end
end
end
# Configure for tests
Cloudtasker.configure do |config|
# GCP
config.gcp_project_id = 'my-project-id'
config.gcp_location_id = 'us-east2'
config.gcp_queue_prefix = 'my-queue'
# Processor
config.secret = 'my$s3cr3t'
config.processor_host = 'http://localhost'
config.processor_path = '/mynamespace/run'
# Redis
config.redis = { url: "redis://#{ENV['REDIS_HOST'] || 'localhost'}:6379/15" }
# Logger
config.logger = Logger.new(nil)
# Hooks
config.on_error = ->(w, e) {}
config.on_dead = ->(w, e) {}
end