From a96139c11922074d9a80dfae9842e55789240461 Mon Sep 17 00:00:00 2001
From: Arnold van der Meulen <arnold@roqua.nl>
Date: Mon, 6 May 2019 08:19:05 +0000
Subject: [PATCH] Ruby 2.5 and appsignal update

---
 .gitlab-ci.yml                                | 22 ++++++++++++
 CHANGELOG.md                                  |  5 +++
 Gemfile                                       |  2 +-
 Gemfile.lock                                  | 10 +++---
 lib/roqua-support/version.rb                  |  2 +-
 lib/roqua/core_ext/fixnum/clamp.rb            |  8 -----
 lib/roqua/logging/roqua_logging_railtie.rb    |  1 -
 lib/roqua/probes/base_probe.rb                |  3 +-
 lib/roqua/support.rb                          |  2 +-
 lib/roqua/support/errors.rb                   |  1 -
 roqua-support.gemspec                         |  2 +-
 .../enumerable/sort_by_alphanum_spec.rb       | 13 +++----
 .../core_ext/fabrication/singleton_spec.rb    |  7 ++--
 spec/roqua/core_ext/fixnum/clamp_spec.rb      | 23 ------------
 spec/roqua/probes/delayed_job_probe_spec.rb   |  2 +-
 spec/roqua/support/helpers_spec.rb            |  2 +-
 spec/roqua/support/logwrapper_spec.rb         | 20 +++++------
 spec/roqua/support/request_logger_spec.rb     | 35 ++++++++++---------
 spec/roqua/support_spec.rb                    |  6 ++--
 19 files changed, 80 insertions(+), 86 deletions(-)
 delete mode 100644 lib/roqua/core_ext/fixnum/clamp.rb
 delete mode 100644 spec/roqua/core_ext/fixnum/clamp_spec.rb

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b8c6e60..a0a9ab0 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -21,6 +21,13 @@ before_script:
     paths:
       - .gems
 
+.ruby_25: &ruby_25
+  image: registry.roqua.nl/roqua/docker-base-images:ruby-2.5
+  cache:
+    key: ruby_25
+    paths:
+      - .gems
+
 rails_42_ruby_23:
   <<: *ruby_23
   script:
@@ -36,6 +43,11 @@ rails_50_ruby_24:
   script:
     - bundle exec appraisal rails50 bundle exec rspec
 
+rails_50_ruby_25:
+  <<: *ruby_25
+  script:
+    - bundle exec appraisal rails50 bundle exec rspec
+
 rails_51_ruby_23:
   <<: *ruby_23
   script:
@@ -46,6 +58,11 @@ rails_51_ruby_24:
   script:
     - bundle exec appraisal rails51 bundle exec rspec
 
+rails_51_ruby_25:
+  <<: *ruby_25
+  script:
+    - bundle exec appraisal rails51 bundle exec rspec
+
 rails_52_ruby_23:
   <<: *ruby_23
   script:
@@ -55,3 +72,8 @@ rails_52_ruby_24:
   <<: *ruby_24
   script:
     - bundle exec appraisal rails52 bundle exec rspec
+
+rails_52_ruby_25:
+  <<: *ruby_25
+  script:
+    - bundle exec appraisal rails52 bundle exec rspec
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 849c230..2a96838 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 0.3.0
+
+* Support for Ruby 2.5
+* Removed Fixnum#clamp, since Fixnum was deprecated and the clamp method was never used.
+
 ## 0.2.0
 
 * Removed Array#stable_sort_by, since it was not stable and the name was wrong.
diff --git a/Gemfile b/Gemfile
index deb8331..ad25f50 100644
--- a/Gemfile
+++ b/Gemfile
@@ -9,7 +9,7 @@ gem 'roqua_styleguide', git: 'https://gitlab.roqua.nl/roqua/styleguide.git'
 group :test do
   gem 'actionpack', '>= 4.0'
   gem 'active_interaction', '~> 3.0'
-  gem 'appsignal'
+  gem 'appsignal', '~> 2.9.6'
   gem 'climate_control' # For ENV modification in specs
   gem 'combustion', '~> 0.5.2'
   gem 'fakefs', require: 'fakefs/safe'
diff --git a/Gemfile.lock b/Gemfile.lock
index a321c67..1f7b53e 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -8,7 +8,7 @@ GIT
 PATH
   remote: .
   specs:
-    roqua-support (0.1.33)
+    roqua-support (0.3.0)
       active_interaction (~> 3.0)
       activesupport (>= 3.2, < 6)
       naught (~> 1.0)
