Module: ChefSpec::API::GitMatchers

Defined in:
lib/chefspec/api/git.rb

Overview

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

#checkout_git(resource_name) ⇒ ChefSpec::Matchers::ResourceMatcher

Assert that a git resource exists in the Chef run with the action :checkout. Given a Chef Recipe that checks out “git://…” as a git:

git 'git://...' do
  action :checkout
end

The Examples section demonstrates the different ways to test a git resource with ChefSpec.

Examples:

Assert that a git was checked out

expect(chef_run).to checkout_git('git://...')

Assert that a git was checked out with predicate matchers

expect(chef_run).to checkout_git('git://...').with_user('svargo')

Assert that a git was checked out with attributes

expect(chef_run).to checkout_git('git://...').with(user: 'svargo')

Assert that a git was checked out using a regex

expect(chef_run).to checkout_git('git://...').with(user: /sva(.+)/)

Assert that a git was not checked out

expect(chef_run).to_not checkout_git('git://...')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0


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

def checkout_git(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:git, :checkout, resource_name)
end

#export_git(resource_name) ⇒ ChefSpec::Matchers::ResourceMatcher

Assert that a git resource exists in the Chef run with the action :export. Given a Chef Recipe that exports “git://” as a git:

git 'git://' do
  action :export
end

The Examples section demonstrates the different ways to test a git resource with ChefSpec.

Examples:

Assert that a git was exported

expect(chef_run).to export_git('git://')

Assert that a git was exported with predicate matchers

expect(chef_run).to export_git('git://').with_user('svargo')

Assert that a git was exported with attributes

expect(chef_run).to export_git('git://').with(user: 'svargo')

Assert that a git was exported using a regex

expect(chef_run).to export_git('git://').with(user: /sva(.+)/)

Assert that a git was not exported

expect(chef_run).to_not export_git('git://')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0


76
77
78
# File 'lib/chefspec/api/git.rb', line 76

def export_git(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:git, :export, resource_name)
end

#sync_git(resource_name) ⇒ ChefSpec::Matchers::ResourceMatcher

Assert that a git resource exists in the Chef run with the action :sync. Given a Chef Recipe that syncs “git://” as a git:

git 'git://' do
  action :sync
end

The Examples section demonstrates the different ways to test a git resource with ChefSpec.

Examples:

Assert that a git was synced

expect(chef_run).to sync_git('git://')

Assert that a git was synced with predicate matchers

expect(chef_run).to sync_git('git://').with_user('svargo')

Assert that a git was synced with attributes

expect(chef_run).to sync_git('git://').with(user: 'svargo')

Assert that a git was synced using a regex

expect(chef_run).to sync_git('git://').with(user: /sva(.+)/)

Assert that a git was not synced

expect(chef_run).to_not sync_git('git://')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0


113
114
115
# File 'lib/chefspec/api/git.rb', line 113

def sync_git(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:git, :sync, resource_name)
end