Skip to content

Commit 611cfe1

Browse files
committed
♻️ Refactor spec harness
1 parent 9c3fe2b commit 611cfe1

File tree

8 files changed

+65
-38
lines changed

8 files changed

+65
-38
lines changed

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gemspec
1717

1818
platform :mri do
1919
# Debugging - Ensure ENV["DEBUG"] == "true" to use debuggers within spec suite
20-
if ruby_version < Gem::Version.new("2.7")
20+
if ruby_version < Gem::Version.create("2.7")
2121
# Use byebug in code
2222
gem "byebug", ">= 11"
2323
else
@@ -49,3 +49,5 @@ eval_gemfile "gemfiles/modular/style.gemfile"
4949
eval_gemfile "gemfiles/modular/documentation.gemfile"
5050

5151
gem "appraisal", github: "pboling/appraisal", branch: "galtzo"
52+
53+
gem "gem_checksums", github: "pboling/gem_checksums", branch: "feat/docs"

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ GIT
88
rake (>= 10)
99
thor (>= 0.14.0)
1010

11+
GIT
12+
remote: https://github.com/pboling/gem_checksums
13+
revision: 5ae91cf8cbf741c76254272c8dac09b2afac22c7
14+
branch: feat/docs
15+
specs:
16+
gem_checksums (1.0.0)
17+
version_gem (>= 1.1.5, < 3)
18+
1119
PATH
1220
remote: .
1321
specs:
@@ -233,6 +241,7 @@ DEPENDENCIES
233241
benchmark (~> 0.4)
234242
bundler-audit (~> 0.9.2)
235243
debug (>= 1.0.0)
244+
gem_checksums!
236245
github-markup (~> 5.0, >= 5.0.1)
237246
kettle-soup-cover (~> 1.0, >= 1.0.4)
238247
pry (~> 0.14)

Rakefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,14 @@ rescue LoadError
6868
task(coverage: :spec)
6969
end
7070

71+
begin
72+
require "gem_checksums"
73+
GemChecksums.install_tasks
74+
rescue LoadError
75+
task("build:checksums") do
76+
warn("gem_checksums is not available")
77+
end
78+
end
79+
7180
# coverage task will open coverage in browser locally
7281
task default: %i[coverage rubocop_gradual:autocorrect yard yard:junk]

spec/config/byebug.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if ENV.fetch("DEBUG", "false").casecmp?("true")
2+
ruby_version = Gem::Version.create(RUBY_VERSION)
3+
if ruby_version < Gem::Version.create("2.7")
4+
# Use byebug in code
5+
require "byebug"
6+
else
7+
# Use binding.break, binding.b, or debugger in code
8+
require "debug"
9+
end
10+
end
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
require "rspec/block_is_expected"
2-
3-
# This breaks RSpec v2, which may be used to run transpec.
4-
# So allow it to be turned off.
5-
require "rspec/block_is_expected/matchers/not" unless ENV["TRANSPEC"] == "true"
2+
require "rspec/block_is_expected/matchers/not"

spec/helpers/faux.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# - Not requiring because we want line coverage
2+
# - Not loading because we don't want to manage the constant re-definition
3+
module VersionGem
4+
# Helpers for library CI integration against many different versions of Ruby
5+
module Faux
6+
RUBY_VER = ::Gem::Version.new(RUBY_VERSION)
7+
8+
def gte_minimum_version?(version, engine = "ruby")
9+
RUBY_VER >= ::Gem::Version.new(version) && ::RUBY_ENGINE == engine
10+
end
11+
module_function :gte_minimum_version?
12+
13+
def actual_minor_version?(major, minor, engine = "ruby")
14+
major.to_i == RUBY_VER.segments[0] &&
15+
minor.to_i == RUBY_VER.segments[1] &&
16+
::RUBY_ENGINE == engine
17+
end
18+
module_function :actual_minor_version?
19+
end
20+
end

spec/spec_helper.rb

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,27 @@
11
# frozen_string_literal: true
22

3-
begin
4-
# This does not require "simplecov",
5-
# because that has a side-effect of running `.simplecov`
6-
# Avoid loading version_gem via "kettle-soup-cover":
7-
require "kettle/soup/cover"
8-
rescue LoadError
9-
puts "Not running code coverage"
10-
end
11-
123
DEBUG = ENV.fetch("DEBUG", nil) == "true"
134
DEBUG_IDE = ENV.fetch("DEBUG_IDE", "false") == "true"
145

15-
# Ruby Helpers from this gem.
16-
# - Not requiring because we want line coverage
17-
# - Not loading because we don't want to manage the constant re-definition
18-
module VersionGem
19-
# Helpers for library CI integration against many different versions of Ruby
20-
module Faux
21-
RUBY_VER = ::Gem::Version.new(RUBY_VERSION)
22-
23-
def gte_minimum_version?(version, engine = "ruby")
24-
RUBY_VER >= ::Gem::Version.new(version) && ::RUBY_ENGINE == engine
25-
end
26-
module_function :gte_minimum_version?
27-
28-
def actual_minor_version?(major, minor, engine = "ruby")
29-
major.to_i == RUBY_VER.segments[0] &&
30-
minor.to_i == RUBY_VER.segments[1] &&
31-
::RUBY_ENGINE == engine
32-
end
33-
module_function :actual_minor_version?
34-
end
35-
end
36-
376
# RSpec Configs
7+
require_relative "config/byebug"
388
require_relative "config/rspec/rspec_core"
399
require_relative "config/rspec/rspec_block_is_expected"
4010

4111
# RSpec Helpers which do not depend on gem internals
42-
# NONE
12+
require_relative "helpers/faux"
4313

4414
# Last thing before this gem is code coverage:
45-
require "simplecov" if defined?(Kettle) && Kettle::Soup::Cover::DO_COV
15+
begin
16+
# kettle-soup-cover does not require "simplecov", but
17+
# we do that next, and that has a side effect of running `.simplecov`
18+
# Also, we must avoid loading "version_gem" (this gem) via "kettle-soup-cover",
19+
# so instead of the normal kettle-soup-cover we use kettle/soup/cover.
20+
require "kettle/soup/cover"
21+
require "simplecov" if defined?(Kettle) && Kettle::Soup::Cover::DO_COV
22+
rescue LoadError
23+
nil
24+
end
4625

4726
# This gem
4827
require "version_gem"

version_gem.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Gem::Specification.new do |spec|
7171
spec.add_development_dependency("rspec-block_is_expected", "~> 1.0") # ruby >= 1.8.7
7272

7373
# Development Tasks
74+
spec.add_development_dependency("gem_checksums", "~> 1.0") # ruby >= 2.2
7475
spec.add_development_dependency("rake", "~> 13.0") # ruby >= 2.2
7576

7677
# Linting - rubocop-lts v8 is a rubocop wrapper for Ruby >= 2.2,

0 commit comments

Comments
 (0)