Sha256: d9af3919957d58c916b930093f635045aff872c0853f7715ddbbceb83d1a8120

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

require 'yaml'
require 'logger'
require 'file_repository'

RSpec.describe RubyRemoteConfig::FileRepository do
  describe '#refresh' do
    it 'reads the YAML file and unmarshals it into the data map' do
      # Create a temporary YAML file
      yaml_data = { 'config_name' => { 'key' => 'value' } }.to_yaml
      yaml_file = Tempfile.new('config.yml')
      yaml_file.write(yaml_data)
      yaml_file.close

      # Create a new FileRepository object
      repo = RubyRemoteConfig::FileRepository.new(name: 'test', path: yaml_file.path)

      # Call the refresh method
      repo.refresh

      # Check that the data map is set correctly
      expect(repo.get_data('config_name')).to eq({ 'key' => 'value' })

      # Delete the temporary YAML file
      yaml_file.unlink
    end

    it 'raises an error if there is an error unmarshalling the YAML data' do
      # Create a temporary YAML file with invalid data
      yaml_data = "invalid_yaml_data"
      yaml_file = Tempfile.new('invalid_yaml_data.yml')
      yaml_file.write(yaml_data)
      yaml_file.close
      # Create a new FileRepository object
      repo = RubyRemoteConfig::FileRepository.new(name: 'test', path: yaml_file.path)
      # Call the refresh method and check that it raises an error
      repo.refresh

      # Delete the temporary YAML file
      yaml_file.unlink
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-remote-config-1.0.4 spec/file_repository_spec.rb
ruby-remote-config-1.0.3 spec/file_repository_spec.rb
ruby-remote-config-1.0.2 spec/file_repository_spec.rb