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.
-
.match_matcher(actual, expected, failures) ⇒ void
Compares the parsed content against the given RSpec matcher.
- .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.
49 50 51 |
# File 'lib/rspec/path_matchers/options/parsed_content_base.rb', line 49 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.message}" 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 |
.match_matcher(actual, expected, failures) ⇒ void
This method returns an undefined value.
Compares the parsed content against the given RSpec matcher.
38 39 40 41 42 43 |
# File 'lib/rspec/path_matchers/options/parsed_content_base.rb', line 38 def self.match_matcher(actual, expected, failures) return if expected.matches?(actual) = "expected #{content_type} content to #{expected.description}" add_failure(, failures) end |
.valid_expected_types ⇒ Object
10 |
# File 'lib/rspec/path_matchers/options/parsed_content_base.rb', line 10 def self.valid_expected_types = [TrueClass] |