Skip to content

Commit

Permalink
Switch to Minitest
Browse files Browse the repository at this point in the history
  • Loading branch information
paracycle committed Jun 9, 2020
1 parent 82c45a5 commit a49bc4e
Show file tree
Hide file tree
Showing 21 changed files with 2,229 additions and 2,221 deletions.
10 changes: 9 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ gemspec
gem 'rubocop-shopify', require: false

group(:deployment, :development) do
gem("rake", "~> 12.3")
gem("rake")
end

gem("bundler", "~> 1.17")
gem("pry-byebug")
gem("minitest")
gem("minitest-hooks")
gem("minitest-fork_executor")
gem("minitest-reporters")
gem("sorbet")

group(:development, :test) do
gem("smart_properties", ">= 1.15.0", require: false)
gem("frozen_record", ">= 0.17", require: false)
Expand Down
33 changes: 16 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
ansi (1.5.0)
arel (9.0.0)
ast (2.4.0)
builder (3.2.4)
Expand All @@ -63,7 +64,6 @@ GEM
highline (~> 2.0.0)
concurrent-ruby (1.1.6)
crass (1.0.6)
diff-lcs (1.3)
erubi (1.9.0)
frozen_record (0.17.0)
activemodel
Expand All @@ -85,6 +85,15 @@ GEM
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.1)
minitest-fork_executor (1.0.1)
minitest
minitest-hooks (1.5.0)
minitest (> 5.3)
minitest-reporters (1.4.2)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
nio4r (2.5.2)
nokogiri (1.10.9)
mini_portile2 (~> 2.4.0)
Expand Down Expand Up @@ -130,20 +139,7 @@ GEM
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rainbow (3.0.0)
rake (12.3.2)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rake (13.0.1)
rubocop (0.78.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
Expand Down Expand Up @@ -183,10 +179,13 @@ DEPENDENCIES
activerecord-typedstore (~> 1.3)
bundler (~> 1.17)
frozen_record (>= 0.17)
minitest
minitest-fork_executor
minitest-hooks
minitest-reporters
pry-byebug
rails (~> 5.2)
rake (~> 12.3)
rspec
rake
rubocop-shopify
smart_properties (>= 1.15.0)
sorbet
Expand Down
19 changes: 15 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
require "bundler/gem_tasks"
require "rake/testtask"

begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
rescue LoadError # rubocop:disable Lint/SuppressedException
Rake.application.options.trace = false

Rake::TestTask.new do |t|
t.libs << "lib"
t.libs << "spec"
t.warning = false
t.test_files = FileList['spec/**/*_spec.rb']
end

task(:spec) do
begin
Rake::Task[:test].execute
rescue RuntimeError
exit(1)
end
end

task(default: :spec)
2 changes: 1 addition & 1 deletion bin/test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
bundle exec rspec "$@"
bundle exec rake "$@"
7 changes: 0 additions & 7 deletions lib/tapioca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,4 @@ class Error < StandardError; end
require "tapioca/compilers/symbol_table/symbol_loader"
require "tapioca/compilers/todos_compiler"
require "tapioca/compilers/dsl/base"
require "tapioca/compilers/dsl/smart_properties"
require "tapioca/compilers/dsl/frozen_record"
require "tapioca/compilers/dsl/action_mailer"
require "tapioca/compilers/dsl/state_machines"
require "tapioca/compilers/dsl/action_controller_helpers"
require "tapioca/compilers/dsl/active_support_current_attributes"
require "tapioca/compilers/dsl/active_record_typed_store"
require "tapioca/version"
29 changes: 29 additions & 0 deletions spec/content_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module ContentHelper
def with_contents(contents, requires: [contents.keys.first], &block)
Dir.mktmpdir do |path|
dir = Pathname.new(path)
# Create a "lib" folder
Dir.mkdir(dir.join("lib"))

contents.each do |file, content|
# Add our contents into their files in lib folder
File.write(dir.join("lib/#{file}"), content)
end

Tapioca.silence_warnings do
# Require files
requires.each do |file|
require(dir.join("lib/#{file}"))
end

block.call(dir)
end
end
end

def with_content(content, &block)
with_contents({ "file.rb" => content }, &block)
end
end
112 changes: 16 additions & 96 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,101 +2,21 @@
# frozen_string_literal: true

require "tapioca"
require "rubocop/rspec/support"

RSpec.configure do |config|
config.include(RuboCop::RSpec::ExpectOffense)

config.expect_with(:rspec) do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

config.mock_with(:rspec) do |mocks|
mocks.verify_partial_doubles = true
end

config.shared_context_metadata_behavior = :apply_to_host_groups
config.filter_run_when_matching(:focus)
config.example_status_persistence_file_path = "spec/examples.txt"
config.disable_monkey_patching!
config.warnings = true
config.order = :defined
Kernel.srand(config.seed)

if config.files_to_run.one?
config.default_formatter = "doc"
end
end

def run_in_child
read, write = IO.pipe

pid = fork do
Tapioca.silence_warnings do
read.close
result = yield
write.puts(result)
end
end

write.close
Process.wait(pid)
read.read
ensure
read&.close
end

def with_contents(contents, requires: [contents.keys.first], &block)
Dir.mktmpdir do |path|
dir = Pathname.new(path)
# Create a "lib" folder
Dir.mkdir(dir.join("lib"))

contents.each do |file, content|
# Add our contents into their files in lib folder
File.write(dir.join("lib/#{file}"), content)
end

result = run_in_child do
# Require files
requires.each do |file|
require(dir.join("lib/#{file}"))
end

block.call(dir).to_yaml
end

YAML.load(result)
end
end

def with_content(content, &block)
with_contents({ "file.rb" => content }, &block)
end

module RSpec
module Matchers
class Binding
def ruby_version(selector)
Gem::Requirement.new(selector).satisfied_by?(Gem::Version.new(RUBY_VERSION))
end

def erb_bindings
binding
end
end

ERB_SUPPORTS_KVARGS = ::ERB.instance_method(:initialize).parameters.assoc(:key)
private_constant :ERB_SUPPORTS_KVARGS

def template(src)
erb = if ERB_SUPPORTS_KVARGS
::ERB.new(src, trim_mode: ">")
else
::ERB.new(src, nil, ">")
end

erb.result(Binding.new.erb_bindings)
end
require "minitest/autorun"
require "minitest/spec"
require "minitest/hooks/default"
require "minitest/fork_executor"
require "minitest/reporters"

require "content_helper"
require "template_helper"

Minitest::Reporters.use!(Minitest::Reporters::DefaultReporter.new(color: true))
Minitest.parallel_executor = Minitest::ForkExecutor.new

module Minitest
class Test
include ContentHelper
include TemplateHelper
end
end
Loading

0 comments on commit a49bc4e

Please sign in to comment.