spec_helper.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # frozen_string_literal: true
  2. RSpec.configure do |config|
  3. config.example_status_persistence_file_path = 'tmp/rspec/examples.txt'
  4. config.expect_with :rspec do |expectations|
  5. expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  6. end
  7. config.disable_monkey_patching!
  8. config.mock_with :rspec do |mocks|
  9. mocks.verify_partial_doubles = true
  10. end
  11. config.before :suite do
  12. Rails.application.load_seed
  13. Chewy.strategy(:bypass)
  14. # NOTE: we switched registrations mode to closed by default, but the specs
  15. # very heavily rely on having it enabled by default, as it relies on users
  16. # being approved by default except in select cases where explicitly testing
  17. # other registration modes
  18. Setting.registrations_mode = 'open'
  19. end
  20. config.after :suite do
  21. FileUtils.rm_rf(Rails.root.glob('spec/test_files'))
  22. end
  23. # Use the GitHub Annotations formatter for CI
  24. if ENV['GITHUB_ACTIONS'] == 'true' && ENV['GITHUB_RSPEC'] == 'true'
  25. require 'rspec/github'
  26. config.add_formatter RSpec::Github::Formatter
  27. end
  28. end
  29. def serialized_record_json(record, serializer, adapter: nil, options: {})
  30. options[:serializer] = serializer
  31. options[:adapter] = adapter if adapter.present?
  32. JSON.parse(
  33. ActiveModelSerializers::SerializableResource.new(
  34. record,
  35. options
  36. ).to_json
  37. )
  38. end
  39. def expect_push_bulk_to_match(klass, matcher)
  40. allow(Sidekiq::Client).to receive(:push_bulk)
  41. yield
  42. expect(Sidekiq::Client).to have_received(:push_bulk).with(hash_including({
  43. 'class' => klass,
  44. 'args' => matcher,
  45. }))
  46. end