Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to minitest #403

Merged
merged 2 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,14 +661,27 @@ end

## Testing

Closure tree is [tested under every valid combination](http://travis-ci.org/#!/ClosureTree/closure_tree) of
Closure tree is [tested under every valid combination](https://github.com/ClosureTree/closure_tree/blob/master/.github/workflows/ci.yml) of

* Ruby 2.7+
* ActiveRecord 6.0+
* PostgreSQL, MySQL, and SQLite. Concurrency tests are only run with MySQL and PostgreSQL.

Assuming you're using [rbenv](https://github.com/sstephenson/rbenv), you can use ```tests.sh``` to
run the test matrix locally.
```shell
$ bundle
$ appraisal bundle # this will install the matrix of dependencies
$ appraisal rake # this will run the tests in all combinations
$ appraisal activerecord-7.0 rake # this will run the tests in AR 7.0 only
$ appraisal activerecord-7.0 rake spec # this will run rspec in AR 7.0 only
$ appraisal activerecord-7.0 rake test # this will run minitest in AR 7.0 only
```

By default the test are run with sqlite3 only.
You run test with other databases by passing the database url as environment variable:

```shell
$ DATABASE_URL=postgres://localhost/my_database appraisal activerecord-7.0 rake test
```

## Change log

Expand Down
10 changes: 9 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rake/testtask'

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

task default: :spec
task default: [:spec, :test]

namespace :spec do
desc 'Run all spec variants'
Expand All @@ -27,6 +28,13 @@ namespace :spec do
end
end

Rake::TestTask.new do |t|
t.libs.push 'lib'
t.libs.push 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

require 'github_changelog_generator/task'
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
config.user = 'ClosureTree'
Expand Down
2 changes: 2 additions & 0 deletions closure_tree.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'database_cleaner'
gem.add_development_dependency 'generator_spec'
gem.add_development_dependency 'parallel'
gem.add_development_dependency 'minitest'
gem.add_development_dependency 'minitest-reporters'
gem.add_development_dependency 'rspec-instafail'
gem.add_development_dependency 'rspec-rails'
gem.add_development_dependency 'simplecov'
Expand Down
9 changes: 0 additions & 9 deletions spec/closure_tree/model_spec.rb

This file was deleted.

7 changes: 7 additions & 0 deletions test/closure_tree/model_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

describe '#_ct' do
it 'should delegate to the Support instance on the class' do
assert_equal Tag._ct, Tag.new._ct
end
end
53 changes: 53 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'erb'
require 'active_record'
require 'with_advisory_lock'
require 'tmpdir'
require 'securerandom'
require 'minitest'
require 'minitest/autorun'

ActiveRecord::Base.configurations = {
default_env: {
url: ENV.fetch('DATABASE_URL', "sqlite3://#{Dir.tmpdir}/#{SecureRandom.hex}.sqlite3"),
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
}
}

ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex

ActiveRecord::Base.establish_connection

def env_db
@env_db ||= if ActiveRecord::Base.respond_to?(:connection_db_config)
ActiveRecord::Base.connection_db_config.adapter
else
ActiveRecord::Base.connection_config[:adapter]
end.to_sym
end

ActiveRecord::Migration.verbose = false
ActiveRecord::Base.table_name_prefix = ENV['DB_PREFIX'].to_s
ActiveRecord::Base.table_name_suffix = ENV['DB_SUFFIX'].to_s
ActiveRecord::Base.establish_connection

def env_db
@env_db ||= if ActiveRecord::Base.respond_to?(:connection_db_config)
ActiveRecord::Base.connection_db_config.adapter
else
ActiveRecord::Base.connection_config[:adapter]
end.to_sym
end

# Use in specs to skip some tests
def sqlite?
env_db == :sqlite3
end

ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex

ActiveRecord::Base.connection.recreate_database("closure_tree_test") unless sqlite?
puts "Testing with #{env_db} database, ActiveRecord #{ActiveRecord.gem_version} and #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} as #{RUBY_VERSION}"

require 'closure_tree'
require_relative '../spec/support/schema'
require_relative '../spec/support/models'