@@ -47,7 +47,7 @@ GEM
       bundler
       rake
       thor (>= 0.14.0)
-    appsignal (2.3.1)
+    appsignal (2.9.6)
       rack
     arel (7.1.4)
     ast (2.3.0)
@@ -181,7 +181,7 @@ DEPENDENCIES
   actionpack (>= 4.0)
   active_interaction (~> 3.0)
   appraisal
-  appsignal
+  appsignal (~> 2.9.6)
   bundler (~> 1.0)
   climate_control
   combustion (~> 0.5.2)
@@ -195,8 +195,8 @@ DEPENDENCIES
   rspec (>= 2.12.0, < 4.0)
   rspec-instrumentation-matcher
   rspec-rails
-  sqlite3
+  sqlite3 (~> 1.3.6)
   timecop
 
 BUNDLED WITH
-   1.16.4
+   1.16.6
diff --git a/lib/roqua-support/version.rb b/lib/roqua-support/version.rb
index 25a34a8..b1a181b 100644
--- a/lib/roqua-support/version.rb
+++ b/lib/roqua-support/version.rb
@@ -1,5 +1,5 @@
 module Roqua
   module Support
-    VERSION = '0.2.0'.freeze
+    VERSION = '0.3.0'.freeze
   end
 end
diff --git a/lib/roqua/core_ext/fixnum/clamp.rb b/lib/roqua/core_ext/fixnum/clamp.rb
deleted file mode 100644
index f25971d..0000000
--- a/lib/roqua/core_ext/fixnum/clamp.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-class Fixnum
-  def clamp(low, high)
-    raise "Low (#{low}) must be lower than high (#{high})" unless low < high
-    return low if self < low
-    return high if self > high
-    self
-  end
-end
\ No newline at end of file
diff --git a/lib/roqua/logging/roqua_logging_railtie.rb b/lib/roqua/logging/roqua_logging_railtie.rb
index 1d28c45..6881646 100644
--- a/lib/roqua/logging/roqua_logging_railtie.rb
+++ b/lib/roqua/logging/roqua_logging_railtie.rb
@@ -1,4 +1,3 @@
-
 class RoquaLoggingRailtie < Rails::Railtie
   config.after_initialize do |app|
     RoquaLoggingRailtie.configure
diff --git a/lib/roqua/probes/base_probe.rb b/lib/roqua/probes/base_probe.rb
index 7ae1a35..61411e5 100644
--- a/lib/roqua/probes/base_probe.rb
+++ b/lib/roqua/probes/base_probe.rb
@@ -3,7 +3,8 @@ module Roqua
     module BaseProbe
       def enable
         new.tap do |probe|
-          Appsignal::Minutely.probes << probe unless Appsignal::Minutely.probes.map(&:class).include?(probe.class)
+          probe_sym = probe.class.to_s.to_sym
+          Appsignal::Minutely.probes.register(probe_sym, probe) unless Appsignal::Minutely.probes[probe_sym]
         end
       end
     end
diff --git a/lib/roqua/support.rb b/lib/roqua/support.rb
index 77f1c16..b4b5f52 100644
--- a/lib/roqua/support.rb
+++ b/lib/roqua/support.rb
@@ -1,5 +1,5 @@
 require 'logger'
-require 'roqua/logging/roqua_logging_railtie'
+require 'roqua/logging/roqua_logging_railtie' if defined?(Rails)
 require 'roqua/support/instrumentation'
 require 'roqua/support/log_wrapper'
 require 'roqua/support/errors'
diff --git a/lib/roqua/support/errors.rb b/lib/roqua/support/errors.rb
index bb0c69d..d90b18f 100644
--- a/lib/roqua/support/errors.rb
+++ b/lib/roqua/support/errors.rb
@@ -62,7 +62,6 @@ module Roqua
                               parameters: parameters}
             exception_info[:notification_urls] = notification_urls if notification_urls.present?
             exception_info[:backtrace] = exception.backtrace unless skip_backtrace
-            puts exception_info.inspect
             Roqua.logger.error('roqua.exception', exception_info)
           end
         rescue Exception
diff --git a/roqua-support.gemspec b/roqua-support.gemspec
index e3cf0b0..8e41528 100644
--- a/roqua-support.gemspec
+++ b/roqua-support.gemspec
@@ -28,6 +28,6 @@ Gem::Specification.new do |gem|
   gem.add_development_dependency 'delayed_job_active_record'
   gem.add_development_dependency 'rake'
   gem.add_development_dependency 'rspec', '>= 2.12.0', '< 4.0'
