Sha256: 55d88d9e5ee7aa277e3f87c5f6dbe8ae6f1bef9cf8b25b79ac383976be8e5067

Contents?: true

Size: 1.39 KB

Versions: 29

Compression:

Stored size: 1.39 KB

Contents

#!/usr/bin/env rspec
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.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.execute(true_command).should == 'stub called'
    stub_call_count.should == 1
    Puppet::Util::ExecutionStub.reset
    Puppet::Util::ExecutionStub.current_value.should == nil
    Puppet::Util.execute(true_command).should == ''
    stub_call_count.should == 1
  end
end

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
puppet-2.7.26 spec/unit/util/execution_stub_spec.rb
puppet-2.7.25 spec/unit/util/execution_stub_spec.rb
puppet-2.7.24 spec/unit/util/execution_stub_spec.rb
puppet-2.7.23 spec/unit/util/execution_stub_spec.rb
puppet-2.7.22 spec/unit/util/execution_stub_spec.rb
puppet-2.7.21 spec/unit/util/execution_stub_spec.rb
puppet-2.7.20 spec/unit/util/execution_stub_spec.rb
puppet-2.7.20.rc1 spec/unit/util/execution_stub_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/util/execution_stub_spec.rb
puppet-2.7.19 spec/unit/util/execution_stub_spec.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/execution_stub_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/util/execution_stub_spec.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/execution_stub_spec.rb
puppet-2.7.18 spec/unit/util/execution_stub_spec.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/execution_stub_spec.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/execution_stub_spec.rb
puppet-2.7.17 spec/unit/util/execution_stub_spec.rb
puppet-2.7.16 spec/unit/util/execution_stub_spec.rb
puppet-2.7.14 spec/unit/util/execution_stub_spec.rb
puppet-2.7.13 spec/unit/util/execution_stub_spec.rb