/
spec_helper.rb
58 lines (47 loc) · 1.41 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
# frozen_string_literal: true
require "ruby_event_store"
require "ruby_event_store/outbox"
require "ruby_event_store/outbox/cli"
require "ruby_event_store/outbox/metrics/null"
require "ruby_event_store/outbox/metrics/influx"
require "ruby_event_store/outbox/metrics/test"
require_relative "../../../support/helpers/rspec_defaults"
require_relative "../../../support/helpers/schema_helper"
require_relative "../../../support/helpers/time_enrichment"
require_relative "../../../support/helpers/redis_client_unix_socket_patch"
require_relative "./support/db"
require "rails"
require "active_support/testing/time_helpers.rb"
ENV["DATABASE_URL"] ||= "sqlite3::memory:"
RSpec.configure do |config|
config.include ActiveSupport::Testing::TimeHelpers
config.after(:each) { travel_back }
config.before(:each, redis: true) { |example| redis.flushdb }
end
$verbose = ENV.has_key?("VERBOSE") ? true : false
ActiveRecord::Schema.verbose = $verbose
ENV["DATABASE_URL"] ||= "sqlite3::memory:"
module RedisIsolation
def self.redis_url
ENV["REDIS_URL"]
end
end
class TickingClock
def initialize(start: Time.now.utc, tick_by: 1)
@start = start.change(usec: 0)
@next = @start.dup
@tick_by = tick_by
end
def now
current = @next.dup
@next += tick_by
current
end
def test_travel(ticks)
@next += ticks
end
def tick(index)
start.dup + index * tick_by
end
attr_reader :start, :tick_by
end