From 3706124e0ec403c4d4666a85affbdd9bd8cde998 Mon Sep 17 00:00:00 2001 From: Will Farrington Date: Tue, 6 Sep 2011 18:31:56 -0400 Subject: [PATCH] Woo --- .rspec | 2 +- lib/vagabond/matchers/file.rb | 18 +++++++++++++++++- lib/vagabond/resources/file.rb | 9 ++++++++- spec/file_spec.rb | 4 ++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.rspec b/.rspec index 4e1e0d2..114486d 100644 --- a/.rspec +++ b/.rspec @@ -1 +1 @@ ---color +--color --format documentation diff --git a/lib/vagabond/matchers/file.rb b/lib/vagabond/matchers/file.rb index 0ec5656..981f268 100644 --- a/lib/vagabond/matchers/file.rb +++ b/lib/vagabond/matchers/file.rb @@ -1,9 +1,25 @@ +require 'etc' + module Vagabond module Matchers module File RSpec::Matchers.define :exist do match do |actual| - ::File.exist? actual.name + ::File.exist? actual + end + + failure_message_for_should do |actual| + "expected file(#{actual}) would exist" + end + + failure_message_for_should_not do |actual| + "expected file(#{actual}) would not exist" + end + end + + RSpec::Matchers.define :have_owner do |expected| + match do |actual| + ::Etc.getpwuid(::File.stat(actual).uid).name == expected end end end diff --git a/lib/vagabond/resources/file.rb b/lib/vagabond/resources/file.rb index 0280ced..ab64f5e 100644 --- a/lib/vagabond/resources/file.rb +++ b/lib/vagabond/resources/file.rb @@ -1,7 +1,7 @@ module Vagabond module Resources class File - attr_accessor :name, :owner, :group + attr_accessor :name, :owner, :group, :path def initialize(name, options = {}) @name = name @@ -11,6 +11,13 @@ def initialize(name, options = {}) if options[:group] @group = options[:group] end + if options[:path] + @path = options[:path] + end + end + + def to_s + @path || @name end end end diff --git a/spec/file_spec.rb b/spec/file_spec.rb index e186df7..76a79bf 100644 --- a/spec/file_spec.rb +++ b/spec/file_spec.rb @@ -6,4 +6,8 @@ describe file("/etc/motd") do it { should_not exist } +end + +describe file("~/.git/config") do + it { should have_owner('wfarr') } end \ No newline at end of file