Class: RSpec::PathMatchers::Options::ParsedContentBase
- Defined in:
- lib/rspec/path_matchers/options/parsed_content_base.rb
Overview
Base class for options that parse file content like JSON, and YAML
Direct Known Subclasses
Class Method Summary collapse
-
.description(expected) ⇒ Object
Provides a human-readable description for the option.
-
.fetch_actual(path, failures) ⇒ Object, FETCH_ERROR
Reads and parses the file content.
-
.match_literal(_actual, _expected, _failures) ⇒ Object
This is the
xxxx_content: true
case. -
.matcher_failure_message(actual, expected)
Failure message for when a matcher is used (e.g.,
json_content: include(...)
). - .valid_expected_types ⇒ Object
Methods inherited from Base
Class Method Details
.description(expected) ⇒ Object
Provides a human-readable description for the option
Returns a special message for the json_content: true
case.
48 49 50 |
# File 'lib/rspec/path_matchers/options/parsed_content_base.rb', line 48 def self.description(expected) expected == true ? "be #{content_type.downcase} content" : super end |
.fetch_actual(path, failures) ⇒ Object, FETCH_ERROR
Reads and parses the file content
This method will rescue any parsing errors (e.g., JSON::ParserError
)
and add a descriptive failure instead of crashing.
21 22 23 24 25 26 27 |
# File 'lib/rspec/path_matchers/options/parsed_content_base.rb', line 21 def self.fetch_actual(path, failures) parse(File.read(path)) rescue parsing_error => e = "expected valid #{content_type} content, but got error: #{e.}" add_failure(, failures) FETCH_ERROR end |
.match_literal(_actual, _expected, _failures) ⇒ Object
This is the xxxx_content: true
case. A successful fetch_actual is sufficient
30 |
# File 'lib/rspec/path_matchers/options/parsed_content_base.rb', line 30 def self.match_literal(_actual, _expected, _failures); end |
.matcher_failure_message(actual, expected)
This method returns an undefined value.
Failure message for when a matcher is used (e.g., json_content: include(...)
)
38 39 40 41 42 |
# File 'lib/rspec/path_matchers/options/parsed_content_base.rb', line 38 def self.(actual, expected) actual_summary = actual.inspect.length > 100 ? 'it did not' : "was #{actual.inspect}" "expected #{content_type} content to #{expected.description}, but #{actual_summary}" end |
.valid_expected_types ⇒ Object
10 |
# File 'lib/rspec/path_matchers/options/parsed_content_base.rb', line 10 def self.valid_expected_types = [TrueClass] |