Class: RSpec::PathMatchers::Options::SymlinkTargetType

Inherits:
Base
  • Object
show all
Defined in:
lib/rspec/path_matchers/options/symlink_target_type.rb

Overview

target_type:

Checks the type of the entry a symlink points to (e.g., 'file', 'directory').

Class Method Summary collapse

Methods inherited from Base

description, validate_expected

Class Method Details

.fetch_actual(path, _failures) ⇒ Object



30
31
32
# File 'lib/rspec/path_matchers/options/symlink_target_type.rb', line 30

def self.fetch_actual(path, _failures)
  File.ftype(File.expand_path(File.readlink(path), File.dirname(path)))
end

.keyObject



13
# File 'lib/rspec/path_matchers/options/symlink_target_type.rb', line 13

def self.key = :target_type

.match(path, expected, failures) ⇒ Object

Overrides the base match method to gracefully handle dangling symlinks

If File.ftype fails because the target doesn't exist, it adds a descriptive failure instead of crashing.



22
23
24
25
26
27
28
# File 'lib/rspec/path_matchers/options/symlink_target_type.rb', line 22

def self.match(path, expected, failures)
  super
rescue Errno::ENOENT => e
  message = "expected the symlink target to exist, but got error: #{e.message}"
  add_failure(message, failures)
  nil
end

.normalize_expected_literal(expected) ⇒ Object



15
# File 'lib/rspec/path_matchers/options/symlink_target_type.rb', line 15

def self.normalize_expected_literal(expected) = expected.to_s

.valid_expected_typesObject



14
# File 'lib/rspec/path_matchers/options/symlink_target_type.rb', line 14

def self.valid_expected_types = [String, Symbol]