class GeneratorSpec::Matcher::Directory
Attributes
tree[R]
Public Class Methods
new(root = nil, &block)
click to toggle source
# File lib/generator_spec/matcher.rb, line 64 def initialize(root = nil, &block) @tree = {} @negative_tree = [] @root = root instance_eval(&block) if block_given? end
Public Instance Methods
directory(name, &block)
click to toggle source
# File lib/generator_spec/matcher.rb, line 71 def directory(name, &block) @tree[name] = block_given? && Directory.new(location(name), &block) end
file(name, &block)
click to toggle source
# File lib/generator_spec/matcher.rb, line 75 def file(name, &block) @tree[name] = File.new(location(name), &block) end
location(name)
click to toggle source
# File lib/generator_spec/matcher.rb, line 83 def location(name) [@root, name].compact.join("/") end
matches?(root)
click to toggle source
# File lib/generator_spec/matcher.rb, line 91 def matches?(root) @tree.each do |file, value| unless value unless root.join(location(file)).exist? throw :failure, "#{root}/#{location(file)}" end else value.matches?(root) end end @negative_tree.each do |file| if root.join(location(file)).exist? throw :failure, [:not, "unexpected #{root}/#{location(file)}"] end end nil end
migration(name, &block)
click to toggle source
# File lib/generator_spec/matcher.rb, line 87 def migration(name, &block) @tree[name] = Migration.new(location(name), &block) end
no_file(name)
click to toggle source
# File lib/generator_spec/matcher.rb, line 79 def no_file(name) @negative_tree << name end