-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathtest_helper.rb
More file actions
80 lines (66 loc) · 1.77 KB
/
test_helper.rb
File metadata and controls
80 lines (66 loc) · 1.77 KB
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
require "bundler/setup"
require "combustion"
Bundler.require(:default)
require "minitest/autorun"
ENV["ADAPTER"] ||= "sqlite3"
puts "Using #{ENV["ADAPTER"]}"
logger = ActiveSupport::Logger.new(ENV["VERBOSE"] ? STDOUT : nil)
frameworks = [:action_controller, :active_job]
if ENV["ADAPTER"] == "mongoid"
require_relative "support/mongoid"
Dir.glob("support/mongoid_models/**/*.rb", base: __dir__) do |file|
require_relative file
end
Mongoid.logger = logger
Mongo::Logger.logger = logger
[Ahoy::Visit, Ahoy::Event].each do |model|
model.collection.drop
model.create_indexes
end
else
frameworks << :active_record
end
Combustion.path = "test/internal"
Combustion.initialize!(*frameworks) do
config.load_defaults Rails::VERSION::STRING.to_f
if ENV["ADAPTER"] != "mongoid"
config.active_record.logger = logger
end
config.action_controller.logger = logger
config.active_job.logger = logger
end
Ahoy.logger = logger
class Minitest::Test
def setup
Ahoy::Visit.delete_all
Ahoy::Event.delete_all
User.delete_all
end
def with_options(options)
previous_options = {}
options.each_key do |k|
previous_options[k] = Ahoy.send(k)
end
begin
options.each do |k, v|
Ahoy.send("#{k}=", v)
end
yield
ensure
previous_options.each do |k, v|
Ahoy.send("#{k}=", v)
end
end
end
def stub_method(cls, method, code)
original_code = cls.method(method)
begin
cls.singleton_class.undef_method(method)
cls.define_singleton_method(method, code.respond_to?(:call) ? code : ->(*) { code })
yield
ensure
cls.singleton_class.undef_method(method) if cls.singleton_class.method_defined?(method)
cls.define_singleton_method(method, original_code)
end
end
end