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| ...@@ -304,7 +304,7 @@ RSpec.configure do |config|
RequestStore.clear! RequestStore.clear!
end 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 # Wrap each example in it's own context to make sure the contexts don't
# leak # leak
Gitlab::ApplicationContext.with_raw_context { example.run } Gitlab::ApplicationContext.with_raw_context { example.run }
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'API::CI::Runner application context metadata' do |api_route| 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 # Avoids popping the context from the thread so we can
# check its content after the request. # check its content after the request.
allow(Labkit::Context).to receive(:pop) allow(Labkit::Context).to receive(:pop)
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'storing arguments in the application context' do RSpec.shared_examples 'storing arguments in the application context' do
around do |example| it 'places the expected params in the application context', :context_aware do
Gitlab::ApplicationContext.with_base_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 # 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) allow(Labkit::Context).to receive(:pop)
subject subject
Gitlab::ApplicationContext.with_base_context do |context| expect(Gitlab::ApplicationContext.current).to include(log_hash(expected_params))
expect(context.to_h)
.to include(log_hash(expected_params))
end
end end
def log_hash(hash) 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