Class: RSpec::PathMatchers::Options::Content

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

Overview

content:

Class Method Summary collapse

Methods inherited from Base

description, match, validate_expected

Class Method Details

.fetch_actual(path, _failures) ⇒ Object



11
# File 'lib/rspec/path_matchers/options/content.rb', line 11

def self.fetch_actual(path, _failures) = File.read(path)

.keyObject



10
# File 'lib/rspec/path_matchers/options/content.rb', line 10

def self.key = :content

.literal_failure_message(actual, expected) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rspec/path_matchers/options/content.rb', line 25

def self.literal_failure_message(actual, expected)
  verb = expected.is_a?(Regexp) ? 'match' : 'be'

  actual_summary =
    if actual.length > 100
      verb == 'match' ? 'did not' : 'was not'
    else
      "was #{actual.inspect}"
    end

  "expected content to #{verb} #{expected.inspect}, but it #{actual_summary}"
end

.literal_match?(actual, expected) ⇒ Boolean

Override to provide custom matching logic for regexp literals

Returns:

  • (Boolean)


15
16
17
# File 'lib/rspec/path_matchers/options/content.rb', line 15

def self.literal_match?(actual, expected)
  expected.is_a?(Regexp) ? expected.match?(actual) : super
end

.matcher_failure_message(actual, expected) ⇒ Object

Handles failures when a matcher is used (e.g., content: include('...'))



20
21
22
23
# File 'lib/rspec/path_matchers/options/content.rb', line 20

def self.matcher_failure_message(actual, expected)
  actual_summary = actual.length > 100 ? 'did not' : "was #{actual.inspect}"
  "expected content to #{expected.description}, but it #{actual_summary}"
end

.valid_expected_typesObject



12
# File 'lib/rspec/path_matchers/options/content.rb', line 12

def self.valid_expected_types = [String, Regexp]