From bcc7ffc6d2cdecffd4aedd2156c08a8bf0beda8c Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sat, 16 Jul 2011 16:15:28 +1000 Subject: [PATCH] Proof of concept --- .gitignore | 1 + lib/puppet-rspec.rb | 2 ++ lib/puppet-rspec/matchers/exec.rb | 34 +++++++++++++++++++++++++++++++ puppet-rspec.gemspec | 18 ++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 .gitignore create mode 100644 lib/puppet-rspec/matchers/exec.rb create mode 100644 puppet-rspec.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c111b33 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.gem diff --git a/lib/puppet-rspec.rb b/lib/puppet-rspec.rb index e69de29..fd4a5c2 100644 --- a/lib/puppet-rspec.rb +++ b/lib/puppet-rspec.rb @@ -0,0 +1,2 @@ +require 'puppet' +require 'puppet-rspec/matchers/exec' diff --git a/lib/puppet-rspec/matchers/exec.rb b/lib/puppet-rspec/matchers/exec.rb new file mode 100644 index 0000000..11dbad1 --- /dev/null +++ b/lib/puppet-rspec/matchers/exec.rb @@ -0,0 +1,34 @@ +module PuppetRSpec + module Matchers + extend RSpec::Matchers::DSL + + matcher :create_exec do |expected_title| + match do |catalogue| + ret = true + resources = catalogue.resources.select { |r| + r.title == expected_title if r.respond_to? :title + } + + unless resources.length == 1 + ret = false + end + + unless @expected_command.nil? + unless resources.first.send(:parameters)[:command] == @expected_command + ret = false + end + end + ret + end + description do + "create Exec['#{expected_title}']" + end + failure_message_for_should do |actual| + "expected that the catalogue would contain Exec['#{expected_title}']" + end + chain :with_command do |expected_command| + @expected_command = expected_command + end + end + end +end diff --git a/puppet-rspec.gemspec b/puppet-rspec.gemspec new file mode 100644 index 0000000..26026d6 --- /dev/null +++ b/puppet-rspec.gemspec @@ -0,0 +1,18 @@ +Gem::Specification.new do |s| + s.name = 'puppet-rspec' + s.version = '0.0.1' + s.homepage = 'https://github.com/rodjek/puppet-rspec/' + s.summary = '' + s.description = '' + + s.files = [ + 'puppet-rspec.gemspec', + 'lib/puppet-rspec.rb', + 'lib/puppet-rspec/matchers/exec.rb' + ] + + s.add_dependency 'rspec' + + s.authors = ['Tim Sharpe'] + s.email = 'tim@sharpe.id.au' +end