Commit b3d88d8f authored by Alex Buijs's avatar Alex Buijs

Save some time initialising a context every spec

parent 547ca286
......@@ -304,7 +304,7 @@ RSpec.configure do |config|
RequestStore.clear!
end
config.around do |example|
config.around(:example, :context_aware) do |example|
# Wrap each example in it's own context to make sure the contexts don't
# leak
Gitlab::ApplicationContext.with_raw_context { example.run }
......
# frozen_string_literal: true
RSpec.shared_examples 'API::CI::Runner application context metadata' do |api_route|
it 'contains correct context metadata' do
it 'contains correct context metadata', :context_aware do
# Avoids popping the context from the thread so we can
# check its content after the request.
allow(Labkit::Context).to receive(:pop)
......
# frozen_string_literal: true
RSpec.shared_examples 'storing arguments in the application context' do
around do |example|
Gitlab::ApplicationContext.with_base_context { example.run }
end
it 'places the expected params in the application context' do
it 'places the expected params in the application context', :context_aware 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
Gitlab::ApplicationContext.with_base_context do |context|
expect(context.to_h)
.to include(log_hash(expected_params))
end
expect(Gitlab::ApplicationContext.current).to include(log_hash(expected_params))
end
def log_hash(hash)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment