Fix test framework contention.

RSpec is used internally. Minitest is used for our tests. They don't
really like each other. This fixes that and gets our tests
consistently running the correct number of tests (they were load-order
dependent before and each platform had its own different number of
tests it would run).

Signed-off-by: Ryan Davis <zenspider@chef.io>
This commit is contained in:
Ryan Davis 2019-05-15 00:20:27 -07:00
parent fa7a8c9e19
commit eead889325
2 changed files with 60 additions and 1 deletions

View file

@ -23,3 +23,4 @@ require 'minitest/spec'
require 'minitest/autorun'
# You might want to put some debugging tools here. We run tests to find bugs, after all.
# require 'byebug'

View file

@ -1,6 +1,13 @@
# author: Dominik Richter
# author: Christoph Hartmann
##
# Do not add any code above this line.
##
# Do not add any other code to this code block. Simplecov and
# coveralls only until the next code block:
require 'simplecov'
require 'coveralls'
@ -16,7 +23,58 @@ SimpleCov.start do
add_group 'Backends', 'lib/inspec/backend'
end
require 'minitest/autorun'
##
#
# Do not add any other code from here until the end of this code
# block.
#
# Before ANYTHING else happens, this must happen:
#
# 1) require minitest/autorun
# 2) alias describe to mt_describe
# 3) require rspec
# 4) disable_monkey_patching from rspec
# 5) alias mt_describe back to describe using change_global_dsl.
#
# Explanation: eventually, our tests get around to inspec/runner_rspec
# (and a few others), and they load rspec. When rspec loads, it
# creates it's own global `describe` method, overwriting minitest's.
# When you tell RSpec to disable_monkey_patching, instead of using
# remove_method, they use undef_method, which blocks access to our
# Kernel.describe. We then need to go back in and reactivate it in
# order for our tests to finish declaring their tests and eventually
# actually running.
#
# Before this, the tests would get to the point of loading rspec, then
# all subsequently loaded spec-style tests would just disappear into
# the aether. Differences in test load order created differences in
# test count and vast differences in test time (which should have been
# a clue that something was up--windows is just NOT THAT FAST).
#
# The OTHER way to fix this is to ban spec style tests in our
# codebase. This is a more rational approach but requires more work. I
# need these tests up and all running and dependable. We can make them
# right later.
require "minitest/autorun"
module Kernel
alias mt_describe describe
end
require "rspec"
RSpec.configure do |config|
config.disable_monkey_patching!
end
RSpec::Core::DSL.change_global_dsl do
alias describe mt_describe
end
# End of rspec vs minitest fight
########################################################################
require 'webmock/minitest'
require 'mocha/setup'
require 'fileutils'