summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/requests/api/logging_application_context_shared_examples.rb
blob: 038ede884c88c403b395ec6c0c997fee9e9dbc16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

RSpec.shared_examples 'storing arguments in the application context' do
  around do |example|
    Labkit::Context.with_context { example.run }
  end

  it 'places the expected params in the application context' do
    # Stub the clearing of the context so we can validate it later
    # The `around` block above makes sure we do clean it up later
    allow(Labkit::Context).to receive(:pop)

    subject

    Labkit::Context.with_context do |context|
      expect(context.to_h)
        .to include(log_hash(expected_params))
    end
  end

  def log_hash(hash)
    hash.transform_keys! { |key| "meta.#{key}" }
  end
end