-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathspec_helper.rb
More file actions
49 lines (39 loc) · 965 Bytes
/
spec_helper.rb
File metadata and controls
49 lines (39 loc) · 965 Bytes
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
require "rspec"
require "active_record"
require "database_cleaner"
require "factory_bot"
require "timecop"
PROJECT_ROOT = File.expand_path("../..", __FILE__)
$LOAD_PATH << PROJECT_ROOT
ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
database: File.join(PROJECT_ROOT, "test.db")
)
class CreateSchema < ActiveRecord::Migration[4.2]
def self.up
create_table :posts, force: true do |table|
table.string :title
table.timestamps
end
end
end
FactoryBot.define do
sequence(:title) { |n| "title#{n}text" }
factory :post do
title
end
end
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
config.before(:suite) do
CreateSchema.suppress_messages { CreateSchema.migrate(:up) }
DatabaseCleaner.clean_with :deletion
DatabaseCleaner.strategy = :transaction
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end