class Minitest::Filesystem::Matcher
Public Class Methods
new(root, &block)
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 6 def initialize(root, &block) @actual_tree = MatchingTree.new(root) @expected_tree = block @is_matching = true end
Public Instance Methods
dir(dir, &block)
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 20 def dir(dir, &block) matcher = self.class.new(@actual_tree.expand_path(dir), &block) if block_given? exists?(dir, :directory) && subtree(matcher) end
file(file)
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 12 def file(file) exists?(file, :file) end
link(link, target=nil)
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 16 def link(link, target=nil) exists?(link, :symlink) && is_target_correct?(link, target) end
match_found?()
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 26 def match_found? instance_eval(&@expected_tree) @is_matching end
message()
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 31 def message @failure_msg || "" end
Private Instance Methods
entry(entry, kind=:entry)
click to toggle source
Checks if an entry with given name exists.
# File lib/minitest/filesystem/matcher.rb, line 45 def entry(entry, kind=:entry) update_matching_status( @actual_tree.include?(entry), not_found_msg_for(entry, kind)) end
exists?(entry, kind=:entry)
click to toggle source
Checks existance of specified entry. Existance is defined both in terms of presence and of being of the right type (e.g. a file being a file and not a directory)
# File lib/minitest/filesystem/matcher.rb, line 40 def exists?(entry, kind=:entry) entry(entry, kind) && is_a?(entry, kind) end
is_a?(entry, kind)
click to toggle source
Checks if a specific entry (supposed to exist) is of a given kind.
# File lib/minitest/filesystem/matcher.rb, line 52 def is_a?(entry, kind) update_matching_status( @actual_tree.is_a?(entry, kind), mismatch_msg_for(entry, kind)) end
is_target_correct?(link, target)
click to toggle source
Checks the target of a symbolic link.
# File lib/minitest/filesystem/matcher.rb, line 59 def is_target_correct?(link, target) return true unless target update_matching_status( @actual_tree.has_target?(link, target), link_target_mismatch_msg_for(link, target)) end
link_target_mismatch_msg_for(link, target)
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 86 def link_target_mismatch_msg_for(link, target) "Expected `#{link}` to point to `#{target}`, but it pointed to #{@actual_tree.follow_link(link)}" end
mismatch_msg_for(entry, kind)
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 82 def mismatch_msg_for(entry, kind) "Expected `#{entry}` to be a #{kind}, but it was not." end
not_found_msg_for(entry, kind)
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 78 def not_found_msg_for(entry, kind) "Expected `#{@actual_tree.root}` to contain #{kind} `#{entry}`." end
set_failure_msg(msg)
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 90 def set_failure_msg(msg) @failure_msg ||= msg end
subtree(matcher)
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 67 def subtree(matcher) update_matching_status(matcher.match_found?, matcher.message) if matcher end
update_matching_status(check, msg)
click to toggle source
# File lib/minitest/filesystem/matcher.rb, line 71 def update_matching_status(check, msg) @is_matching = @is_matching && check set_failure_msg(msg) unless @is_matching @is_matching end