Sha256: 7030fc12799a9eef7318080c670c97da801ca29c967f7f4073113af9a49c4558

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'
module WLang
  class Scope
    describe ObjectScope do

      it 'implements fetch through [] if a Hash' do
        scope = Scope.coerce(:who => "World")
        scope.fetch(:who).should eq("World")
      end

      it 'supports any obj that responds to :has_key?' do
        subj = Object.new.tap{|x|
          def x.has_key?(k); true; end
          def x.[](k); "World"; end
        }
        scope = Scope.coerce(subj)
        scope.fetch(:who).should eq("World")
      end

      it 'falls back to send' do
        subj = Struct.new(:who).new("World")
        scope = Scope.coerce(subj)
        scope.fetch(:who).should eq("World")
      end

      it 'delegates fetch to its parent when not found' do
        scope = Scope.coerce(12, Scope.coerce({:who => "World"}))
        scope.fetch(:who).should eq("World")
      end

      it 'fetches `self` correctly' do
        scope = Scope.coerce(12)
        scope.fetch(:self).should eq(12)
      end

    end # describe ObjectScope
  end # class Scope
end # module WLang

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wlang-2.0.1 spec/unit/scope/test_object_scope.rb
wlang-2.0.0 spec/unit/scope/test_object_scope.rb
wlang-2.0.0.beta spec/unit/scope/test_object_scope.rb