Permalink
Browse files

Add support for link resources

* Add create, delete, and link_to matchers
* Add link finder to ChefRunner
  • Loading branch information...
1 parent 55819e3 commit 350936575c3d9bd89385408c3786277f026122f2 James Burgess committed May 1, 2012
View
@@ -4,6 +4,7 @@
require 'chefspec/version'
require 'chefspec/matchers/execute'
require 'chefspec/matchers/file'
+require 'chefspec/matchers/link'
require 'chefspec/matchers/log'
require 'chefspec/matchers/package'
require 'chefspec/matchers/service'
@@ -126,6 +126,14 @@ def template(path)
find_resource('template', path)
end
+ # Find any link declared with the given target_file
+ #
+ # @param [String] target_file The link's target_file
+ # @return [Chef::Resource::Directory] The matching link, or Nil
+ def link(target_file)
+ find_resource('link', target_file)
+ end
+
# This runner as a string.
#
# @return [String] Currently includes the run_list. Format of the string may change between versions of this gem.
@@ -0,0 +1,14 @@
+require 'chefspec/matchers/shared'
+
+module ChefSpec
+ module Matchers
+
+ define_resource_matchers([:create, :delete], [:link], :target_file)
+
+ RSpec::Matchers.define :link_to do |path|
+ match do |link|
+ link.nil? ? false : link.to == path
+ end
+ end
+ end
+end
@@ -119,6 +119,18 @@ module ChefSpec
runner.directory('/tmp').should be
end
end
+ describe "#link" do
+ it "should not return a resource when the link has not been declared" do
+ runner = ChefSpec::ChefRunner.new
+ runner.resources = []
+ runner.link('/tmp').should_not be
+ end
+ it "should return a resource when the link has been declared" do
+ runner = ChefSpec::ChefRunner.new
+ runner.resources = [{:resource_name => 'link', :name => '/tmp'}]
+ runner.link('/tmp').should be
+ end
+ end
describe "#to_s" do
let(:chef_run) { ChefSpec::ChefRunner.new(:dry_run => true) }
it "should override the default string representation to something readable" do
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+module ChefSpec
+ module Matchers
+ describe :link_to do
+ describe "#match" do
+ let(:matcher) { link_to('/foo') }
+ it "should not match when the link is nil" do
+ matcher.matches?(nil).should be false
+ end
+ it "should not match when the link is different" do
+ matcher.matches?({:to => '/bar'}).should be false
+ end
+ it "should match when the link matches" do
+ matcher.matches?({:to => '/foo'}).should be true
+ end
+ end
+ end
+ end
+end

0 comments on commit 3509365

Please sign in to comment.