spec/support/matchers/file_system_matchers.rb in berkshelf-1.4.5 vs spec/support/matchers/file_system_matchers.rb in berkshelf-1.4.6

- old
+ new

@@ -1,11 +1,11 @@ # Taken from (https://github.com/carlhuda/beard) # Permission granted by Yehuda Katz (Jan 4th, 2012) module Berkshelf module RSpec module FileSystemMatchers - class File < ::File + class FileMatcher def initialize(name, &block) @contents = [] @negative_contents = [] @name = name @@ -25,11 +25,11 @@ def matches?(root) unless root.join(@name).exist? throw :failure, root.join(@name) end - contents = ::File.read(root.join(@name)) + contents = File.read(root.join(@name)) @contents.each do |string| unless contents.include?(string) throw :failure, [root.join(@name), string, contents] end @@ -41,27 +41,27 @@ end end end end - class Directory + class DirectoryMatcher attr_reader :tree def initialize(root = nil, &block) @tree = {} @negative_tree = [] @root = root instance_eval(&block) if block_given? end def directory(name, &block) - @tree[name] = block_given? && Directory.new(location(name), &block) + @tree[name] = block_given? && DirectoryMatcher.new(location(name), &block) end def file(name, &block) silence_warnings do - @tree[name] = Berkshelf::RSpec::FileSystemMatchers::File.new(location(name), &block) + @tree[name] = FileMatcher.new(location(name), &block) end end def no_file(name) @negative_tree << name @@ -90,11 +90,11 @@ nil end end - class Root < Directory + class RootMatcher < DirectoryMatcher def failure_message if @failure.is_a?(Array) && @failure[0] == :not if @failure[2] "File #{@failure[1]} should not have contained \"#{@failure[2]}\"" else @@ -123,10 +123,10 @@ !@failure end end def have_structure(&block) - Root.new(&block) + RootMatcher.new(&block) end end end end