diff --git a/sentry-ruby/lib/sentry/configuration.rb b/sentry-ruby/lib/sentry/configuration.rb index ec582bdd6..424ff479e 100644 --- a/sentry-ruby/lib/sentry/configuration.rb +++ b/sentry-ruby/lib/sentry/configuration.rb @@ -405,7 +405,7 @@ def valid? def sample_allowed? return true if sample_rate == 1.0 - if Random::DEFAULT.rand >= sample_rate + if Random.rand >= sample_rate @errors << "Excluded by random sample" false else diff --git a/sentry-ruby/lib/sentry/core_ext/object/deep_dup.rb b/sentry-ruby/lib/sentry/core_ext/object/deep_dup.rb index cb4ca46ba..1c4adb53f 100644 --- a/sentry-ruby/lib/sentry/core_ext/object/deep_dup.rb +++ b/sentry-ruby/lib/sentry/core_ext/object/deep_dup.rb @@ -20,6 +20,7 @@ def deep_dup end class Array + undef_method :deep_dup if method_defined?(:deep_dup) # Returns a deep copy of array. # # array = [1, [2, 3]] diff --git a/sentry-ruby/lib/sentry/core_ext/object/duplicable.rb b/sentry-ruby/lib/sentry/core_ext/object/duplicable.rb index b70adb5bc..722adf04a 100644 --- a/sentry-ruby/lib/sentry/core_ext/object/duplicable.rb +++ b/sentry-ruby/lib/sentry/core_ext/object/duplicable.rb @@ -115,6 +115,7 @@ def duplicable? end class Method + undef_method :duplicable? if method_defined?(:duplicable?) # Methods are not duplicable: # # method(:puts).duplicable? # => false diff --git a/sentry-ruby/lib/sentry/transport/configuration.rb b/sentry-ruby/lib/sentry/transport/configuration.rb index f630068f5..2ab6d7aad 100644 --- a/sentry-ruby/lib/sentry/transport/configuration.rb +++ b/sentry-ruby/lib/sentry/transport/configuration.rb @@ -2,7 +2,8 @@ module Sentry class Transport class Configuration attr_accessor :timeout, :open_timeout, :proxy, :ssl, :ssl_ca_file, :ssl_verification, :http_adapter, :faraday_builder, - :transport_class, :encoding + :encoding + attr_reader :transport_class def initialize @ssl_verification = true diff --git a/sentry-ruby/spec/sentry/configuration_spec.rb b/sentry-ruby/spec/sentry/configuration_spec.rb index 858ae0152..53ec68455 100644 --- a/sentry-ruby/spec/sentry/configuration_spec.rb +++ b/sentry-ruby/spec/sentry/configuration_spec.rb @@ -195,13 +195,13 @@ end it 'captured_allowed false when sampled' do - allow(Random::DEFAULT).to receive(:rand).and_return(0.76) + allow(Random).to receive(:rand).and_return(0.76) expect(subject.sending_allowed?).to eq(false) expect(subject.errors).to eq(["Excluded by random sample"]) end it 'captured_allowed true when not sampled' do - allow(Random::DEFAULT).to receive(:rand).and_return(0.74) + allow(Random).to receive(:rand).and_return(0.74) expect(subject.sending_allowed?).to eq(true) end end diff --git a/sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb b/sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb index 21c48dd65..801e1ca2f 100644 --- a/sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb +++ b/sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb @@ -66,7 +66,7 @@ it 'does not call #to_s for unnecessary env variables' do expect(mock).not_to receive(:to_s) - interface = described_class.build(env: env) + described_class.build(env: env) end end end @@ -133,7 +133,7 @@ def to_s new_env = env.merge("HTTP_FOO" => "BAR", "rails_object" => obj) - expect { interface = described_class.build(env: new_env) }.to_not raise_error + expect { described_class.build(env: new_env) }.to_not raise_error end end diff --git a/sentry-ruby/spec/sentry/net/http_spec.rb b/sentry-ruby/spec/sentry/net/http_spec.rb index 5b2007f86..89756ffcd 100644 --- a/sentry-ruby/spec/sentry/net/http_spec.rb +++ b/sentry-ruby/spec/sentry/net/http_spec.rb @@ -10,15 +10,7 @@ ::Logger.new(string_io) end - original_buffered_io = Net::BufferedIO - - before(:all) do - Net.send(:const_set, :BufferedIO, Net::WebMockNetBufferedIO) - end - - after(:all) do - Net.send(:const_set, :BufferedIO, original_buffered_io) - end + before { stub_const('Net::BufferedIO', Net::WebMockNetBufferedIO) } class FakeSocket < StringIO def setsockopt(*args); end diff --git a/sentry-ruby/spec/sentry/transport_spec.rb b/sentry-ruby/spec/sentry/transport_spec.rb index dc89d4588..a318487f3 100644 --- a/sentry-ruby/spec/sentry/transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport_spec.rb @@ -87,7 +87,7 @@ before do configuration.logger = Logger.new(string_io) configuration.sample_rate = 0.5 - allow(Random::DEFAULT).to receive(:rand).and_return(0.6) + allow(Random).to receive(:rand).and_return(0.6) end it "logs correct message" do