1
0
Fork 0
mirror of https://github.com/rubyjs/therubyrhino synced 2023-03-27 23:21:34 -04:00
therubyrhino/spec/rhino/native_object_spec.rb

41 lines
970 B
Ruby
Raw Normal View History

require File.dirname(__FILE__) + '/../spec_helper'
include Rhino
describe Rhino::NativeObject do
before(:each) do
@j = J::NativeObject.new
@o = NativeObject.new(@j)
end
it "wraps a native javascript object" do
@o["foo"] = 'bar'
2009-11-10 09:54:16 -05:00
@j.get("foo", @j).unwrap.should == "bar"
@j.put("blue",@j, "blam")
@o["blue"].should == "blam"
end
it "doesn't matter if you use a symbol or a string to set a value" do
@o[:foo] = "bar"
@o['foo'].should == "bar"
@o['baz'] = "bang"
@o[:baz].should == "bang"
end
it "returns nil when the value is null, null, or not defined" do
@o[:foo].should be_nil
end
2009-10-06 10:04:57 -04:00
describe Enumerable do
it "enumerates according to native keys and values" do
@j.put("foo", @j, 'bar')
@j.put("bang", @j, 'baz')
@j.put(5, @j, 'flip')
@o.inject({}) {|i,p| k,v = p; i.tap {i[k] = v}}.should == {"foo" => 'bar', "bang" => 'baz', 5 => 'flip'}
end
end
end