module ChefSpec::API::Stubs

def stub_command(command, &block)

Returns:
  • (ChefSpec::CommandStub) -

Parameters:
  • command (String, Regexp) --

Other tags:
    Example: stubbing a command that raises an exception -
    Example: stubbing a command that matches a pattern -
    Example: stubbing a block that is evaluated at runtime -
    Example: stubbing a command to return true -
def stub_command(command, &block)
  ChefSpec::Stubs::CommandRegistry.register(ChefSpec::Stubs::CommandStub.new(command, &block))
end

def stub_data_bag(bag, &block)

Returns:
  • (ChefSpec::DataBagStub) -

Parameters:
  • bag (String, Symbol) --

Other tags:
    Example: stubbing a data_bag to raise an exception -
    Example: stubbing a data_bag to return an Array of Hashes -
    Example: stubbing a data_bag with a block that is evaluated at runtime -
    Example: stubbing a data_bag to return an empty Array -
def stub_data_bag(bag, &block)
  ChefSpec::Stubs::DataBagRegistry.register(ChefSpec::Stubs::DataBagStub.new(bag, &block))
end

def stub_data_bag_item(bag, id, &block)

Returns:
  • (ChefSpec::DataBagItemStub) -

Parameters:
  • id (String) --
  • bag (String, Symbol) --

Other tags:
    Example: stubbing a data_bag_item to raise an exception -
    Example: stubbing a data_bag_item with a block that is evaluated at runtime -
    Example: stubbing a data_bag_item to return a Hash of data -
def stub_data_bag_item(bag, id, &block)
  ChefSpec::Stubs::DataBagItemRegistry.register(ChefSpec::Stubs::DataBagItemStub.new(bag, id, &block))
end

def stub_node(*args, &block)

Returns:
  • (Chef::Node) -

Options Hash: (**options)
  • :ohai (Hash) --
  • :path (Symbol) --
  • :version (Symbol) --
  • :platform (Symbol) --

Parameters:
  • options (Hash) --
  • name (String) --

Other tags:
    Example: setting specific attributes -
    Example: stubbing a node based on a JSON fixture -
    Example: overriding a specific ohai attribute -
    Example: mocking a specific platform and version -
    Example: mocking a simple node -
def stub_node(*args, &block)
  options = args.last.is_a?(Hash) ? args.pop : {}
  name    = args.first || "node.example"
  fauxhai = Fauxhai.mock(options).data
  fauxhai = fauxhai.merge(options[:ohai] || {})
  fauxhai = Mash.new(fauxhai)
  node = Chef::Node.new
  node.name(name)
  node.automatic_attrs = fauxhai
  node.instance_eval(&block) if block_given?
  node
end

def stub_search(type, query = "*:*", &block)

Returns:
  • (ChefSpec::SearchStub) -

Parameters:
  • query (String, Symbol, nil) --
  • type (String, Symbol) --

Other tags:
    Example: stubbing a search to raise an exception -
    Example: stubbing a search to return a fixed value -
    Example: stubbing a search with a block that is evaluated at runtime -
    Example: stubbing a search with a query as a regex -
    Example: stubbing a search with a query -
    Example: stubbing a search to return nothing -
def stub_search(type, query = "*:*", &block)
  ChefSpec::Stubs::SearchRegistry.register(ChefSpec::Stubs::SearchStub.new(type, query, &block))
end