Skip to content

Fix RSpec expectation ordering error in metrics_spec callback test - #1651

Draft
xrmx with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-failing-ci-job
Draft

Fix RSpec expectation ordering error in metrics_spec callback test#1651
xrmx with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-failing-ci-job

Conversation

Copilot AI commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

On certain CI matrix entries, collect_and_send invokes the callback during the first (probe) call, causing RSpec to reject a subsequent receive(:call) expectation on an already-invoked proc.

Change

  • spec/elastic_apm/metrics_spec.rb: Replace the post-invocation RSpec message expectation with a plain call recorder (array spy). The callback appends each metricset to calls; after the second collect_and_send, the test asserts calls includes a Metricset. The next unless skip path for unsupported environments is preserved.
# Before — expectation set after callback may already have fired
subject.collect_and_send
next unless subject.sets.values.select { |s| s.metrics.any? }.any?
expect(callback).to receive(:call).with(Metricset).at_least(1)
subject.collect_and_send

# After — spy array avoids RSpec ordering constraint entirely
calls = []
callback = ->(metricset) { calls << metricset }
metrics = described_class.new(config, &callback)
begin
  metrics.start
  metrics.collect_and_send
  next unless metrics.sets.values.any? { |s| s.metrics.any? }
  calls.clear
  metrics.collect_and_send
  expect(calls).to include(Metricset)
ensure
  metrics.stop
end

Copilot AI changed the title [WIP] Fix failing CI job in metrics_spec.rb Fix RSpec expectation ordering error in metrics_spec callback test Jul 24, 2026
Copilot finished work on behalf of xrmx July 24, 2026 12:58
Copilot AI requested a review from xrmx July 24, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants