Skip to content

Commit

Permalink
(misc) update mocha and rspec
Browse files Browse the repository at this point in the history
Prepare for upgrading rspec to 3

Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed Dec 21, 2020
1 parent ee6c7a3 commit 819bc84
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 3 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

require 'rspec'
require 'mcollective'
require 'rspec/mocks'
require 'mocha'
require 'ostruct'
require 'tmpdir'
require 'tempfile'
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/mcollective/aggregate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/mcollective/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/mcollective/facts/yaml_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/mcollective/shell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
27 changes: 11 additions & 16 deletions spec/unit/mcollective/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 819bc84

Please sign in to comment.