From 00e8b1616252a8aee6b8646551946aaa5845baa1 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Thu, 16 Jul 2020 11:03:20 -0700 Subject: add a simple smoke test Signed-off-by: Lamont Granquist --- lib/mixlib/shellout/helper.rb | 3 ++- spec/mixlib/shellout/helper_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 spec/mixlib/shellout/helper_spec.rb diff --git a/lib/mixlib/shellout/helper.rb b/lib/mixlib/shellout/helper.rb index 50ee702..c7091d4 100644 --- a/lib/mixlib/shellout/helper.rb +++ b/lib/mixlib/shellout/helper.rb @@ -16,6 +16,7 @@ # limitations under the License. require_relative "../shellout" +require "chef-utils" require "chef-utils/dsl/path_sanity" require "chef-utils/internal" @@ -153,7 +154,7 @@ module Mixlib end def __shell_out_command(*args, **options) - if __config.target_mode? + if __transport_connection FakeShellOut.new(args, options, __transport_connection.run_command(args.join(" "))) # FIXME: train should accept run_command(*args) else cmd = if options.empty? diff --git a/spec/mixlib/shellout/helper_spec.rb b/spec/mixlib/shellout/helper_spec.rb new file mode 100644 index 0000000..977568a --- /dev/null +++ b/spec/mixlib/shellout/helper_spec.rb @@ -0,0 +1,30 @@ +require "spec_helper" +require "mixlib/shellout/helper" +require "logger" + +describe Mixlib::ShellOut::Helper do + class TestClass + include Mixlib::ShellOut::Helper + + # this is a hash-like object + def __config + {} + end + + # this is a train transport connection or nil + def __transport_connection + nil + end + + # this is a logger-like object + def __log + Logger.new(IO::NULL) + end + end + + let(:test_class) { TestClass.new } + + it "works to run a trivial ruby command" do + expect(test_class.shell_out("ruby -e 'exit 0'")).to be_kind_of(Mixlib::ShellOut) + end +end -- cgit v1.2.1