Sha256: 6b28fd10474dce7a82faca2adc275ea95d0f5d2ae6588b268d80adc539ad1c7d

Contents?: true

Size: 975 Bytes

Versions: 5

Compression:

Stored size: 975 Bytes

Contents

require 'helper'

describe "Mutaconf.extract" do

  class Source
    attr_accessor :a, :c

    def initialize
      @a, @c = 'b', 'd'
    end
  end

  it "should extract properties from a hash" do
    s = { a: 'b', c: 'd' }
    Mutaconf.extract(s, :a).should == 'b'
    Mutaconf.extract(s, :c).should == 'd'
    Mutaconf.extract(s, :e).should be_nil
  end

  it "should extract properties from an open struct" do
    s = OpenStruct.new a: 'b', c: 'd'
    Mutaconf.extract(s, :a).should == 'b'
    Mutaconf.extract(s, :c).should == 'd'
    Mutaconf.extract(s, :e).should be_nil
  end

  it "should extract properties from an object" do
    s = Source.new
    Mutaconf.extract(s, :a).should == 'b'
    Mutaconf.extract(s, :c).should == 'd'
    lambda{ Mutaconf.extract s, :e }.should raise_error(NoMethodError)
  end

  it "should return a string or symbol" do
    Mutaconf.extract('string', :a).should == 'string'
    Mutaconf.extract(:symbol, :c).should == :symbol
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mutaconf-0.1.1 spec/extract_spec.rb
mutaconf-0.1.0 spec/extract_spec.rb
mutaconf-0.0.7 spec/extract_spec.rb
mutaconf-0.0.6 spec/extract_spec.rb
mutaconf-0.0.5 spec/extract_spec.rb