Class: RSpec::PathMatchers::Matchers::NoEntryMatcher Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/path_matchers/matchers/no_entry_matcher.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Asserts that a directory entry of a specific entry_type does NOT exist. This is a simple, internal matcher-like object.

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry_name, matcher_name:, entry_type:) ⇒ NoEntryMatcher

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the matcher with the entry name and type

Parameters:

  • The name of the entry to check

  • The name of the DSL method used to create this matcher

  • The type of the entry (:file, :directory, or :symlink)

API:

  • private



21
22
23
24
25
26
27
# File 'lib/rspec/path_matchers/matchers/no_entry_matcher.rb', line 21

def initialize(entry_name, matcher_name:, entry_type:)
  @entry_name = entry_name
  @matcher_name = matcher_name
  @entry_type = entry_type
  @base_path = nil
  @path = nil
end

Instance Attribute Details

#base_pathObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



11
12
13
# File 'lib/rspec/path_matchers/matchers/no_entry_matcher.rb', line 11

def base_path
  @base_path
end

#entry_nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



11
12
13
# File 'lib/rspec/path_matchers/matchers/no_entry_matcher.rb', line 11

def entry_name
  @entry_name
end

#entry_typeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



11
12
13
# File 'lib/rspec/path_matchers/matchers/no_entry_matcher.rb', line 11

def entry_type
  @entry_type
end

#pathObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



11
12
13
# File 'lib/rspec/path_matchers/matchers/no_entry_matcher.rb', line 11

def path
  @path
end

Instance Method Details

#collect_validation_errors(_errors) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Called by DirectoryMatcher but is not needed for this simple matcher

API:

  • private



60
# File 'lib/rspec/path_matchers/matchers/no_entry_matcher.rb', line 60

def collect_validation_errors(_errors); end

#descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Provides a human-readable description for use in test output.

API:

  • private



55
56
57
# File 'lib/rspec/path_matchers/matchers/no_entry_matcher.rb', line 55

def description
  "not have #{entry_type} #{entry_name.inspect}"
end

#execute_match(base_path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The core logic. Returns true if the expectation is met (the entry is absent).

API:

  • private



30
31
32
33
34
35
36
37
38
39
# File 'lib/rspec/path_matchers/matchers/no_entry_matcher.rb', line 30

def execute_match(base_path) # rubocop:disable Naming/PredicateMethod
  @base_path = base_path
  @path = File.join(base_path, entry_name)

  case entry_type
  when :file then !File.file?(path)
  when :directory then !File.directory?(path)
  else !File.symlink?(path)
  end
end

#failure_messageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The failure message if execute_match returns false.

API:

  • private



42
43
44
# File 'lib/rspec/path_matchers/matchers/no_entry_matcher.rb', line 42

def failure_message
  "expected #{entry_type} '#{entry_name}' not to be found at '#{base_path}', but it exists"
end

#failuresArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the failure message in an array as expected by the DirectoryMatcher

Returns:

API:

  • private



50
51
52
# File 'lib/rspec/path_matchers/matchers/no_entry_matcher.rb', line 50

def failures
  [RSpec::PathMatchers::Failure.new('.', failure_message)]
end