From fa7a3e17c98e7b3ff971aadd157059e81eb50a9b Mon Sep 17 00:00:00 2001 From: "benjamin.jessop" Date: Tue, 26 Oct 2021 07:35:27 +1300 Subject: [PATCH] [1.0.17] Rectify semantic version comparison Instead of relying on UTF-8 weight comparison via String types, evaluate via Gem::Version classes instead. These semantic versions are seperated by periods and each partition should be considered as its own number. In String form, `3.10` is less than `3.2` as the UTF-8 comparison stops on first difference: `3.1` is lt `3.2`. This was causing issues for the comparison for RSpec version when attempting to bump to the latest (`3.10.1`). --- .rubocop.yml | 2 ++ CHANGELOG.md | 4 +++ lib/nitra/workers/rspec.rb | 6 +++-- nitra.gemspec | 2 +- spec/nitra/workers/rspec_spec.rb | 42 ++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 4 +++ 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 .rubocop.yml create mode 100644 spec/nitra/workers/rspec_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..b0e3775 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +Metrics/BlockLength: + ExcludedMethods: ['describe', 'context'] diff --git a/CHANGELOG.md b/CHANGELOG.md index a39b931..a07d987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## Unreleased ### Updated +## [1.0.17] - 2021-10-26 +### Updated +- Rectify an issue with SemVer comparison + ## [1.0.16] - 2020-04-15 ### Updated - Proactively sort splittable rspec files so all splittable files are processed first diff --git a/lib/nitra/workers/rspec.rb b/lib/nitra/workers/rspec.rb index aa11b1c..8694491 100644 --- a/lib/nitra/workers/rspec.rb +++ b/lib/nitra/workers/rspec.rb @@ -2,6 +2,8 @@ module Nitra::Workers class Rspec < Worker + RSPEC_SEM_VER_VERSION = Gem::Version.new(RSpec::Core::Version::STRING) + def self.filename_match?(filename) filename =~ /_spec\.rb/ end @@ -94,7 +96,7 @@ def runner_for(filename, preloading) args << filename result = - if RSpec::Core::const_defined?(:CommandLine) && RSpec::Core::Version::STRING < "2.99" + if RSpec::Core::const_defined?(:CommandLine) && RSPEC_SEM_VER_VERSION < Gem::Version.new('2.99') RSpec::Core::CommandLine.new(args) else options = RSpec::Core::ConfigurationOptions.new(args) @@ -108,7 +110,7 @@ def runner_for(filename, preloading) def clean_up super - if RSpec::Core::Version::STRING < "3.2" + if RSPEC_SEM_VER_VERSION < Gem::Version.new('3.2') # Rspec.reset in 2.6 didn't destroy your rspec_rails fixture loading, we can't use it anymore for it's intended purpose. # This means our world object will be slightly polluted by the preload_framework code, but that's a small price to pay # to upgrade. diff --git a/nitra.gemspec b/nitra.gemspec index e72a062..ef89d66 100644 --- a/nitra.gemspec +++ b/nitra.gemspec @@ -1,6 +1,6 @@ spec = Gem::Specification.new do |s| s.name = 'nitra' - s.version = '1.0.16' + s.version = '1.0.17' s.platform = Gem::Platform::RUBY s.license = "MIT" s.homepage = "http://github.com/fluxfederation/nitra" diff --git a/spec/nitra/workers/rspec_spec.rb b/spec/nitra/workers/rspec_spec.rb new file mode 100644 index 0000000..d87c1cd --- /dev/null +++ b/spec/nitra/workers/rspec_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require_relative '../../spec_helper' +require_relative '../../../lib/nitra/workers/rspec' + +require 'rspec' + +describe Nitra::Workers::Rspec do + describe '#clean_up' do + let(:described_instance) do + described_class.new( + nil, + nil, + RSpec.configuration + ) + end + + context 'when the rspec semantic version is < 3.2' do + before do + stub_const('Nitra::Workers::Rspec::RSPEC_SEM_VER_VERSION', Gem::Version.new('3.0')) + allow(::RSpec.configuration).to receive(:reset) + end + + it 'calls RSpec.configuration.reset' do + described_instance.clean_up + expect(::RSpec.configuration).to have_received(:reset) + end + end + + context 'when the rspec semantic version is > 3.2' do + before do + stub_const('Nitra::Workers::Rspec::RSPEC_SEM_VER_VERSION', Gem::Version.new('3.10.1')) + allow(::RSpec).to receive(:clear_examples) + end + + it 'calls RSpec.clear_examples' do + described_instance.clean_up + expect(::RSpec).to have_received(:clear_examples) + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index eba0de7..5e29386 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,8 @@ +# frozen_string_literal: true + require 'minitest/spec' require 'minitest/autorun' require 'minitest/reporters' Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new) + +require_relative '../lib/nitra'