-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathspec_helper.rb
97 lines (75 loc) · 2.35 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
85
86
87
88
89
90
91
92
93
94
95
96
97
# frozen_string_literal: true
ENV['RAILS_ENV'] ||= 'test'
require 'coveralls'
require 'simplecov'
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter,
]
SimpleCov.start do
add_filter Bundler.bundle_path.to_s
add_filter File.dirname(__FILE__)
end
require 'switch_point'
require 'models'
RSpec.configure do |config|
config.filter_run :focus
config.run_all_when_everything_filtered = true
if config.files_to_run.one?
config.full_backtrace = true
config.default_formatter = 'doc'
end
config.order = :random
Kernel.srand config.seed
config.expect_with :rspec do |expectations|
expectations.syntax = :expect
end
config.mock_with :rspec do |mocks|
mocks.syntax = :expect
mocks.verify_partial_doubles = true
end
config.before(:suite) do
Book.with_writable do
Book.connection.execute('CREATE TABLE books (id integer primary key autoincrement)')
end
Book2.with_writable do
Book2.connection.execute('CREATE TABLE book2s (id integer primary key autoincrement)')
end
FileUtils.cp('main_writable.sqlite3', 'main_readonly.sqlite3')
Book3.with_writable do
Book3.connection.execute('CREATE TABLE book3s (id integer primary key autoincrement)')
end
FileUtils.cp('main2_writable.sqlite3', 'main2_readonly.sqlite3')
Note.connection.execute('CREATE TABLE notes (id integer primary key autoincrement)')
Nanika3.connection.execute('CREATE TABLE nanika3s (id integer primary key)')
end
config.after(:suite) do
if ActiveRecord::Base.configurations.respond_to?(:configs_for)
ActiveRecord::Base.configurations.configs_for.each do |c|
FileUtils.rm_f(c.config['database'])
end
else
ActiveRecord::Base.configurations.each_value do |c|
FileUtils.rm_f(c[:database])
end
end
end
config.after(:each) do
Book.with_writable do
Book.delete_all
end
FileUtils.cp('main_writable.sqlite3', 'main_readonly.sqlite3')
Nanika3.delete_all
end
end
RSpec::Matchers.define :connect_to do |expected|
database_name = lambda do |model|
model.connection.pool.spec.config[:database]
end
match do |actual|
database_name.call(actual) == expected
end
failure_message do |actual|
"expected #{actual.name} to connect to #{expected} but connected to #{database_name.call(actual)}"
end
end