-  gem.add_development_dependency 'sqlite3'
+  gem.add_development_dependency 'sqlite3', '~> 1.3.6'
   gem.add_development_dependency 'timecop'
 end
diff --git a/spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb b/spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
index 562d7bf..9de0b2f 100644
--- a/spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
+++ b/spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
@@ -2,20 +2,17 @@ require 'roqua/core_ext/enumerable/sort_by_alphanum'
 
 describe Enumerable do
   describe '#sort_by_alphanum' do
+    let(:input) { ["004some11thing", "004some10thing", "3another"] }
     it 'sorts by chunks' do
-      ["004some11thing",
-       "004some10thing",
-       "3another"].sort_by_alphanum.should == ["3another", "004some10thing", "004some11thing"]
+      expect(input.sort_by_alphanum).to eq ["3another", "004some10thing", "004some11thing"]
     end
 
     it 'can take a block which can transform values before comparison' do
-      ["004some11thing",
-       "004some10thing",
-       "3another"].sort_by_alphanum(&:reverse).should == ["004some10thing", "004some11thing", "3another"]
+      expect(input.sort_by_alphanum(&:reverse)).to eq ["004some10thing", "004some11thing", "3another"]
     end
 
     it 'compares number chunks as integers' do
-      %w(004 3).sort_by_alphanum.should == %w(3 004)
+      expect(%w(004 3).sort_by_alphanum).to eq %w(3 004)
     end
   end
-end
\ No newline at end of file
+end
diff --git a/spec/roqua/core_ext/fabrication/singleton_spec.rb b/spec/roqua/core_ext/fabrication/singleton_spec.rb
index b812b90..4009677 100644
--- a/spec/roqua/core_ext/fabrication/singleton_spec.rb
+++ b/spec/roqua/core_ext/fabrication/singleton_spec.rb
@@ -6,11 +6,13 @@ end
 
 describe Fabricate do
   it "returns singleton objects" do
-    Fabricate.singleton(:one).should == Fabricate.singleton(:one)
+    # Fabricate.singleton(:one).should == Fabricate.singleton(:one)
+    expect(Fabricate.singleton(:one)).to eq Fabricate.singleton(:one)
   end
 
   it 'maintains multiple singletons' do
-    Fabricate.singleton(:one).should_not == Fabricate.singleton(:two)
+    # Fabricate.singleton(:one).should_not == Fabricate.singleton(:two)
+    expect(Fabricate.singleton(:one)).not_to eq Fabricate.singleton(:two)
   end
 
   it 'clears singletons' do
@@ -19,4 +21,3 @@ describe Fabricate do
     expect(Fabricate.singleton(:one)).not_to eq(the_one)
   end
 end
-
diff --git a/spec/roqua/core_ext/fixnum/clamp_spec.rb b/spec/roqua/core_ext/fixnum/clamp_spec.rb
deleted file mode 100644
index 4889102..0000000
--- a/spec/roqua/core_ext/fixnum/clamp_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require 'roqua/core_ext/fixnum/clamp'
-
-describe Fixnum do
-  describe '#clamp' do
-    it "returns self if within bounds" do
-      5.clamp(1,10).should == 5
-    end
-
-    it "returns the lower bound if self < low" do
-      5.clamp(8,10).should == 8
-    end
-
-    it "returns the upper bound if self > high" do
-      5.clamp(1,3).should == 3
-    end
-
-    it "should raise an exception if the lower bound is greater than the upper bound" do
-      expect {
-        5.clamp(10,1)
-      }.to raise_error
-    end
-  end
-end
diff --git a/spec/roqua/probes/delayed_job_probe_spec.rb b/spec/roqua/probes/delayed_job_probe_spec.rb
index de10d9b..39c1151 100644
--- a/spec/roqua/probes/delayed_job_probe_spec.rb
+++ b/spec/roqua/probes/delayed_job_probe_spec.rb
@@ -40,7 +40,7 @@ describe Roqua::Probes::DelayedJobProbe do
       expect { Roqua::Probes::DelayedJobProbe.enable }
         .to change { Appsignal::Minutely.probes.count }.by(1)
 
-      expect(Appsignal::Minutely.probes.map(&:class)).to include(Roqua::Probes::DelayedJobProbe)
+      expect(Appsignal::Minutely.probes[:"Roqua::Probes::DelayedJobProbe"]).to be
     end
 
     it 'will not add the same probe twice if called multiple times' do
