Skip to content

Commit

Permalink
test else and end of a conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Nov 13, 2024
1 parent 98dd060 commit 8c0d362
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ def test_method_with_block
end # line 17
end

end # line 20
def test_method_with_conditional
if false
a = 1
else # line 23
a = 2
end # line 25
a
end

end # line 29

# Comment - line 22
# Comment - line 31
41 changes: 40 additions & 1 deletion spec/datadog/di/integration/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,49 @@ def run_test
end
end

shared_examples 'installs but does not invoke probe' do
it 'installs but does not invoke probe' do
expect(component.transport).to receive(:send_request).once
probe_manager.add_probe(probe)
component.probe_notifier_worker.flush
expect(probe_manager.installed_probes.length).to eq 1
expect(component.probe_notifier_worker).not_to receive(:add_snapshot)
call_target
end
end

context 'target line is else of a conditional' do
let(:probe) do
Datadog::DI::Probe.new(id: "1234", type: :log,
file: 'instrumentation_integration_test_class.rb', line_no: 23,
capture_snapshot: false,)
end

let(:call_target) do
expect(InstrumentationIntegrationTestClass.new.test_method_with_conditional).to eq(2)
end

include_examples 'installs but does not invoke probe'
end

context 'target line is end of a conditional' do
let(:probe) do
Datadog::DI::Probe.new(id: "1234", type: :log,
file: 'instrumentation_integration_test_class.rb', line_no: 25,
capture_snapshot: false,)
end

let(:call_target) do
expect(InstrumentationIntegrationTestClass.new.test_method_with_conditional).to eq(2)
end

include_examples 'installs but does not invoke probe'
end

context 'target line contains a comment (no executable code)' do
let(:probe) do
Datadog::DI::Probe.new(id: "1234", type: :log,
file: 'instrumentation_integration_test_class.rb', line_no: 22,
file: 'instrumentation_integration_test_class.rb', line_no: 31,
capture_snapshot: false,)
end

Expand Down

0 comments on commit 8c0d362

Please sign in to comment.