Skip to content

Commit 4fa9ef9

Browse files
committed
Adjust ActionDispatch contib tests
1 parent 61119fb commit 4fa9ef9

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

spec/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation_spec.rb

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@
44
require 'datadog/tracing/contrib/action_pack/action_dispatch/instrumentation'
55

66
RSpec.describe Datadog::Tracing::Contrib::ActionPack::ActionDispatch::Instrumentation do
7-
describe '::set_http_route_tags' do
8-
let(:tracing_enabled) { true }
9-
10-
before do
11-
expect(Datadog::Tracing).to receive(:enabled?).and_return(tracing_enabled)
12-
end
13-
7+
describe '.set_http_route_tags' do
148
context 'when tracing is disabled' do
15-
let(:tracing_enabled) { false }
9+
before { expect(Datadog::Tracing).to receive(:enabled?).and_return(false) }
1610

1711
it 'sets no tags' do
1812
Datadog::Tracing.trace('rack.request') do |_span, trace|
@@ -24,37 +18,41 @@
2418
end
2519
end
2620

27-
it 'sets http.route and http.route.path tags on existing trace' do
28-
Datadog::Tracing.trace('rack.request') do |_span, trace|
29-
described_class.set_http_route_tags('/users/:id(.:format)', '/auth')
21+
context 'when tracing is enabled' do
22+
before { expect(Datadog::Tracing).to receive(:enabled?).and_return(true) }
3023

31-
expect(trace.send(:meta).fetch('http.route')).to eq('/users/:id')
32-
expect(trace.send(:meta).fetch('http.route.path')).to eq('/auth')
24+
it 'sets http.route and http.route.path tags on existing trace' do
25+
Datadog::Tracing.trace('rack.request') do |_span, trace|
26+
described_class.set_http_route_tags('/users/:id', '/auth')
27+
28+
expect(trace.send(:meta).fetch('http.route')).to eq('/users/:id')
29+
expect(trace.send(:meta).fetch('http.route.path')).to eq('/auth')
30+
end
3331
end
34-
end
3532

36-
it 'sets no http.route.path when script name is nil' do
37-
Datadog::Tracing.trace('rack.request') do |_span, trace|
38-
described_class.set_http_route_tags('/users/:id(.:format)', nil)
33+
it 'sets no http.route.path when script name is nil' do
34+
Datadog::Tracing.trace('rack.request') do |_span, trace|
35+
described_class.set_http_route_tags('/users/:id', nil)
3936

40-
expect(trace.send(:meta).fetch('http.route')).to eq('/users/:id')
41-
expect(trace.send(:meta)).not_to have_key('http.route.path')
37+
expect(trace.send(:meta).fetch('http.route')).to eq('/users/:id')
38+
expect(trace.send(:meta)).not_to have_key('http.route.path')
39+
end
4240
end
43-
end
4441

45-
it 'sets no tags when route spec is nil' do
46-
Datadog::Tracing.trace('rack.request') do |_span, trace|
47-
described_class.set_http_route_tags(nil, '/auth')
42+
it 'sets no tags when route spec is nil' do
43+
Datadog::Tracing.trace('rack.request') do |_span, trace|
44+
described_class.set_http_route_tags(nil, '/auth')
4845

49-
expect(trace.send(:meta)).not_to have_key('http.route')
50-
expect(trace.send(:meta)).not_to have_key('http.route.path')
46+
expect(trace.send(:meta)).not_to have_key('http.route')
47+
expect(trace.send(:meta)).not_to have_key('http.route.path')
48+
end
5149
end
52-
end
5350

54-
it 'does not create new traces when no active trace is present' do
55-
described_class.set_http_route_tags('/users/:id', '/auth')
51+
it 'does not create new traces when no active trace is present' do
52+
described_class.set_http_route_tags('/users/:id', '/auth')
5653

57-
expect(traces).to be_empty
54+
expect(traces).to be_empty
55+
end
5856
end
5957
end
6058
end

0 commit comments

Comments
 (0)