Class: ChefSpec::Stubs::CommandStub

Inherits:
Stub
  • Object
show all
Defined in:
lib/chefspec/stubs/command_stub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Stub

#and_raise

Constructor Details

#initialize(command, &block) ⇒ CommandStub

Returns a new instance of CommandStub.



10
11
12
13
# File 'lib/chefspec/stubs/command_stub.rb', line 10

def initialize(command, &block)
  @command = command
  @block   = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



6
7
8
# File 'lib/chefspec/stubs/command_stub.rb', line 6

def block
  @block
end

#commandObject (readonly)

Returns the value of attribute command.



7
8
9
# File 'lib/chefspec/stubs/command_stub.rb', line 7

def command
  @command
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/chefspec/stubs/command_stub.rb', line 8

def value
  @value
end

Instance Method Details

#and_return(value) ⇒ Object



15
16
17
18
# File 'lib/chefspec/stubs/command_stub.rb', line 15

def and_return(value)
  @value = value
  self
end

#resultObject



20
21
22
23
24
25
26
# File 'lib/chefspec/stubs/command_stub.rb', line 20

def result
  if @block
    @block.call
  else
    @value
  end
end

#signatureObject



28
29
30
31
32
33
34
# File 'lib/chefspec/stubs/command_stub.rb', line 28

def signature
  if @block
    "stub_command(#{@command.inspect}) { # Ruby code }"
  else
    "stub_command(#{@command.inspect}).and_return(#{@value})"
  end
end