Sha256: 2f92e60861af75c4a24f35e979762e811a245604fb5490e1fbd67622749e077a

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 KB

Contents

require 'helper'

describe Mutaconf::Target do

  subject{ Mutaconf::Target.new target }

  context "with a hash" do

    let(:target){ { a: 'z' } }

    it "should set values" do
      subject.set :a, 'b'
      subject.set :c, 'd'
      target.should == { a: 'b', c: 'd' }
    end

    it "should get values" do
      subject.get(:a).should == 'z'
    end

    it "should have all values" do
      ('a'..'z').each{ |key| subject.has?(key).should be_true }
    end
  end

  context "with an open struct" do

    let(:target){ OpenStruct.new a: 'z' }

    it "should set values" do
      subject.set :a, 'b'
      subject.set :c, 'd'
      target.a.should == 'b'
      target.c.should == 'd'
    end

    it "should get values" do
      subject.get(:a).should == 'z'
    end

    it "should have all values" do
      ('a'..'z').each{ |key| subject.has?(key).should be_true }
    end
  end

  context "with an object" do

    let(:target) do
      Class.new do
        attr_accessor :a, :c

        def initialize
          @a = 'z'
        end
      end.new
    end

    it "should set values" do
      subject.set :a, 'b'
      subject.set :c, 'd'
    end

    it "should get values" do
      subject.get(:a).should == 'z'
    end

    it "should have values corresponding to its setters" do
      subject.has?(:a).should be_true
      subject.has?(:b).should be_false
      subject.has?(:c).should be_true
      ('d'..'z').each{ |key| subject.has?(key).should be_false }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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