spec_helper.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.example_status_persistence_file_path = "tmp/rspec/examples.txt"
  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.before :suite do
  25. Rails.application.load_seed
  26. Chewy.strategy(:bypass)
  27. # NOTE: we switched registrations mode to closed by default, but the specs
  28. # very heavily rely on having it enabled by default, as it relies on users
  29. # being approved by default except in select cases where explicitly testing
  30. # other registration modes
  31. Setting.registrations_mode = 'open'
  32. end
  33. config.after :suite do
  34. gc_counter = 0
  35. FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
  36. end
  37. config.after :each do
  38. gc_counter += 1
  39. if gc_counter > 19
  40. GC.enable
  41. GC.start
  42. GC.disable
  43. gc_counter = 0
  44. end
  45. end
  46. end
  47. def body_as_json
  48. json_str_to_hash(response.body)
  49. end
  50. def json_str_to_hash(str)
  51. JSON.parse(str, symbolize_names: true)
  52. end
  53. def expect_push_bulk_to_match(klass, matcher)
  54. expect(Sidekiq::Client).to receive(:push_bulk).with(hash_including({
  55. "class" => klass,
  56. "args" => matcher
  57. }))
  58. end