From 819bc84bc7373e22e1c812e4cafbe99a6116e1bd Mon Sep 17 00:00:00 2001 From: "R.I.Pienaar" Date: Mon, 21 Dec 2020 09:52:47 +0100 Subject: [PATCH] (misc) update mocha and rspec Prepare for upgrading rspec to 3 Signed-off-by: R.I.Pienaar --- Gemfile | 4 +-- Rakefile | 2 +- spec/spec_helper.rb | 7 +++-- spec/unit/mcollective/aggregate_spec.rb | 4 +-- spec/unit/mcollective/config_spec.rb | 2 +- .../unit/mcollective/facts/yaml_facts_spec.rb | 4 +-- spec/unit/mcollective/shell_spec.rb | 4 +-- spec/unit/mcollective/util_spec.rb | 27 ++++++++----------- 8 files changed, 24 insertions(+), 30 deletions(-) diff --git a/Gemfile b/Gemfile index 6b835788..4c23fdc9 100755 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,8 @@ source ENV["GEM_SOURCE"] || "https://rubygems.org" gem "systemu", "~> 2.6.4" gem "rdoc" gem "yarjuf", "~> 1.0" -gem "rspec", "~> 2.11.0" -gem "mocha", "~> 0.10.0" +gem "rspec", "~> 2.99.0" +gem "mocha", "~> 0.12.2" gem "mcollective-test" gem "rake", "< 11.0" gem "rubocop", "1.6.1" diff --git a/Rakefile b/Rakefile index 0b2342b0..dee76f09 100644 --- a/Rakefile +++ b/Rakefile @@ -29,5 +29,5 @@ end desc "Run spec tests" task :test do sh "bundle exec rubocop --config .rubocop.yml lib" - sh "bundle exec rspec --colour --backtrace" + sh "bundle exec rspec" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e5e10e52..18b5f156 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,8 +4,6 @@ require 'rspec' require 'mcollective' -require 'rspec/mocks' -require 'mocha' require 'ostruct' require 'tmpdir' require 'tempfile' @@ -15,10 +13,11 @@ require 'monkey_patches/instance_variable_defined' RSpec.configure do |config| - config.mock_with :mocha + config.mock_with(:mocha) + config.mock_framework = :mocha config.include(MCollective::Test::Matchers) - config.before :each do + config.before :each do |example| MCollective::Config.instance.set_config_defaults("") MCollective::PluginManager.clear end diff --git a/spec/unit/mcollective/aggregate_spec.rb b/spec/unit/mcollective/aggregate_spec.rb index 633b8ad8..711d18b5 100644 --- a/spec/unit/mcollective/aggregate_spec.rb +++ b/spec/unit/mcollective/aggregate_spec.rb @@ -61,7 +61,7 @@ module MCollective end describe '#contains_ouput?' do - before :all do + before :each do Aggregate.any_instance.stubs(:create_functions) @aggregate = Aggregate.new(ddl) end @@ -148,7 +148,7 @@ module MCollective end describe '#load_function' do - before :all do + before :each do Aggregate.any_instance.stubs(:create_functions) @aggregate = Aggregate.new(ddl) end diff --git a/spec/unit/mcollective/config_spec.rb b/spec/unit/mcollective/config_spec.rb index 49b00ca5..a644e0f0 100755 --- a/spec/unit/mcollective/config_spec.rb +++ b/spec/unit/mcollective/config_spec.rb @@ -161,7 +161,7 @@ module MCollective it "should skip files that do not match the expected filename pattern" do Dir.expects(:new).with(@plugindir).returns(["foo.txt"]) - IO.expects(:open).with(File.join(@plugindir, "foo.txt")).never + File.expects(:open).with(File.join(@plugindir, "foo.txt")).never Config.instance.read_plugin_config_dir(@plugindir) end diff --git a/spec/unit/mcollective/facts/yaml_facts_spec.rb b/spec/unit/mcollective/facts/yaml_facts_spec.rb index 6e7e9765..f2ad9eb3 100644 --- a/spec/unit/mcollective/facts/yaml_facts_spec.rb +++ b/spec/unit/mcollective/facts/yaml_facts_spec.rb @@ -51,13 +51,13 @@ module Facts it 'should return true if the mtime has changed' do @facts.instance_variable_get(:@yaml_file_mtimes)['facts.yaml'] = 1234 @stat.stubs(:mtime).returns(1235) - @facts.force_reload?.should be_true + @facts.force_reload?.should be_truthy end it 'should return false if the mtime is the same' do @facts.instance_variable_get(:@yaml_file_mtimes)['facts.yaml'] = 1234 @stat.stubs(:mtime).returns(1234) - @facts.force_reload?.should be_false + @facts.force_reload?.should be_falsey end end end diff --git a/spec/unit/mcollective/shell_spec.rb b/spec/unit/mcollective/shell_spec.rb index b33b70c3..5bec14f7 100755 --- a/spec/unit/mcollective/shell_spec.rb +++ b/spec/unit/mcollective/shell_spec.rb @@ -93,8 +93,8 @@ module MCollective end it "should run the command" do - Shell.any_instance.stubs("systemu").returns(@systemu).once.with("date", "stdout" => '', "stderr" => '', "env" => {"LC_ALL" => "C"}, 'cwd' => Dir.tmpdir) s = Shell.new("date") + s.stubs("systemu").returns(@systemu).once.with("date", "stdout" => '', "stderr" => '', "env" => {"LC_ALL" => "C"}, 'cwd' => Dir.tmpdir) s.runcommand end @@ -164,7 +164,7 @@ module MCollective it "should quietly catch Errno::ESRCH if the systemu process has completed" do s = Shell.new("echo foo") - Thread.any_instance.stubs(:alive?).raises(Errno::ESRCH) + Thread.current.stubs(:alive?).raises(Errno::ESRCH) s.runcommand end diff --git a/spec/unit/mcollective/util_spec.rb b/spec/unit/mcollective/util_spec.rb index 5bc34ec6..1d6f7e9b 100755 --- a/spec/unit/mcollective/util_spec.rb +++ b/spec/unit/mcollective/util_spec.rb @@ -57,18 +57,13 @@ module MCollective end it "should support regular expression searches" do - File.stubs(:readlines).returns(["test_class_test"]) - String.any_instance.expects(:start_with?).with("/").returns(true) - String.any_instance.expects(:match).with(Regexp.new("class")).returns(true) - + tc = "test_class_test" + File.stubs(:readlines).returns([tc]) Util.has_cf_class?("/class/").should == true end it "should support exact string matches" do File.stubs(:readlines).returns(["test_class_test"]) - String.any_instance.expects(:start_with?).with("/").returns(false) - String.any_instance.expects(:match).with(Regexp.new("test_class_test")).never - Util.has_cf_class?("test_class_test").should == true end @@ -141,14 +136,14 @@ module MCollective subs1 = {:agent => "test_agent", :type => "test_type", :collective => "test_collective"} subs2 = {:agent => "test_agent2", :type => "test_type2", :collective => "test_collective2"} - MCollective::Connector::Stomp.any_instance.expects(:subscribe).with("test_agent", "test_type", "test_collective").once - MCollective::Connector::Stomp.any_instance.expects(:subscribe).with("test_agent2", "test_type2", "test_collective2").once + MCollective::PluginManager["connector_plugin"].expects(:subscribe).with("test_agent", "test_type", "test_collective").once + MCollective::PluginManager["connector_plugin"].expects(:subscribe).with("test_agent2", "test_type2", "test_collective2").once Util.subscribe([subs1, subs2]) end it "should subscribe to a single topic given a hash" do - MCollective::Connector::Stomp.any_instance.expects(:subscribe).with("test_agent", "test_type", "test_collective").once + MCollective::PluginManager["connector_plugin"].expects(:subscribe).with("test_agent", "test_type", "test_collective").once Util.subscribe({:agent => "test_agent", :type => "test_type", :collective => "test_collective"}) end end @@ -157,14 +152,14 @@ module MCollective it "should unsubscribe to multiple topics given an Array" do subs1 = {:agent => "test_agent", :type => "test_type", :collective => "test_collective"} subs2 = {:agent => "test_agent2", :type => "test_type2", :collective => "test_collective2"} - MCollective::Connector::Stomp.any_instance.expects(:unsubscribe).with("test_agent", "test_type", "test_collective").once - MCollective::Connector::Stomp.any_instance.expects(:unsubscribe).with("test_agent2", "test_type2", "test_collective2").once + MCollective::PluginManager["connector_plugin"].expects(:unsubscribe).with("test_agent", "test_type", "test_collective").once + MCollective::PluginManager["connector_plugin"].expects(:unsubscribe).with("test_agent2", "test_type2", "test_collective2").once Util.unsubscribe([subs1, subs2]) end it "should subscribe to a single topic given a hash" do - MCollective::Connector::Stomp.any_instance.expects(:unsubscribe).with("test_agent", "test_type", "test_collective").once + MCollective::PluginManager["connector_plugin"].expects(:unsubscribe).with("test_agent", "test_type", "test_collective").once Util.unsubscribe({:agent => "test_agent", :type => "test_type", :collective => "test_collective"}) end end @@ -667,7 +662,7 @@ module MCollective it "should correctly validate paths on Windows" do ['C:\foo', '\foo\bar', '\C\FOO\Bar', '/C/FOO/Bar'].each do |path| - Util.absolute_path?(path, '/', '\\').should be_true + Util.absolute_path?(path, '/', '\\').should be_truthy end end end @@ -685,13 +680,13 @@ module MCollective describe "str_to_bool" do it "should transform true like strings into TrueClass" do ["1", "y", "yes", "Y", "YES", "t", "true", "T", "TRUE", true].each do |val| - Util.str_to_bool(val).should be_true + Util.str_to_bool(val).should be_truthy end end it "should transform false like strings into FalseClass" do ["0", "n", "no", "N", "NO", "f", "false", "F", "FALSE", false].each do |val| - Util.str_to_bool(val).should be_false + Util.str_to_bool(val).should be_falsey end end