Skip to content

Instantly share code, notes, and snippets.

@e2
Last active May 27, 2019 23:30

Revisions

  1. e2 revised this gist Nov 18, 2014. 1 changed file with 4 additions and 23 deletions.
    27 changes: 4 additions & 23 deletions autorun.rb
    Original file line number Diff line number Diff line change
    @@ -9,33 +9,15 @@
    require 'rspec/matchers'

    RSpec::Core::Runner.disable_autorun!
    RSpec.configure { |c| }
    RSpec.configure do |c|
    c.expect_with :minitest
    end

    module MiniTest
    class Test
    end
    end

    module Assertions
    def __filter_backtrace__(bt)
    bt.reject { |x| x.start_with?("#{__FILE__}:") }
    end

    def assert_equal(expected, actual, message = nil)
    expect(actual).to eq(expected)
    rescue RSpec::Expectations::ExpectationNotMetError => e
    e.set_backtrace(__filter_backtrace__(e.backtrace))
    fail
    end

    def assert(condition, message = nil)
    expect(condition).to be_truthy
    rescue RSpec::Expectations::ExpectationNotMetError => e
    e.set_backtrace(__filter_backtrace__(e.backtrace))
    fail
    end
    end

    at_exit do
    constants = Object.constants.select
    selected = constants.select do |const|
    @@ -53,9 +35,8 @@ def assert(condition, message = nil)
    meths = klass.public_instance_methods.select { |meth| /^test_/ =~ meth }

    group.around do |example|
    klass.include(Assertions)
    klass.include(RSpec::Matchers)
    @__rspec_test_instance = klass.new
    @__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)
  2. e2 revised this gist Nov 17, 2014. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions autorun.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    # HOW TO USE:
    #
    # Given you have a minitest-based test requiring "minitest/autorun"
    # 1) save this to /some_path/lib/minitest/autorun.rb
    # 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
    @@ -18,12 +17,22 @@ class Test
    end

    module Assertions
    def __filter_backtrace__(bt)
    bt.reject { |x| x.start_with?("#{__FILE__}:") }
    end

    def assert_equal(expected, actual, message = nil)
    expect(actual).to eq(expected)
    rescue RSpec::Expectations::ExpectationNotMetError => e
    e.set_backtrace(__filter_backtrace__(e.backtrace))
    fail
    end

    def assert(condition, message = nil)
    expect(condition).to be_truthy
    rescue RSpec::Expectations::ExpectationNotMetError => e
    e.set_backtrace(__filter_backtrace__(e.backtrace))
    fail
    end
    end

  3. e2 revised this gist Nov 17, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion autorun.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    # HOW TO USE:
    #
    # 1) save this to /some_path/lib/minitests/autorun.rb
    # Given you have a minitest-based test requiring "minitest/autorun"
    # 1) save this to /some_path/lib/minitest/autorun.rb
    # 2) run your test with RSpec, e.g.
    #
    # $ RUBYLIB=/some_path/lib rspec -f d test/hello_test.rb
  4. e2 created this gist Nov 17, 2014.
    62 changes: 62 additions & 0 deletions autorun.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    # 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 { |c| }

    module MiniTest
    class Test
    end
    end

    module Assertions
    def assert_equal(expected, actual, message = nil)
    expect(actual).to eq(expected)
    end

    def assert(condition, message = nil)
    expect(condition).to be_truthy
    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(Assertions)
    klass.include(RSpec::Matchers)
    @__rspec_test_instance = klass.new
    @__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