Class: RSpecPuppetUtils::MockFunction

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_puppet_utils/mock_function.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) {|_self| ... } ⇒ MockFunction

Returns a new instance of MockFunction.

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
20
21
# File 'lib/rspec_puppet_utils/mock_function.rb', line 16

def initialize(name, options = {})
  parse_options! options
  this = self
  Puppet::Parser::Functions.newfunction(name.to_sym, options) { |args| this.call args }
  yield self if block_given?
end

Instance Method Details

#call(args) ⇒ Object



23
24
25
# File 'lib/rspec_puppet_utils/mock_function.rb', line 23

def call(args)
  execute *args
end

#execute(*args) ⇒ Object



27
28
29
# File 'lib/rspec_puppet_utils/mock_function.rb', line 27

def execute(*args)
  args
end

#expect(*args) ⇒ Object

Use expected instead, see readme



46
47
48
49
# File 'lib/rspec_puppet_utils/mock_function.rb', line 46

def expect(*args)
  RSpec::Puppet::Support.clear_cache unless args.include? :keep_cache
  self.expects(:call)
end

#expected(*args) ⇒ Object



35
36
37
38
# File 'lib/rspec_puppet_utils/mock_function.rb', line 35

def expected(*args)
  RSpec::Puppet::Support.clear_cache unless args.include? :keep_cache
  self.expects(:execute)
end

#stubObject

Use stubbed instead, see readme



41
42
43
# File 'lib/rspec_puppet_utils/mock_function.rb', line 41

def stub
  self.stubs(:call)
end

#stubbedObject



31
32
33
# File 'lib/rspec_puppet_utils/mock_function.rb', line 31

def stubbed
  self.stubs(:execute)
end