spec_helper.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. require 'rspec/retry'
  2. require 'simplecov'
  3. GC.disable
  4. SimpleCov.start 'rails' do
  5. add_group 'Services', 'app/services'
  6. add_group 'Presenters', 'app/presenters'
  7. add_group 'Validators', 'app/validators'
  8. end
  9. gc_counter = -1
  10. RSpec.configure do |config|
  11. config.verbose_retry = true
  12. config.display_try_failure_messages = true
  13. config.expect_with :rspec do |expectations|
  14. expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  15. end
  16. config.mock_with :rspec do |mocks|
  17. mocks.verify_partial_doubles = true
  18. config.around(:example, :without_verify_partial_doubles) do |example|
  19. mocks.verify_partial_doubles = false
  20. example.call
  21. mocks.verify_partial_doubles = true
  22. end
  23. end
  24. config.around :each do |ex|
  25. ex.run_with_retry retry: 3
  26. end
  27. config.before :suite do
  28. Chewy.strategy(:bypass)
  29. end
  30. config.after :suite do
  31. gc_counter = 0
  32. FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
  33. end
  34. config.after :each do
  35. gc_counter += 1
  36. if gc_counter > 19
  37. GC.enable
  38. GC.start
  39. GC.disable
  40. gc_counter = 0
  41. end
  42. end
  43. end
  44. def body_as_json
  45. json_str_to_hash(response.body)
  46. end
  47. def json_str_to_hash(str)
  48. JSON.parse(str, symbolize_names: true)
  49. end