Skip to content

Commit

Permalink
Add support for remote_file.
Browse files Browse the repository at this point in the history
  • Loading branch information
guitsaru authored and Andrew Crump committed May 25, 2012
1 parent 3509365 commit 23f4b34
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
27 changes: 27 additions & 0 deletions features/step_definitions/file_steps.rb
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions features/write_examples_for_files.feature
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/chefspec/matchers/file.rb
Expand Up @@ -4,11 +4,12 @@ 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|
file.nil? ? false : file.owner == user and file.group == group
end
end
end
end
end

0 comments on commit 23f4b34

Please sign in to comment.