summaryrefslogtreecommitdiffstats
path: root/spec/unit/util/execution_stub_spec.rb
blob: 9cd15ca6a32b73118aa72e1483824d558ca442e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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", :fails_on_windows => true do
    true_command = Puppet::Util.which('true') # Note: "true" exists at different paths in different OSes
    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