Class: RSpec::PathMatchers::Options::Base
- Inherits:
-
Object
- Object
- RSpec::PathMatchers::Options::Base
- Defined in:
- lib/rspec/path_matchers/options/base.rb
Overview
Abstract base class for all option matchers
@ api public
Direct Known Subclasses
Content, FileStatBase, ParsedContentBase, SymlinkTarget, SymlinkTargetExist, SymlinkTargetType
Class Method Summary collapse
-
.description(expected) ⇒ String
The description of the expectation for this option.
-
.key ⇒ Symbol
abstract
The option key.
-
.match(path, expected, failures)
Adds to
failuresif the entry at path does not match the expectation. -
.validate_expected(expected, errors)
Adds to
errorsif the value ofexpectedis not valid for this option type.
Class Method Details
.description(expected) ⇒ String
The description of the expectation for this option
This is used by RSpec when describing the matcher when tests are run in documentation format or when generating failure messages.
78 79 80 |
# File 'lib/rspec/path_matchers/options/base.rb', line 78 def self.description(expected) RSpec::PathMatchers.matcher?(expected) ? expected.description : expected.inspect end |
.key ⇒ Symbol
The option key
For example, if the option key is :owner, then it could be used like this:
expect(path).to be_file(owner: 'alice')
29 30 31 |
# File 'lib/rspec/path_matchers/options/base.rb', line 29 def self.key raise NotImplementedError, 'Subclasses must implement Base.key' end |
.match(path, expected, failures)
This method returns an undefined value.
Adds to failures if the entry at path does not match the expectation
Entry is a file, directory, or symlink.
You can assume that entry at path exists and is the expected type (file, directory, or symlink).
This is the main method that the matcher (such as be_dir, be_file, or be_symlink) calls to run its check for an option.
failure objects to (if any)
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rspec/path_matchers/options/base.rb', line 54 def self.match(path, expected, failures) actual = fetch_actual(path, failures) return if actual == FETCH_ERROR rescue NotImplementedError RSpec.configuration.reporter.((path)) else if RSpec::PathMatchers.matcher?(expected) match_matcher(actual, expected, failures) else match_literal(actual, expected, failures) end end |
.validate_expected(expected, errors)
This method returns an undefined value.
Adds to errors if the value of expected is not valid for this option type
The matcher (such as be_dir, be_file, or be_symlink) calls this
method to validate the expected value before running the matcher.
It checks that the expected value is a RSpec matcher or one of the types listed in valid_expected_types.
98 99 100 101 102 103 104 105 106 |
# File 'lib/rspec/path_matchers/options/base.rb', line 98 def self.validate_expected(expected, errors) return if expected == NOT_GIVEN || RSpec::PathMatchers.matcher?(expected) || valid_expected_types.any? { |type| expected.is_a?(type) } types = ['Matcher', *valid_expected_types.map(&:name)].to_sentence(conjunction: 'or') errors << "expected `#{key}:` to be a #{types}, but it was #{expected.inspect}" end |