Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ end

# sneakers main only supports >=2.5.0
if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('2.5.0') && !defined?(JRUBY_VERSION)
gem 'sneakers', github: 'jondot/sneakers', ref: 'd761dfe1493', require: nil
# The sneakers gem was renamed to kicks, which SneakersSpy also instruments.
# Set SNEAKERS_GEM=kicks to run the suite against it instead.
if ENV['SNEAKERS_GEM'] == 'kicks'
gem 'kicks', '>= 2.12.0', require: nil
else
gem 'sneakers', github: 'jondot/sneakers', ref: 'd761dfe1493', require: nil
end
end

if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.5.0')
Expand Down
5 changes: 4 additions & 1 deletion lib/elastic_apm/spies/sneakers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ module Spies
class SneakersSpy
include Logging

# The sneakers gem was renamed to kicks, which still ships
# `lib/sneakers.rb` but registers under a different gem name.
def self.supported_version?
Gem.loaded_specs['sneakers'].version >= Gem::Version.create('2.12.0')
spec = Gem.loaded_specs['sneakers'] || Gem.loaded_specs['kicks']
spec && spec.version >= Gem::Version.create('2.12.0')
end

def install
Expand Down
30 changes: 27 additions & 3 deletions spec/elastic_apm/spies/sneakers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@
# frozen_string_literal: true

require 'spec_helper'
unless Gem::Specification.find_all_by_name('sneakers', '>=2.12.0').empty? || defined?(JRUBY_VERSION)
require 'elastic_apm/spies/sneakers'

# The sneakers gem was renamed to kicks. Both ship `lib/sneakers.rb` and define
# the `Sneakers` constant, but register under different gem names, so either one
# satisfies the spy.
queue_gem_bundled =
!defined?(JRUBY_VERSION) &&
!(Gem::Specification.find_all_by_name('sneakers', '>=2.12.0') +
Gem::Specification.find_all_by_name('kicks', '>=2.12.0')).empty?

if queue_gem_bundled
require 'sneakers'
require 'elastic_apm/spies/sneakers'

module ElasticAPM
RSpec.describe 'Spy: Sneakers', :intercept do
Expand Down Expand Up @@ -70,6 +79,10 @@ def work(_message)
Sneakers.logger = Logger.new(nil) # silence
end

it 'supports the version of the gem in the bundle' do
expect(Spies::SneakersSpy.supported_version?).to be_truthy
end

it 'instruments job transaction' do
with_agent do
worker = TestWorker.new
Expand Down Expand Up @@ -108,4 +121,15 @@ def work(_message)
end
end
end
end
elsif Gem.loaded_specs['sneakers'].nil? && Gem.loaded_specs['kicks'].nil?
# Neither gem is in the bundle (eg. JRuby, or Ruby below 2.5), so the spy has
# no gem spec to read a version from. It has to report the version as
# unsupported rather than raise.
module ElasticAPM
RSpec.describe 'Spy: Sneakers' do
it 'is unsupported when neither sneakers nor kicks is bundled' do
expect(Spies::SneakersSpy.supported_version?).to be_falsey
end
end
end
end
Loading