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

Class Method Details

.load_file(file_name) ⇒ String

Loads the content of a fixture file as a string.

Parameters:

  • file_name (String)

    The name of the fixture file to load.

Returns:

  • (String)

    The content of the loaded file.



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.

Parameters:

  • file_name (String)

    The name of the JSON fixture file to load.

Returns:

  • (Object)

    The parsed Ruby object from the JSON file.



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.

Parameters:

  • file_name (String)

    The name of the YAML fixture file to load.

Returns:

  • (Object)

    The parsed Ruby object from the YAML file.



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

.rootPathname

Returns the root directory path where the fixture files are located.

Returns:

  • (Pathname)

    The root directory path.



12
13
14
# File 'lib/deepgram/fixtures.rb', line 12

def self.root
  @root ||= Pathname.new(__dir__).join('..', '..', 'spec', 'fixtures')
end