Sha256: 5ea45757b73e3123b37072d9f2d31b0ca4e0266c045ba00de05931f2a1b185c1

Contents?: true

Size: 1.85 KB

Versions: 8

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Stealth::Configuration" do

  describe "accessing via method calling" do
    let(:services_yml) { File.read(File.join(File.dirname(__FILE__), 'sample_services_yml', 'services.yml')) }
    let(:parsed_config) { YAML.load(ERB.new(services_yml).result)[Stealth.env] }
    let(:config) { Stealth.load_services_config!(services_yml) }

    it "should return the root node" do
      expect(config.facebook).to eq parsed_config['facebook']
    end

    it "should access deeply nested nodes" do
      expect(config.facebook.setup.greeting).to eq parsed_config['facebook']['setup']['greeting']
    end

    it "should handle values that are arrays correctly" do
      expect(config.facebook.setup.persistent_menu).to be_a(Array)
    end

    it "should retain the configuration at the class level" do
      expect(Stealth.config.facebook.setup.greeting).to eq parsed_config['facebook']['setup']['greeting']
    end

    it "should handle multiple keys at the root level" do
      expect(config.twilio_sms.account_sid).to eq parsed_config['twilio_sms']['account_sid']
    end
  end

  describe "config files with ERB" do
    let(:services_yml) { File.read(File.join(File.dirname(__FILE__), 'sample_services_yml', 'services_with_erb.yml')) }
    let(:config) { Stealth.load_services_config!(services_yml) }

    it "should replace available embedded env vars" do
      ENV['FACEBOOK_VERIFY_TOKEN'] = 'it works'
      expect(config.facebook.verify_token).to eq 'it works'
    end

    it "should replace unavailable embedded env vars with nil" do
      expect(config.facebook.challenge).to be_nil
    end

    it "should not reload the configuration file if one already exists" do
      Stealth.load_services_config(services_yml)
      expect(config.facebook.challenge).to be_nil
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stealth-0.9.8 spec/configuration_spec.rb
stealth-0.9.7 spec/configuration_spec.rb
stealth-0.9.6 spec/configuration_spec.rb
stealth-0.9.5 spec/configuration_spec.rb
stealth-0.9.4 spec/configuration_spec.rb
stealth-0.9.3 spec/configuration_spec.rb
stealth-0.9.2 spec/configuration_spec.rb
stealth-0.9.1 spec/configuration_spec.rb