Module: Deepgram::Fixtures
- Defined in:
- lib/deepgram/fixtures.rb
Overview
The Fixtures module provides utility methods for loading fixture files used for testing purposes.
Class Method Summary collapse
-
.load_file(file_name) ⇒ String
Loads the content of a fixture file as a string.
-
.load_json(file_name) ⇒ Object
Loads the content of a JSON fixture file and parses it as a Ruby object.
-
.load_yaml(file_name) ⇒ Object
Loads the content of a YAML fixture file and parses it as a Ruby object.
-
.root ⇒ Pathname
Returns the root directory path where the fixture files are located.
Class Method Details
.load_file(file_name) ⇒ String
Loads the content of a fixture file as a string.
21 22 23 24 |
# File 'lib/deepgram/fixtures.rb', line 21 def self.load_file(file_name) file_path = root.join(file_name) File.read(file_path) end |
.load_json(file_name) ⇒ Object
Loads the content of a JSON fixture file and parses it as a Ruby object.
31 32 33 |
# File 'lib/deepgram/fixtures.rb', line 31 def self.load_json(file_name) JSON.parse(load_file(file_name)) end |
.load_yaml(file_name) ⇒ Object
Loads the content of a YAML fixture file and parses it as a Ruby object.
40 41 42 |
# File 'lib/deepgram/fixtures.rb', line 40 def self.load_yaml(file_name) YAML.safe_load(load_file(file_name), permitted_classes: []) end |
.root ⇒ Pathname
Returns the root directory path where the fixture files are located.
12 13 14 |
# File 'lib/deepgram/fixtures.rb', line 12 def self.root @root ||= Pathname.new(__dir__).join('..', '..', 'spec', 'fixtures') end |