Guest User

Untitled

a guest
Dec 13th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. # frozen_string_literal: true
  2.  
  3. require_relative '../system/my_app/container'
  4.  
  5. module MyApp
  6. module Tests
  7. class Container < Dry::System::Container
  8. use :env, inferrer: -> { 'test' }
  9.  
  10. configure do
  11. config.name = :my_app_tests
  12. end
  13.  
  14. import core: MyApp::Container
  15.  
  16. load_paths! 'spec'
  17. end
  18. end
  19. end
  20.  
  21. MyApp::Tests::Container.boot :rspec do |system|
  22. init do
  23. require 'rspec/collection_matchers'
  24.  
  25. RSpec.configure do |config|
  26. config.expect_with :rspec do |expectations|
  27. expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  28. end
  29.  
  30. config.mock_with :rspec do |mocks|
  31. mocks.verify_partial_doubles = true
  32. end
  33.  
  34. config.default_formatter = 'doc' if config.files_to_run.one?
  35. config.disable_monkey_patching!
  36. config.shared_context_metadata_behavior = :apply_to_host_groups
  37. config.warnings = false
  38.  
  39. config.define_derived_metadata do |meta|
  40. meta[:aggregate_failures] = true
  41. end
  42.  
  43. config.order = :random
  44. Kernel.srand config.seed
  45. end
  46. end
  47. end
  48.  
  49. MyApp::Tests::Container.boot :rack_test do
  50. init do
  51. use :rspec
  52.  
  53. require 'rack/test'
  54. require 'my_app/web'
  55.  
  56. RSpec.configure do |config|
  57. config.include Rack::Test::Methods, type: :request
  58.  
  59. config.include((Module.new do
  60. def app
  61. MyApp::Web.freeze.app
  62. end
  63. end), type: :request)
  64. end
  65. end
  66. end
  67.  
  68. MyApp::Tests::Container.boot :database_cleaner do |system|
  69. init do
  70. use :rspec
  71.  
  72. require 'database_cleaner'
  73.  
  74. DatabaseCleaner.allow_remote_database_url = true
  75.  
  76. database_cleaner = DatabaseCleaner[
  77. :sequel, connection: system[:'core.persistence.database']
  78. ]
  79.  
  80. RSpec.configure do |config|
  81. config.before :suite do
  82. database_cleaner.strategy = :deletion
  83. database_cleaner.start
  84. database_cleaner.strategy.clean
  85. end
  86.  
  87. config.around do |example|
  88. database_cleaner.cleaning do
  89. example.run
  90. end
  91. end
  92. end
  93. end
  94. end
  95.  
  96. MyApp::Tests::Container.boot :factory do |system|
  97. init do
  98. use :rspec
  99.  
  100. require 'rom-factory'
  101.  
  102. factory = ROM::Factory.configure do |config|
  103. config.rom = system[:'core.persistence.rom']
  104. end
  105.  
  106. factory.define :provider do |f|
  107. f.title { fake(:company, :name) }
  108.  
  109. f.created_at { Time.now }
  110. f.updated_at { Time.now }
  111. end
  112.  
  113. register :factory, factory
  114.  
  115. RSpec.configure do |config|
  116. config.include(Module.new do
  117. def factory
  118. MyApp::Tests::Container[:factory]
  119. end
  120. end)
  121. end
  122. end
  123. end
  124.  
  125. MyApp::Tests::Container.finalize!
Add Comment
Please, Sign In to add comment