Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # frozen_string_literal: true
- require_relative '../system/my_app/container'
- module MyApp
- module Tests
- class Container < Dry::System::Container
- use :env, inferrer: -> { 'test' }
- configure do
- config.name = :my_app_tests
- end
- import core: MyApp::Container
- load_paths! 'spec'
- end
- end
- end
- MyApp::Tests::Container.boot :rspec do |system|
- init do
- require 'rspec/collection_matchers'
- 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.default_formatter = 'doc' if config.files_to_run.one?
- config.disable_monkey_patching!
- config.shared_context_metadata_behavior = :apply_to_host_groups
- config.warnings = false
- config.define_derived_metadata do |meta|
- meta[:aggregate_failures] = true
- end
- config.order = :random
- Kernel.srand config.seed
- end
- end
- end
- MyApp::Tests::Container.boot :rack_test do
- init do
- use :rspec
- require 'rack/test'
- require 'my_app/web'
- RSpec.configure do |config|
- config.include Rack::Test::Methods, type: :request
- config.include((Module.new do
- def app
- MyApp::Web.freeze.app
- end
- end), type: :request)
- end
- end
- end
- MyApp::Tests::Container.boot :database_cleaner do |system|
- init do
- use :rspec
- require 'database_cleaner'
- DatabaseCleaner.allow_remote_database_url = true
- database_cleaner = DatabaseCleaner[
- :sequel, connection: system[:'core.persistence.database']
- ]
- RSpec.configure do |config|
- config.before :suite do
- database_cleaner.strategy = :deletion
- database_cleaner.start
- database_cleaner.strategy.clean
- end
- config.around do |example|
- database_cleaner.cleaning do
- example.run
- end
- end
- end
- end
- end
- MyApp::Tests::Container.boot :factory do |system|
- init do
- use :rspec
- require 'rom-factory'
- factory = ROM::Factory.configure do |config|
- config.rom = system[:'core.persistence.rom']
- end
- factory.define :provider do |f|
- f.title { fake(:company, :name) }
- f.created_at { Time.now }
- f.updated_at { Time.now }
- end
- register :factory, factory
- RSpec.configure do |config|
- config.include(Module.new do
- def factory
- MyApp::Tests::Container[:factory]
- end
- end)
- end
- end
- end
- MyApp::Tests::Container.finalize!
Add Comment
Please, Sign In to add comment