Sha256: f6e19e45e190f8cd3fc26b1747f4a725dc47d9bafd124b66b3cbd3053b011152

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe Peony do
  describe 'Scope' do
    it 'should can set and get value' do
      root_scope = Peony::Scope.new(:root)
      scope = Peony::Scope.new(:my, root_scope)
      root_scope[:a], scope[:b] = 1, 2

      scope.has_key?(:a).should be_true
      scope.key?(:a).should be_true
      scope.include?(:a).should be_true
      scope.local?(:a).should be_false

      scope[:a].should == 1
      scope.set(:a, 2)
      scope[:a].should == 2
      root_scope[:a].should == 2

      scope[:b].should == 2
      root_scope[:b].should == nil
      scope.set(:b, 3)
      scope[:b].should == 3
      root_scope[:b].should == nil

      root_scope.set(:b, 5)
      scope[:b].should == 3
      root_scope[:b].should == 5

      scope.local(:a, 6)
      scope[:a].should == 6
      root_scope[:a].should == 2
      scope[:a] = 8
      scope[:a].should == 8
      root_scope[:a].should == 2

      scope.a.should == 8
      root_scope.a.should == 2
      scope.a?.should be_true

      scope.delete(:a)
      scope[:a] = 9
      scope[:a].should == 9
      root_scope[:a].should == 9

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
peony-0.3.1 spec/scope_spec.rb
peony-0.3.0 spec/scope_spec.rb