Skip to content

Commit

Permalink
Merge pull request #17 from fluxfederation/semvar-comparison
Browse files Browse the repository at this point in the history
[1.0.17] Rectify semantic version comparison
  • Loading branch information
benjessop12 authored Oct 25, 2021
2 parents 6f4c0f5 + fa7a3e1 commit afd70d7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Metrics/BlockLength:
ExcludedMethods: ['describe', 'context']
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/nitra/workers/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion nitra.gemspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
42 changes: 42 additions & 0 deletions spec/nitra/workers/rspec_spec.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit afd70d7

Please sign in to comment.