Skip to content

Commit

Permalink
add apt_update matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Cullen McDermott committed May 18, 2016
1 parent 82f79e2 commit 11964e7
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/apt_update/recipes/periodic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apt_repository 'default_action'

apt_update 'explicit_action' do
action :periodic
end
3 changes: 3 additions & 0 deletions examples/apt_update/recipes/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apt_update 'update_repo' do
action :update
end
14 changes: 14 additions & 0 deletions examples/apt_update/spec/periodic_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'chefspec'

describe 'apt_update::periodic' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

it 'updates apt with default action' do
expect(chef_run).to periodic_apt_update('default_action')
expect(chef_run).to_not periodic_apt_update('not_default_action')
end

it 'installs a apt_repository with an explicit action' do
expect(chef_run).to periodic_apt_update('explicit_action')
end
end
9 changes: 9 additions & 0 deletions examples/apt_update/spec/update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'chefspec'

describe 'apt_update::update' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

it 'updates apt repo' do
expect(chef_run).to update_apt_update('update_repo')
end
end
50 changes: 50 additions & 0 deletions lib/chefspec/api/apt_update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module ChefSpec::API
# @since 3.0.0
module AptRepositoryMatchers
ChefSpec.define_matcher :apt_update

#
# Assert that an +apt_update+ resource exists in the Chef run with the
# action +:update+. Given a Chef Recipe that adds "rsyslog" as a repository
# to update.
# apt_repository 'rsyslog' do
# action :update
# end
#
# The Examples section demonstrates the different ways to test an
# +apt_update+ resource with ChefSpec.
#
# @example Assert that an +apt_update+ was run
# expect(chef_run).to update_apt_update('rsyslog')
# @param [String, Regex] resource_name
# the name of the resource to match
#
# @return [ChefSpec::Matchers::ResourceMatcher]

def update_apt_update(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:apt_update, :update,
resource_name)
end

#
# Assert that an +apt_update+ resource exists in the Chef run
# with the action +:periodic+. Given a Chef Recipe that updates "rsyslog"
# as an +apt_update+: periodically
#
# apt_update 'rsyslog' do
# action :periodic
# end
#
# The Examples section demonstrates the different ways to test an
# +apt_update+ resource with ChefSpec.
#
# @example Assert that an +apt_update+ was updated periodically
# expect(chef_run).to periodic_apt_update('rsyslog')
# @param [String, Regex] resource_name
# the name of the resource to match
#
# @return [ChefSpec::Matchers::ResourceMatcher]


end
end

0 comments on commit 11964e7

Please sign in to comment.