diff --git a/features/step_definitions/file_steps.rb b/features/step_definitions/file_steps.rb index 5c3f477c..d4a722e0 100644 --- a/features/step_definitions/file_steps.rb +++ b/features/step_definitions/file_steps.rb @@ -51,6 +51,17 @@ } end +Given /^a Chef cookbook with a recipe that creates a remote file$/ do + steps %q{ + Given a file named "cookbooks/example/recipes/default.rb" with: + """ruby + remote_file "hello-world.txt" do + action :create + end + """ + } +end + Given /^a Chef cookbook with a recipe that sets file ownership$/ do steps %q{ Given a file named "cookbooks/example/recipes/default.rb" with: @@ -162,6 +173,22 @@ } end +Given /^the recipe has a spec example that expects the remote file to be created/ do + steps %q{ + Given a file named "cookbooks/example/spec/default_spec.rb" with: + """ruby + require "chefspec" + + describe "example::default" do + let(:chef_run) {ChefSpec::ChefRunner.new.converge 'example::default'} + it "should create the remote file" do + chef_run.should create_remote_file 'hello-world.txt' + end + end + """ + } +end + Given /^the recipe has a spec example that expects the file to be set to be owned by a specific user$/ do steps %q{ Given a file named "cookbooks/example/spec/default_spec.rb" with: diff --git a/features/write_examples_for_files.feature b/features/write_examples_for_files.feature index 23fef8d4..c722a18a 100644 --- a/features/write_examples_for_files.feature +++ b/features/write_examples_for_files.feature @@ -42,6 +42,12 @@ Feature: Write examples for files When the recipe example is successfully run Then the directory will not have been deleted + Scenario: Create a remote file + Given a Chef cookbook with a recipe that creates a remote file + And the recipe has a spec example that expects the remote file to be created + When the recipe example is successfully run + Then the file will not have been created + Scenario: Check file ownership Given a Chef cookbook with a recipe that sets file ownership And the recipe has a spec example that expects the file to be set to be owned by a specific user diff --git a/lib/chefspec/matchers/file.rb b/lib/chefspec/matchers/file.rb index 3f4eff5f..c3c28c42 100644 --- a/lib/chefspec/matchers/file.rb +++ b/lib/chefspec/matchers/file.rb @@ -4,6 +4,7 @@ module ChefSpec module Matchers define_resource_matchers([:create, :delete], [:file, :directory, :cookbook_file], :path) + define_resource_matchers([:create], [:remote_file], :path) RSpec::Matchers.define :be_owned_by do |user, group| match do |file| @@ -11,4 +12,4 @@ module Matchers end end end -end \ No newline at end of file +end