Sha256: 359fa0231e57952b566536010d84316ad2e6b0a9507d2135ce06e60bf35a3d2a

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

RSpec.describe TTY::Config do
  it "fetches default if no value" do
    config = TTY::Config.new
    expect(config.fetch(:foo, default: :bar)).to eq(:bar)
  end

  it "fetches default proc value" do
    config = TTY::Config.new
    expect(config.fetch(:foo, default: -> { :bar })).to eq(:bar)
  end

  it "fetches deeply nested proc value" do
    config = TTY::Config.new
    expect(config.fetch(:foo, default: -> { -> { :bar }})).to eq(:bar)
  end

  it "fetches default as block" do
    config = TTY::Config.new
    expect(config.fetch(:foo) { :bar }).to eq(:bar)
  end

  it "fetches default as block for deeply nested missing key" do
    config = TTY::Config.new
    expect(config.fetch(:foo, :bar, :baz) { 2 }).to eq(2)
  end

  it "fetches value for deeply nested key" do
    config = TTY::Config.new
    config.set(:foo, :bar, :baz, value: 2)
    expect(config.fetch(:foo, :bar, :baz)).to eq(2)
  end

  it "fetches value as string delimited by . for deeply nested key" do
    config = TTY::Config.new
    config.set('foo', 'bar', 'baz') { 2 }
    expect(config.fetch("foo.bar.baz")).to eq(2)
  end

  it "fetches key with indifferent access" do
    config = TTY::Config.new
    config.set(:foo, :bar, :baz, value: 2)

    expect(config.fetch('foo', :bar, 'baz')).to eq(2)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tty-config-0.3.2 spec/unit/fetch_spec.rb
tty-config-0.3.1 spec/unit/fetch_spec.rb
tty-config-0.3.0 spec/unit/fetch_spec.rb