lib/minitest/filesystem/matcher.rb in minitest-filesystem-1.0.1 vs lib/minitest/filesystem/matcher.rb in minitest-filesystem-1.1.0
- old
+ new
@@ -11,10 +11,14 @@
def file(file)
entry(file, :file) && is_a?(file, :file)
end
+ def link(link, target=nil)
+ entry(link, :symlink) && is_a?(link, :symlink) && is_target_correct?(link, target)
+ end
+
def dir(dir, &block)
matcher = self.class.new(@actual_tree.expand_path(dir), &block) if block_given?
entry(dir, :directory) && is_a?(dir, :directory) && subtree(matcher)
end
@@ -34,14 +38,26 @@
update_matching_status(
@actual_tree.include?(entry),
not_found_msg_for(entry, kind))
end
+ def is_target_correct?(link, target)
+ return true unless target
+
+ update_matching_status(
+ @actual_tree.expand_path(target) == follow_link(@actual_tree.expand_path(link)),
+ link_target_mismatch_msg_for(link, target))
+ end
+
def subtree(matcher)
update_matching_status(matcher.match_found?, matcher.message) if matcher
end
+ def follow_link(link)
+ Pathname.new(File.readlink(link))
+ end
+
def is_a?(entry, kind)
update_matching_status(
@actual_tree.is_a?(entry, kind),
mismatch_msg_for(entry, kind))
end
@@ -57,9 +73,13 @@
"Expected `#{@actual_tree.root}` to contain #{kind} `#{entry}`."
end
def mismatch_msg_for(entry, kind)
"Expected `#{entry}` to be a #{kind}, but it was not."
+ end
+
+ def link_target_mismatch_msg_for(link, target)
+ "Expected `#{link}` to point to `#{target}`, but it pointed to #{File.readlink(@actual_tree.expand_path(link))}"
end
def set_failure_msg(msg)
@failure_msg ||= msg
end