Sha256: 46596525dc811b9603fd74dfe25c8b7871c9c6924ec07982ef6ab861a0b5b8da

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require "wlang"
describe "WLang's version of BasicObject" do
  
  class A 
    # Methods that we keep
    KEPT_METHODS = ["__send__", "__id__", "instance_eval", "initialize", 
                    "object_id", "nil?", "singleton_method_added", "__clean_scope__",
                    "singleton_method_undefined"]

    def self.__clean_scope__
      # Removes all methods that are not needed to the class
      (instance_methods + private_instance_methods).each do |m|
        undef_method(m.to_s.to_sym) unless KEPT_METHODS.include?(m.to_s)
      end
    end
    __clean_scope__
  end
  
  it "should not have kernel methods except certain" do
    [:puts, :to_s, :hash].each do |sym|
      begin
        A.new.instance_eval{ __send__(sym, []) }
        "Not pass here".should == ""
      rescue NoMethodError 
        true.should == true
      end
    end
  end
  
  it "should not gain methods when requiring gems" do
    Kernel.load(File.join(File.dirname(__FILE__),"global_extensions.rb"))
    begin
      A.new.__clean_scope__.instance_eval{ hello_world }
      "Not pass here".should == ""
    rescue NoMethodError 
      true.should == true
    end
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wlang-0.10.0 test/spec/basic_object.spec
wlang-0.9.2 test/spec/basic_object.spec
wlang-0.9.1 test/spec/basic_object.spec