Class: RSpec::PathMatchers::Options::SymlinkTargetType
- 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
- .fetch_actual(path, _failures) ⇒ Object
- .key ⇒ Object
-
.match(path, expected, failures) ⇒ Object
Overrides the base match method to gracefully handle dangling symlinks.
- .normalize_expected_literal(expected) ⇒ Object
- .valid_expected_types ⇒ Object
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.(File.readlink(path), File.dirname(path))) end |
.key ⇒ Object
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 = "expected the symlink target to exist, but got error: #{e.}" add_failure(, 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_types ⇒ Object
14 |
# File 'lib/rspec/path_matchers/options/symlink_target_type.rb', line 14 def self.valid_expected_types = [String, Symbol] |