summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-01-04 11:28:02 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2019-01-04 11:28:02 -0800
commit6d938b76ec4e73cb97cf7a65daa21a6d708ed84a (patch)
tree11c1457cb1e3a467e23cb971f1a788f11bba4fb2 /spec
parente38d58daeb39db79a13fc5d7c9bd9a8d0b20bccf (diff)
downloadmixlib-cli-6d938b76ec4e73cb97cf7a65daa21a6d708ed84a.tar.gz
fix global state pollution issues across examples
since classes are global state, having a single TestCLI class that threads through all the examples creates state pollution that can cause ordering problems. solve this by rewiring TestCLI to a new class every single time. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/cli_spec.rb2
-rw-r--r--spec/spec_helper.rb12
2 files changed, 9 insertions, 5 deletions
diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb
index ed890b5..8c77703 100644
--- a/spec/mixlib/cli_spec.rb
+++ b/spec/mixlib/cli_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 6f3d7e2..ffbde8a 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -3,10 +3,6 @@ $:.push File.join(File.dirname(__FILE__), "..", "lib")
require "mixlib/cli"
-class TestCLI
- include Mixlib::CLI
-end
-
RSpec.configure do |config|
# Use documentation format
config.formatter = "doc"
@@ -23,4 +19,12 @@ RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.warnings = true
+
+ config.before(:each) do
+ # create a fresh TestCLI class on every example, so that examples never
+ # pollute global variables and create ordering issues
+ Object.send(:remove_const, "TestCLI") if Object.const_defined?("TestCLI")
+ TestCLI = Class.new
+ TestCLI.send(:include, Mixlib::CLI)
+ end
end