Sha256: f437fc8c6f64a30c505fb3b517893ea8492a09a7e0b0f9171b1aed4a1f5a634c

Contents?: true

Size: 1.43 KB

Versions: 92

Compression:

Stored size: 1.43 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'

describe Puppet::Util::ExecutionStub do
  it "should use the provided stub code when 'set' is called" do
    Puppet::Util::ExecutionStub.set do |command, options|
      command.should == ['/bin/foo', 'bar']
      "stub output"
    end
    Puppet::Util::ExecutionStub.current_value.should_not == nil
    Puppet::Util::Execution.execute(['/bin/foo', 'bar']).should == "stub output"
  end

  it "should automatically restore normal execution at the conclusion of each spec test" do
    # Note: this test relies on the previous test creating a stub.
    Puppet::Util::ExecutionStub.current_value.should == nil
  end

  it "should restore normal execution after 'reset' is called" do
    # Note: "true" exists at different paths in different OSes
    if Puppet.features.microsoft_windows?
      true_command = [Puppet::Util.which('cmd.exe').tr('/', '\\'), '/c', 'exit 0']
    else
      true_command = [Puppet::Util.which('true')]
    end
    stub_call_count = 0
    Puppet::Util::ExecutionStub.set do |command, options|
      command.should == true_command
      stub_call_count += 1
      'stub called'
    end
    Puppet::Util::Execution.execute(true_command).should == 'stub called'
    stub_call_count.should == 1
    Puppet::Util::ExecutionStub.reset
    Puppet::Util::ExecutionStub.current_value.should == nil
    Puppet::Util::Execution.execute(true_command).should == ''
    stub_call_count.should == 1
  end
end

Version data entries

92 entries across 92 versions & 2 rubygems

Version Path
puppet-3.8.7 spec/unit/util/execution_stub_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.6 spec/unit/util/execution_stub_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.5 spec/unit/util/execution_stub_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.4 spec/unit/util/execution_stub_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.3 spec/unit/util/execution_stub_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.2 spec/unit/util/execution_stub_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/util/execution_stub_spec.rb
puppet-3.8.1 spec/unit/util/execution_stub_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/util/execution_stub_spec.rb