Skip to content

Instantly share code, notes, and snippets.

@e2
Last active May 27, 2019 23:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save e2/bcd2be81b4ac28c85ea0 to your computer and use it in GitHub Desktop.
Save e2/bcd2be81b4ac28c85ea0 to your computer and use it in GitHub Desktop.
# HOW TO USE:
#
# 1) save this to /some_path/lib/minitests/autorun.rb
# 2) run your test with RSpec, e.g.
#
# $ RUBYLIB=/some_path/lib rspec -f d test/hello_test.rb
require 'rspec/core'
require 'rspec/matchers'
RSpec::Core::Runner.disable_autorun!
RSpec.configure do |c|
c.expect_with :minitest
end
module MiniTest
class Test
end
end
at_exit do
constants = Object.constants.select
selected = constants.select do |const|
next unless const =~ /Test$/
klass = Object.const_get(const)
next unless klass.respond_to?(:superclass)
klass.superclass == MiniTest::Test
end
klasses = selected.map { |name| Object.const_get(name) }
klasses.each do |klass|
group = RSpec.describe(klass)
meths = klass.public_instance_methods.select { |meth| /^test_/ =~ meth }
group.around do |example|
klass.include(RSpec::Matchers)
@__rspec_test_instance = klass.new(klass.to_s)
@__rspec_test_instance.setup if @instance.respond_to?(:setup)
example.run
@__rspec_test_instance.teardown if @instance.respond_to?(:teardown)
end
meths.each do |meth|
group.it(meth.to_s[/^test_(.*)/,1].tr('_',' ')) do |example|
@__rspec_test_instance.method(meth).call
end
end
end
RSpec::Core::Runner.run([])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment