Skip to content

Commit 09ffe3b

Browse files
authored
Migrate to minitest (#403)
* Migrate to minitest
1 parent c680ce3 commit 09ffe3b

File tree

6 files changed

+87
-13
lines changed

6 files changed

+87
-13
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,27 @@ end
661661
662662
## Testing
663663
664-
Closure tree is [tested under every valid combination](http://travis-ci.org/#!/ClosureTree/closure_tree) of
664+
Closure tree is [tested under every valid combination](https://github.com/ClosureTree/closure_tree/blob/master/.github/workflows/ci.yml) of
665665
666666
* Ruby 2.7+
667667
* ActiveRecord 6.0+
668668
* PostgreSQL, MySQL, and SQLite. Concurrency tests are only run with MySQL and PostgreSQL.
669669
670-
Assuming you're using [rbenv](https://github.com/sstephenson/rbenv), you can use ```tests.sh``` to
671-
run the test matrix locally.
670+
```shell
671+
$ bundle
672+
$ appraisal bundle # this will install the matrix of dependencies
673+
$ appraisal rake # this will run the tests in all combinations
674+
$ appraisal activerecord-7.0 rake # this will run the tests in AR 7.0 only
675+
$ appraisal activerecord-7.0 rake spec # this will run rspec in AR 7.0 only
676+
$ appraisal activerecord-7.0 rake test # this will run minitest in AR 7.0 only
677+
```
678+
679+
By default the test are run with sqlite3 only.
680+
You run test with other databases by passing the database url as environment variable:
681+
682+
```shell
683+
$ DATABASE_URL=postgres://localhost/my_database appraisal activerecord-7.0 rake test
684+
```
672685
673686
## Change log
674687

Rakefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
require 'bundler/gem_tasks'
44
require 'rspec/core/rake_task'
5+
require 'rake/testtask'
56

67
RSpec::Core::RakeTask.new(:spec) do |task|
78
task.pattern = 'spec/closure_tree/*_spec.rb'
89
end
910

10-
task default: :spec
11+
task default: [:spec, :test]
1112

1213
namespace :spec do
1314
desc 'Run all spec variants'
@@ -27,6 +28,13 @@ namespace :spec do
2728
end
2829
end
2930

31+
Rake::TestTask.new do |t|
32+
t.libs.push 'lib'
33+
t.libs.push 'test'
34+
t.pattern = 'test/**/*_test.rb'
35+
t.verbose = true
36+
end
37+
3038
require 'github_changelog_generator/task'
3139
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
3240
config.user = 'ClosureTree'

closure_tree.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Gem::Specification.new do |gem|
2727
gem.add_development_dependency 'database_cleaner'
2828
gem.add_development_dependency 'generator_spec'
2929
gem.add_development_dependency 'parallel'
30+
gem.add_development_dependency 'minitest'
31+
gem.add_development_dependency 'minitest-reporters'
3032
gem.add_development_dependency 'rspec-instafail'
3133
gem.add_development_dependency 'rspec-rails'
3234
gem.add_development_dependency 'simplecov'

spec/closure_tree/model_spec.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/closure_tree/model_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
describe '#_ct' do
4+
it 'should delegate to the Support instance on the class' do
5+
assert_equal Tag._ct, Tag.new._ct
6+
end
7+
end

test/test_helper.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
require 'erb'
2+
require 'active_record'
3+
require 'with_advisory_lock'
4+
require 'tmpdir'
5+
require 'securerandom'
6+
require 'minitest'
7+
require 'minitest/autorun'
8+
9+
ActiveRecord::Base.configurations = {
10+
default_env: {
11+
url: ENV.fetch('DATABASE_URL', "sqlite3://#{Dir.tmpdir}/#{SecureRandom.hex}.sqlite3"),
12+
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
13+
}
14+
}
15+
16+
ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex
17+
18+
ActiveRecord::Base.establish_connection
19+
20+
def env_db
21+
@env_db ||= if ActiveRecord::Base.respond_to?(:connection_db_config)
22+
ActiveRecord::Base.connection_db_config.adapter
23+
else
24+
ActiveRecord::Base.connection_config[:adapter]
25+
end.to_sym
26+
end
27+
28+
ActiveRecord::Migration.verbose = false
29+
ActiveRecord::Base.table_name_prefix = ENV['DB_PREFIX'].to_s
30+
ActiveRecord::Base.table_name_suffix = ENV['DB_SUFFIX'].to_s
31+
ActiveRecord::Base.establish_connection
32+
33+
def env_db
34+
@env_db ||= if ActiveRecord::Base.respond_to?(:connection_db_config)
35+
ActiveRecord::Base.connection_db_config.adapter
36+
else
37+
ActiveRecord::Base.connection_config[:adapter]
38+
end.to_sym
39+
end
40+
41+
# Use in specs to skip some tests
42+
def sqlite?
43+
env_db == :sqlite3
44+
end
45+
46+
ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex
47+
48+
ActiveRecord::Base.connection.recreate_database("closure_tree_test") unless sqlite?
49+
puts "Testing with #{env_db} database, ActiveRecord #{ActiveRecord.gem_version} and #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} as #{RUBY_VERSION}"
50+
51+
require 'closure_tree'
52+
require_relative '../spec/support/schema'
53+
require_relative '../spec/support/models'

0 commit comments

Comments
 (0)