Module: ChefSpec::API::StubsFor::ClassMethods

Included in:
ChefSpec::API::StubsFor
Defined in:
lib/chefspec/api/stubs_for.rb

Instance Method Summary collapse

Instance Method Details

#included(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



128
129
130
131
132
# File 'lib/chefspec/api/stubs_for.rb', line 128

def included(klass)
  super
  # Inject classmethods into the group.
  klass.extend(ClassMethods)
end

#stubs_for_current_value(*args, &block) ⇒ void Also known as: stubs_for_current_resource

This method returns an undefined value.

Register stubs for current_value objects.

Parameters:

  • target (String, nil)

    Resource name to inject, or nil for all resources.

  • block (Proc)

    A block taking the resource object as a parameter.

See Also:



117
118
119
# File 'lib/chefspec/api/stubs_for.rb', line 117

def stubs_for_current_value(*args, &block)
  before { stubs_for_current_value(*args, &block) }
end

#stubs_for_provider(*args, &block) ⇒ void

This method returns an undefined value.

Register stubs for provider objects.

Parameters:

  • target (String, nil)

    Resource name to inject, or nil for all providers.

  • block (Proc)

    A block taking the resource object as a parameter.

See Also:



123
124
125
# File 'lib/chefspec/api/stubs_for.rb', line 123

def stubs_for_provider(*args, &block)
  before { stubs_for_provider(*args, &block) }
end

#stubs_for_resource(*args, **kwargs, &block) ⇒ void

This method returns an undefined value.

Register stubs for resource objects.

The ‘target` parameter can select either a resource string like `’package’‘, a resource name like `’package’‘, or `nil` for all resources.

Examples:

Setting method stub on a single resource

it "does a thing" do
  stubs_for_resource("my_resource[foo]") do |res|
    expect(res).to receive_shell_out.with("my_command").and_return(stdout: "asdf")
  end
  expect(subject.some_method).to eq "asdf"
end

Parameters:

  • target (String, nil)

    Resource name to inject, or nil for all resources.

  • current_value (Boolean)

    If true, also register stubs for current_value objects on the same target.

  • block (Proc)

    A block taking the resource object as a parameter.



112
113
114
# File 'lib/chefspec/api/stubs_for.rb', line 112

def stubs_for_resource(*args, **kwargs, &block)
  before { stubs_for_resource(*args, **kwargs, &block) }
end