1
0

spec_helper.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # frozen_string_literal: true
  2. unless ENV['DISABLE_SIMPLECOV'] == 'true'
  3. require 'simplecov' # Configuration details loaded from .simplecov
  4. end
  5. RSpec.configure do |config|
  6. config.example_status_persistence_file_path = 'tmp/rspec/examples.txt'
  7. config.expect_with :rspec do |expectations|
  8. expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  9. end
  10. config.mock_with :rspec do |mocks|
  11. mocks.verify_partial_doubles = true
  12. config.around(:example, :without_verify_partial_doubles) do |example|
  13. mocks.verify_partial_doubles = false
  14. example.call
  15. mocks.verify_partial_doubles = true
  16. end
  17. end
  18. config.before :suite do
  19. Rails.application.load_seed
  20. Chewy.strategy(:bypass)
  21. end
  22. config.after :suite do
  23. FileUtils.rm_rf(Dir[Rails.root.join('spec', 'test_files')])
  24. end
  25. # Use the GitHub Annotations formatter for CI
  26. if ENV['GITHUB_ACTIONS'] == 'true' && ENV['GITHUB_RSPEC'] == 'true'
  27. require 'rspec/github'
  28. config.add_formatter RSpec::Github::Formatter
  29. end
  30. end
  31. def body_as_json
  32. json_str_to_hash(response.body)
  33. end
  34. def json_str_to_hash(str)
  35. JSON.parse(str, symbolize_names: true)
  36. end
  37. def serialized_record_json(record, serializer, adapter: nil)
  38. options = { serializer: serializer }
  39. options[:adapter] = adapter if adapter.present?
  40. JSON.parse(
  41. ActiveModelSerializers::SerializableResource.new(
  42. record,
  43. options
  44. ).to_json
  45. )
  46. end
  47. def expect_push_bulk_to_match(klass, matcher)
  48. allow(Sidekiq::Client).to receive(:push_bulk)
  49. yield
  50. expect(Sidekiq::Client).to have_received(:push_bulk).with(hash_including({
  51. 'class' => klass,
  52. 'args' => matcher,
  53. }))
  54. end