Module: ChefSpec

Defined in:
lib/chefspec/chef_backwards_compat.rb,
lib/chefspec.rb,
lib/chefspec/api.rb,
lib/chefspec/util.rb,
lib/chefspec/errors.rb,
lib/chefspec/macros.rb,
lib/chefspec/cacher.rb,
lib/chefspec/version.rb,
lib/chefspec/matchers.rb,
lib/chefspec/coverage.rb,
lib/chefspec/renderer.rb,
lib/chefspec/formatter.rb,
lib/chefspec/librarian.rb,
lib/chefspec/berkshelf.rb,
lib/chefspec/stubs/stub.rb,
lib/chefspec/solo_runner.rb,
lib/chefspec/deprecations.rb,
lib/chefspec/server_runner.rb,
lib/chefspec/stubs/registry.rb,
lib/chefspec/server_methods.rb,
lib/chefspec/mixins/normalize.rb,
lib/chefspec/coverage/filters.rb,
lib/chefspec/stubs/search_stub.rb,
lib/chefspec/stubs/command_stub.rb,
lib/chefspec/stubs/data_bag_stub.rb,
lib/chefspec/stubs/search_registry.rb,
lib/chefspec/stubs/command_registry.rb,
lib/chefspec/stubs/data_bag_registry.rb,
lib/chefspec/stubs/data_bag_item_stub.rb,
lib/chefspec/stubs/data_bag_item_registry.rb,
lib/chefspec/expect_exception.rb

Overview

This file contains the backwards compatible hacks required to make ChefSpec work with the previous version of Chef. ChefSpec only promises to be backwards compatible with the last major release of Chef, but it may work with earlier versions.

The hacks are kept in this file so as to avoid a bunch of branching logic throughout the codebase. It also makes dropping backwards compatability much easier without the risk of breaking things.

This file must be loaded AFTER the rest of ChefSpec has been initialized!

Defined Under Namespace

Modules: API, Cacher, Error, Macros, Matchers, Normalize, RemoveExistingLWRP, ServerMethods, Stubs, Util Classes: Berkshelf, ChefFormatter, Coverage, ExpectException, Librarian, Renderer, Runner, Server, ServerRunner, SoloRunner

Constant Summary collapse

VERSION =
'4.2.0'

Class Method Summary collapse

Class Method Details

.define_matcher(resource_name) ⇒ self

Defines a new runner method on the Chef runner.

Parameters:

  • resource_name (Symbol)

    the name of the resource to define a method

Returns:

  • (self)

12
13
14
15
16
17
18
# File 'lib/chefspec.rb', line 12

def define_matcher(resource_name)
  matchers[resource_name.to_sym] = Proc.new do |identity|
    find_resource(resource_name, identity)
  end

  self
end

.matchersHash<String, Proc>

The list of custom defined matchers.

Returns:

  • (Hash<String, Proc>)

39
40
41
# File 'lib/chefspec.rb', line 39

def matchers
  @matchers ||= {}
end

.rootPathname

The source root of the ChefSpec gem. This is useful when requiring files that are relative to the root of the project.

Returns:

  • (Pathname)

27
28
29
# File 'lib/chefspec.rb', line 27

def root
  @root ||= Pathname.new(File.expand_path('../../', __FILE__))
end