Skip to content

Commit 7987f67

Browse files
committed
Switch from minitest to RSpec
1 parent fd3faff commit 7987f67

19 files changed

+382
-262
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ jobs:
7373
bundler-cache: true
7474

7575
- name: RSpec
76-
run: bin/rake
76+
run: bin/rspec

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
Gemfile.lock
66
gemfiles/*.lock
77

8+
# Ignore test files
9+
coverage/
10+
811
# Ignore logs
9-
test/*.log
12+
spec/*.log
1013

1114
# Ignore MacOS files
1215
.DS_Store

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ AllCops:
99
Exclude:
1010
- bin/*
1111
- gemfiles/*
12-
- test/**/*
12+
- spec/**/*
1313
- lib/store_base_sti_class_for_*.rb
1414

1515
Gemspec/RequireMFA:

Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ gemspec
66

77
gem 'appraisal', git: 'https://github.com/n-rodriguez/appraisal.git', branch: 'wip/combustion'
88

9-
gem 'minitest'
10-
gem 'minitest-reporters'
119
gem 'pg'
1210
gem 'rake'
11+
gem 'rspec'
1312
gem 'rubocop'
1413
gem 'rubocop-rake'
1514
gem 'rubocop-rspec'
15+
gem 'simplecov'

Rakefile

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'bundler/gem_tasks'
4-
require 'rake/testtask'
4+
require 'rspec/core/rake_task'
55

6-
Rake::TestTask.new(:test) do |t|
7-
t.libs << 'lib' << 'test'
8-
t.pattern = 'test/**/*_test.rb'
9-
t.verbose = true
10-
t.warning = false
11-
end
12-
13-
task default: :test
6+
RSpec::Core::RakeTask.new(:spec)
7+
task default: :spec

bin/rspec

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rspec' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12+
13+
bundle_binstub = File.expand_path("bundle", __dir__)
14+
15+
if File.file?(bundle_binstub)
16+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17+
load(bundle_binstub)
18+
else
19+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21+
end
22+
end
23+
24+
require "rubygems"
25+
require "bundler/setup"
26+
27+
load Gem.bin_path("rspec-core", "rspec")

gemfiles/activerecord_7.0.8.gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
source "https://rubygems.org"
44

55
gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion"
6-
gem "minitest"
7-
gem "minitest-reporters"
86
gem "pg"
97
gem "rake"
8+
gem "rspec"
109
gem "rubocop"
1110
gem "rubocop-rake"
1211
gem "rubocop-rspec"
12+
gem "simplecov"
1313
gem "activerecord", "7.0.8"
1414

1515
install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3.0") } do

gemfiles/activerecord_7.1.3.gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
source "https://rubygems.org"
44

55
gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion"
6-
gem "minitest"
7-
gem "minitest-reporters"
86
gem "pg"
97
gem "rake"
8+
gem "rspec"
109
gem "rubocop"
1110
gem "rubocop-rake"
1211
gem "rubocop-rspec"
12+
gem "simplecov"
1313
gem "activerecord", "7.1.3"
1414

1515
install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do

gemfiles/activerecord_7.2.0.gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
source "https://rubygems.org"
44

55
gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion"
6-
gem "minitest"
7-
gem "minitest-reporters"
86
gem "pg"
97
gem "rake"
8+
gem "rspec"
109
gem "rubocop"
1110
gem "rubocop-rake"
1211
gem "rubocop-rspec"
12+
gem "simplecov"
1313
gem "activerecord", "7.2.0"
1414

1515
gemspec path: "../"

spec/config_rspec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
# Configure RSpec
4+
RSpec.configure do |config|
5+
config.include TestHelper
6+
7+
config.color = true
8+
config.fail_fast = false
9+
10+
# Run tests in random order
11+
config.order = :random
12+
Kernel.srand config.seed
13+
14+
config.expect_with :rspec do |c|
15+
c.syntax = :expect
16+
end
17+
18+
# disable monkey patching
19+
# see: https://relishapp.com/rspec/rspec-core/v/3-8/docs/configuration/zero-monkey-patching-mode
20+
config.disable_monkey_patching!
21+
end

spec/rspec_patch.rb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module RSpecPatch
2+
module Expectations
3+
def expectation_count
4+
@expectation_count ||= 0
5+
end
6+
7+
def update_expectation_count
8+
@expectation_count = expectation_count + 1
9+
end
10+
end
11+
12+
module Matchers
13+
def expect(*args, &block)
14+
::RSpec::Expectations.update_expectation_count
15+
super
16+
end
17+
end
18+
19+
module SummaryNotification
20+
def totals_line(*args)
21+
text = super
22+
count = ::RSpec::Expectations.expectation_count
23+
message = RSpec::Core::Formatters::Helpers.pluralize(count, "expectation")
24+
"#{text.chomp}, #{message}"
25+
end
26+
end
27+
end
28+
29+
unless ::RSpec::Expectations.respond_to?(:expectation_count)
30+
RSpec::Expectations.extend(RSpecPatch::Expectations)
31+
RSpec::Matchers.prepend(RSpecPatch::Matchers)
32+
RSpec::Core::Notifications::SummaryNotification.prepend(RSpecPatch::SummaryNotification)
33+
end

spec/spec_helper.rb

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
require 'simplecov'
4+
5+
# Start SimpleCov
6+
SimpleCov.start do
7+
add_filter 'spec/'
8+
end
9+
10+
# Load test gems
11+
require 'active_record'
12+
13+
# Requires supporting ruby files with custom matchers and macros, etc,
14+
# in spec/support/ and its subdirectories.
15+
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }
16+
17+
# Load our own config
18+
require_relative 'config_rspec'
19+
require_relative 'rspec_patch'
20+
21+
# Setup DB connections
22+
test_db_config = {
23+
adapter: 'postgresql',
24+
host: '127.0.0.1',
25+
database: 'store_base_sti_class_test',
26+
username: 'postgres',
27+
password: 'postgres',
28+
encoding: 'utf8'
29+
}
30+
31+
ActiveRecord::Tasks::DatabaseTasks.env = 'test'
32+
ActiveRecord::Base.configurations = { 'test' => test_db_config }
33+
ActiveRecord::Base.logger = Logger.new('spec/test.log')
34+
35+
# Re-create test database
36+
ActiveRecord::Tasks::DatabaseTasks.drop_current
37+
ActiveRecord::Tasks::DatabaseTasks.create_current
38+
39+
# Load schema
40+
Schema.up
41+
42+
require 'store_base_sti_class'

0 commit comments

Comments
 (0)