Class: ChefSpec::Stubs::DataBagStub

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

Instance Attribute Summary collapse

Attributes inherited from Stub

#value

Instance Method Summary collapse

Methods inherited from Stub

#and_raise, #and_return, #result

Constructor Details

#initialize(bag, &block) ⇒ DataBagStub

Returns a new instance of DataBagStub.



9
10
11
12
# File 'lib/chefspec/stubs/data_bag_stub.rb', line 9

def initialize(bag, &block)
  @bag   = bag.to_s
  @block = block
end

Instance Attribute Details

#bagObject (readonly)

Returns the value of attribute bag.



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

def bag
  @bag
end

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

Instance Method Details

#signatureObject



14
15
16
17
18
19
20
# File 'lib/chefspec/stubs/data_bag_stub.rb', line 14

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