Initial commit
This commit is contained in:
15
spec/support/db.rb
Normal file
15
spec/support/db.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# require_with_metadata: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "db/helpers"
|
||||
require_relative "db/database_cleaner"
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.before :suite do
|
||||
Hanami.app.start :persistence
|
||||
end
|
||||
|
||||
config.include Test::DB::Helpers, :db
|
||||
|
||||
# config.include(Test::DB::FactoryHelper.new, factory: nil)
|
||||
end
|
18
spec/support/db/database_cleaner.rb
Normal file
18
spec/support/db/database_cleaner.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
require "sequel"
|
||||
require "database_cleaner/sequel"
|
||||
require_relative "helpers"
|
||||
|
||||
DatabaseCleaner[:sequel].strategy = :transaction
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.prepend_before :each, type: :db do |example|
|
||||
strategy = example.metadata[:js] ? :truncation : :transaction
|
||||
DatabaseCleaner[:sequel].strategy = strategy
|
||||
|
||||
DatabaseCleaner[:sequel].start
|
||||
end
|
||||
|
||||
config.append_after :each, type: :db do
|
||||
DatabaseCleaner[:sequel].clean
|
||||
end
|
||||
end
|
19
spec/support/db/helpers.rb
Normal file
19
spec/support/db/helpers.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Test
|
||||
module DB
|
||||
module Helpers
|
||||
module_function
|
||||
|
||||
def relations
|
||||
rom.relations
|
||||
end
|
||||
|
||||
def rom
|
||||
Hanami.app["persistence.rom"]
|
||||
end
|
||||
|
||||
def db
|
||||
Hanami.app["persistence.db"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
12
spec/support/requests.rb
Normal file
12
spec/support/requests.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rack/test"
|
||||
|
||||
RSpec.shared_context "Hanami app" do
|
||||
let(:app) { Hanami.app }
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include Rack::Test::Methods, type: :request
|
||||
config.include_context "Hanami app", type: :request
|
||||
end
|
27
spec/support/rspec.rb
Normal file
27
spec/support/rspec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.expect_with :rspec do |expectations|
|
||||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
||||
end
|
||||
|
||||
config.mock_with :rspec do |mocks|
|
||||
mocks.verify_partial_doubles = true
|
||||
end
|
||||
|
||||
config.shared_context_metadata_behavior = :apply_to_host_groups
|
||||
|
||||
config.filter_run_when_matching :focus
|
||||
|
||||
config.disable_monkey_patching!
|
||||
config.warnings = true
|
||||
|
||||
if config.files_to_run.one?
|
||||
config.default_formatter = "doc"
|
||||
end
|
||||
|
||||
config.profile_examples = 10
|
||||
|
||||
config.order = :random
|
||||
Kernel.srand config.seed
|
||||
end
|
Reference in New Issue
Block a user