spec_helper.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. GC.disable
  2. if ENV['DISABLE_SIMPLECOV'] != 'true'
  3. require 'simplecov'
  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. end
  10. gc_counter = -1
  11. RSpec.configure do |config|
  12. config.expect_with :rspec do |expectations|
  13. expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  14. end
  15. config.mock_with :rspec do |mocks|
  16. mocks.verify_partial_doubles = true
  17. config.around(:example, :without_verify_partial_doubles) do |example|
  18. mocks.verify_partial_doubles = false
  19. example.call
  20. mocks.verify_partial_doubles = true
  21. end
  22. end
  23. config.before :suite do
  24. Rails.application.load_seed
  25. Chewy.strategy(:bypass)
  26. end
  27. config.after :suite do
  28. gc_counter = 0
  29. FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
  30. end
  31. config.after :each do
  32. gc_counter += 1
  33. if gc_counter > 19
  34. GC.enable
  35. GC.start
  36. GC.disable
  37. gc_counter = 0
  38. end
  39. end
  40. end
  41. def body_as_json
  42. json_str_to_hash(response.body)
  43. end
  44. def json_str_to_hash(str)
  45. JSON.parse(str, symbolize_names: true)
  46. end