Class: ChefSpec::Stubs::CommandStub
- Defined in:
- lib/chefspec/stubs/command_stub.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #and_return(value) ⇒ Object
-
#initialize(command, &block) ⇒ CommandStub
constructor
A new instance of CommandStub.
- #result ⇒ Object
- #signature ⇒ Object
Methods inherited from Stub
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
#block ⇒ Object (readonly)
Returns the value of attribute block.
6 7 8 |
# File 'lib/chefspec/stubs/command_stub.rb', line 6 def block @block end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
7 8 9 |
# File 'lib/chefspec/stubs/command_stub.rb', line 7 def command @command end |
#value ⇒ Object (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 |
#result ⇒ Object
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 |
#signature ⇒ Object
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 |