diff --git a/spec/roqua/support/helpers_spec.rb b/spec/roqua/support/helpers_spec.rb
index 17a987e..8a3e218 100644
--- a/spec/roqua/support/helpers_spec.rb
+++ b/spec/roqua/support/helpers_spec.rb
@@ -23,7 +23,7 @@ describe 'Helper methods' do
       end
 
       it 'returns the value returned by the block' do
-        with_instrumentation('testevent') { 1 + 1 }.should == 2
+        expect(with_instrumentation('testevent') { 1 + 1 }).to eq 2
       end
     end
 
diff --git a/spec/roqua/support/logwrapper_spec.rb b/spec/roqua/support/logwrapper_spec.rb
index 727ee0a..61c19cf 100644
--- a/spec/roqua/support/logwrapper_spec.rb
+++ b/spec/roqua/support/logwrapper_spec.rb
@@ -4,7 +4,7 @@ require 'stringio'
 
 module Roqua
   describe LogWrapper do
-    before { Roqua.stub(appname: 'roqua-support-testsuite') }
+    before { allow(Roqua).to receive(:appname).and_return('roqua-support-testsuite') }
 
     let(:logstream)  { StringIO.new }
     let(:logger)     { Logger.new(logstream) }
@@ -17,17 +17,17 @@ module Roqua
     describe '#add' do
       it 'writes event name to log' do
         logwrapper.add :info, "testevent"
-        log.should include("testevent {}\n")
+        expect(log).to include("testevent {}\n")
       end
 
       it 'writes given parameters as json hash' do
         logwrapper.add :info, "testevent", extra: 'params', go: 'here'
-        log.should include('testevent {"extra":"params","go":"here"}' + "\n")
+        expect(log).to include('testevent {"extra":"params","go":"here"}' + "\n")
       end
 
       it 'escapes newline characters in params' do
         logwrapper.add :info, "testevent", param: "this\nshould not have newlines"
-        log.should include('testevent {"param":"this\nshould not have newlines"')
+        expect(log).to include('testevent {"param":"this\nshould not have newlines"')
       end
     end
 
@@ -36,25 +36,25 @@ module Roqua
         logwrapper.lifecycle 'testevent', extra: 'params' do
           1 + 1
         end
-        log.should include('testevent:started {"extra":"params"}')
-        log.should match(/testevent:finished.*"extra":"params"/)
+        expect(log).to include('testevent:started {"extra":"params"}')
+        expect(log).to match(/testevent:finished.*"extra":"params"/)
       end
 
       it 'logs the duration of the block with the finished event' do
         logwrapper.lifecycle('testevent') { 1 + 1 }
-        log.should match(/testevent:finished.*"duration":/)
+        expect(log).to match(/testevent:finished.*"duration":/)
       end
 
       it 'returns the value returned by the block' do
-        logwrapper.lifecycle('testevent') { 1 + 1 }.should == 2
+        expect(logwrapper.lifecycle('testevent') { 1 + 1 }).to eq 2
       end
 
       it 'logs the start and failure of a block if it raises' do
         logwrapper.lifecycle 'testevent' do
           raise StandardError, "Foo"
         end rescue nil
-        log.should include('testevent:started')
-        log.should include('testevent:failed {"exception":"StandardError","message":"Foo"}')
+        expect(log).to include('testevent:started')
+        expect(log).to include('testevent:failed {"exception":"StandardError","message":"Foo"}')
       end
 
       it 'reraises the exception' do
diff --git a/spec/roqua/support/request_logger_spec.rb b/spec/roqua/support/request_logger_spec.rb
index abeba8b..ae78fc3 100644
--- a/spec/roqua/support/request_logger_spec.rb
+++ b/spec/roqua/support/request_logger_spec.rb
@@ -8,7 +8,8 @@ describe Roqua::Support::RequestLogger do
   let(:logger)     { Logger.new(logstream) }
   let(:logwrapper) { Roqua::LogWrapper.new(logger) }
 
-  before { Roqua.stub(logger: logwrapper) }
+  # before { Roqua.stub(logger: logwrapper) }
+  before { allow(Roqua).to receive(:logger).and_return(logwrapper) }
 
   def log
     logstream.string
@@ -29,47 +30,47 @@ describe Roqua::Support::RequestLogger do
 
     it "logs the URL" do
       subscriber.process_action(event)
