Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Forked from e2/autorun.rb
Created May 18, 2015 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/f114eb2f0a36d3c9bcf0 to your computer and use it in GitHub Desktop.
Save JoshCheek/f114eb2f0a36d3c9bcf0 to your computer and use it in GitHub Desktop.
require 'rspec/autorun'
gem 'minitest', '~> 5.6' # might work w/ older vers, I didn't check
require 'minitest'
class WhateverTest < Minitest::Test
def setup
@setup_value = true
end
def test_it_passes
assert @setup_value
end
def test_it_fails
refute @setup_value, 'minitest custom failure message'
end
def test_it_errors
raise 'Minitest: this is an error'
end
def test_it_is_skipped
skip
assert false # won't be hit
end
def it_is_not_considered_to_be_a_test
raise "should not have been called"
end
end
RSpec.describe 'also runs specs' do
it 'passes' do
expect(true).to eq true
end
it 'fails' do
expect(true).to eq(false), 'RSpec custom failure message'
end
it 'errors' do
raise 'RSpec: this is an error'
end
def test_this_is_a_helper_that_is_not_run
raise 'should not have been run'
end
end
at_exit do
first_line = __LINE__.pred
Minitest.load_plugins
minitest_options = Minitest.process_args([])
Minitest.init_plugins minitest_options
Minitest::Runnable.runnables.each do |klass|
RSpec.describe klass do
klass.runnable_methods.each do |meth|
example meth.to_s.sub(/^test_/, '').tr('_', ' ') do
instance = Minitest.run_one_method klass, meth
next if instance.passed?
pending 'skipped' if instance.skipped?
raise instance.failure
end
end
end
end
RSpec.configure do |c|
c.filter_gems_from_backtrace 'minitest'
linenums = (first_line..__LINE__+3).to_a
c.backtrace_exclusion_patterns << Regexp.new("#{__FILE__}:(?:#{linenums.join '|'})")
end
end
# >>
# >> also runs specs
# >> passes
# >> fails (FAILED - 1)
# >> errors (FAILED - 2)
# >>
# >> WhateverTest
# >> it errors (FAILED - 3)
# >> it passes
# >> it is skipped (PENDING: skipped)
# >> it fails (FAILED - 4)
# >>
# >> Pending: (Failures listed here are expected and do not affect your suite's status)
# >>
# >> 1) WhateverTest it is skipped
# >> # skipped
# >> Failure/Error: skip
# >> Minitest::Skip:
# >> Skipped, no message given
# >> # /var/folders/7g/mbft22555w3_2nqs_h1kbglw0000gn/T/seeing_is_believing_temp_dir20150518-23994-10rbkx8/program.rb:23:in `test_it_is_skipped'
# >>
# >> Failures:
# >>
# >> 1) also runs specs fails
# >> Failure/Error: expect(true).to eq(false), 'RSpec custom failure message'
# >> RSpec custom failure message
# >> # /var/folders/7g/mbft22555w3_2nqs_h1kbglw0000gn/T/seeing_is_believing_temp_dir20150518-23994-10rbkx8/program.rb:38:in `block (2 levels) in <main>'
# >>
# >> 2) also runs specs errors
# >> Failure/Error: raise 'RSpec: this is an error'
# >> RuntimeError:
# >> RSpec: this is an error
# >> # /var/folders/7g/mbft22555w3_2nqs_h1kbglw0000gn/T/seeing_is_believing_temp_dir20150518-23994-10rbkx8/program.rb:42:in `block (2 levels) in <main>'
# >>
# >> 3) WhateverTest it errors
# >> Failure/Error: raise 'Minitest: this is an error'
# >> RuntimeError:
# >> Minitest: this is an error
# >> # /var/folders/7g/mbft22555w3_2nqs_h1kbglw0000gn/T/seeing_is_believing_temp_dir20150518-23994-10rbkx8/program.rb:19:in `test_it_errors'
# >>
# >> 4) WhateverTest it fails
# >> Failure/Error: refute @setup_value, 'minitest custom failure message'
# >> Minitest::Assertion:
# >> minitest custom failure message
# >> # /var/folders/7g/mbft22555w3_2nqs_h1kbglw0000gn/T/seeing_is_believing_temp_dir20150518-23994-10rbkx8/program.rb:15:in `test_it_fails'
# >>
# >> Finished in 0.00184 seconds (files took 0.18893 seconds to load)
# >> 7 examples, 4 failures, 1 pending
# >>
# >> Failed examples:
# >>
# >> rspec # also runs specs fails
# >> rspec # also runs specs errors
# >> rspec # WhateverTest it errors
# >> rspec # WhateverTest it fails
# >>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment