Sha256: bbac1eb6bbfe7d5778c70b82587222a58f16de93c74f0e896ab9eb4b96e4cfb2

Contents?: true

Size: 959 Bytes

Versions: 2

Compression:

Stored size: 959 Bytes

Contents

require 'spec_helper'
module Alf
  module Support
    describe Config, '.option' do

      let(:conf1){
        Class.new(Config){
          option :ready, Boolean, false
          option :which, String, ->{ "foo" }
          option :done,  Proc, ->{ "bar" }
          option :cross, String, ->{ which.capitalize }
        }
      }

      let(:conf2){
        Class.new(Config){
          option :hello, String, "world"
        }
      }

      it 'does not mix subclasses' do
        conf1.new.should respond_to(:ready?)
        conf2.new.should_not respond_to(:ready?)
        conf1.new.should_not respond_to(:hello)
        conf2.new.should respond_to(:hello)
      end

      it 'supports procs' do
        conf1.new.which.should eq("foo")
      end

      it 'executes proc in that context' do
        conf1.new.cross.should eq("Foo")
      end

      it 'does not confuse procs' do
        conf1.new.done.should be_a(Proc)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-support/config/test_option.rb
alf-core-0.14.0 spec/unit/alf-support/config/test_option.rb