-      logstream.string.should include('/home')
+      expect(logstream.string).to include('/home')
     end
 
     it "does not log the query string" do
       subscriber.process_action(event)
-      logstream.string.should_not include('?foo=bar')
+      expect(logstream.string).to_not include('?foo=bar')
     end
 
     it "logs the HTTP method" do
       subscriber.process_action(event)
-      logstream.string.should include('"method":"GET"')
+      expect(logstream.string).to include('"method":"GET"')
     end
 
     it "logs the status code returned" do
       subscriber.process_action(event)
-      logstream.string.should include('"status":200')
+      expect(logstream.string).to include('"status":200')
     end
 
     it "logs the controller and action" do
       subscriber.process_action(event)
-      logstream.string.should include('"controller":"home","action":"index"')
+      expect(logstream.string).to include('"controller":"home","action":"index"')
     end
 
     it 'logs request parameters' do
       subscriber.process_action(event)
-      logstream.string.should include('"params":{"foo":"bar"}')
+      expect(logstream.string).to include('"params":{"foo":"bar"}')
     end
 
     it "logs how long the request took" do
       subscriber.process_action(event)
-      logstream.string.should =~ /"duration":1000.0/
+      expect(logstream.string).to match /"duration":1000.0/
     end
 
     it "logs the view rendering time" do
       subscriber.process_action(event)
-      logstream.string.should =~ /"view":0.01/
+      expect(logstream.string).to match /"view":0.01/
     end
 
     it "logs the database rendering time" do
       subscriber.process_action(event)
-      logstream.string.should =~ /"db":0.02/
+      expect(logstream.string).to match /"db":0.02/
     end
 
     it 'logs extra information added in the controller' do
@@ -82,12 +83,12 @@ describe Roqua::Support::RequestLogger do
       end
       controller.new.index
       subscriber.process_action(event)
-      logstream.string.should include('"current_user":"johndoe"')
+      expect(logstream.string).to include('"current_user":"johndoe"')
 
       # next request should not still maintain this data
       logstream.truncate 0
       subscriber.process_action(event)
-      logstream.string.should_not include('current_user')
+      expect(logstream.string).to_not include('current_user')
     end
   end
 
@@ -104,15 +105,15 @@ describe Roqua::Support::RequestLogger do
 
     it "logs the 500 status when an exception occurred" do
       subscriber.process_action(event)
-      logstream.string.should =~ /"status":500/
-      logstream.string.should =~ /"error":"AbstractController::ActionNotFound:Route not found"/
+      expect(logstream.string).to match /"status":500/
+      expect(logstream.string).to match /"error":"AbstractController::ActionNotFound:Route not found"/
     end
 
     it "should return an unknown status when no status or exception is found" do
       event.payload[:status] = nil
       event.payload[:exception] = nil
       subscriber.process_action(event)
-      logstream.string.should =~ /"status":0/
+      expect(logstream.string).to match /"status":0/
     end
   end
 
@@ -136,12 +137,12 @@ describe Roqua::Support::RequestLogger do
     it 'logs the redirect' do
       subscriber.redirect_to(redirect)
       subscriber.process_action(event)
-      log.should include('"location":"http://example.com"')
+      expect(log).to include('"location":"http://example.com"')
 
       # next request should no longer get location
       logstream.truncate 0
       subscriber.process_action(event)
-      log.should_not include('location')
+      expect(log).to_not include('location')
     end
   end
 end
diff --git a/spec/roqua/support_spec.rb b/spec/roqua/support_spec.rb
index 39cc8c3..275a9dd 100644
--- a/spec/roqua/support_spec.rb
+++ b/spec/roqua/support_spec.rb
@@ -3,7 +3,7 @@ require 'roqua/support'
 describe Roqua do
   describe '#logger' do
     it 'has a default' do
-      Roqua.logger.should be_an_instance_of(Roqua::LogWrapper)
+      expect(Roqua.logger).to be_an_instance_of(Roqua::LogWrapper)
     end
   end
 
@@ -12,8 +12,8 @@ describe Roqua do
 
     it 'wraps a given logger' do
       Roqua.logger = logger
-      Roqua.logger.should be_an_instance_of(Roqua::LogWrapper)
-      Roqua.logger.logger.should == logger
+      expect(Roqua.logger).to be_an_instance_of(Roqua::LogWrapper)
+      expect(Roqua.logger.logger).to eq logger
     end
   end
 end
-- 
GitLab