/
test_help.rb
43 lines (36 loc) 路 1.07 KB
/
test_help.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
module Flipper
module TestHelp
extend self
def flipper_configure
# Use a shared Memory adapter for all tests. This is instantiated outside of the
# `configure` block so the same instance is returned in new threads.
adapter = Flipper::Adapters::Memory.new
Flipper.configure do |config|
config.adapter { adapter }
config.default { Flipper.new(config.adapter) }
end
end
def flipper_reset
# Remove all features
Flipper.features.each(&:remove) rescue nil
# Reset previous DSL instance
Flipper.instance = nil
end
end
end
if defined?(RSpec) && RSpec.respond_to?(:configure)
RSpec.configure do |config|
config.include Flipper::TestHelp
config.before(:suite) { Flipper::TestHelp.flipper_configure }
config.before(:each) { flipper_reset }
end
end
if defined?(ActiveSupport)
ActiveSupport.on_load(:active_support_test_case) do
Flipper::TestHelp.flipper_configure
ActiveSupport::TestCase.class_eval do
include Flipper::TestHelp
setup :flipper_reset
end
end
end