Sha256: 0f97257b4fdabd59003fe1622939ae10a750a8ac40c584f4283752e3e08d2d63

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

require 'helper'

describe Mutaconf::DSL do

  let(:target){ {} }
  let(:dsl){ Mutaconf::DSL.new options }
  let(:options){ { attrs: { target => true } } }

  it "should configure properties with instance evaluation" do
    result = dsl.configure do
      a 'b'
      c 'd'
    end
    expected = { a: 'b', c: 'd' }
    result.should be(dsl)
    target.should == expected
  end

  it "should configure properties with a configuration object" do
    result = dsl.configure do |config|
      config.e = 'f'
      config.g = 'h'
      config.i = 'j'
    end
    expected = { e: 'f', g: 'h', i: 'j' }
    result.should be(dsl)
    target.should == expected
  end

  context "with restricted keys" do

    let(:options){ { attrs: { target => [ :a ] } } }

    it "should raise a key error for a unknown key with instance evaluation" do
      lambda{ dsl.configure{ b 'c' } }.should raise_error(Mutaconf::KeyError, /'b'/)
    end

    it "should raise a key error for an unknown key with a configuration object" do
      lambda{ dsl.configure{ |config| config.b = 'c' } }.should raise_error(Mutaconf::KeyError, /'b'/)
    end
  end

  context "with restricted keys in lenient mode" do

    let(:options){ { attrs: { target => [ :a, :e ] }, lenient: true } }

    it "should configure restricted properties with instance evaluation" do
      result = dsl.configure do
        a 'b'
        c 'd'
        e 'f'
        g 'h'
      end
      expected = { a: 'b', e: 'f' }
      result.should be(dsl)
      target.should == expected
    end

    it "should configure restricted properties with a configuration object" do
      result = dsl.configure do |config|
        config.a = 'b'
        config.c = 'd'
        config.e = 'f'
        config.g = 'h'
      end
      expected = { a: 'b', e: 'f' }
      result.should be(dsl)
      target.should == expected
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mutaconf-0.1.1 spec/block_spec.rb
mutaconf-0.1.0 spec/block_spec.rb