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

36 lines
865 B
Ruby
Raw Normal View History

2009-09-24 20:06:31 -04:00
require File.dirname(__FILE__) + '/../spec_helper'
describe Rhino::Context do
include Rhino
it "can evaluate some javascript" do
Rhino::Context.open do |cxt|
cxt.evaljs("5 + 3").should == 8
end
end
it "can embed ruby object into javascript" do
Rhino::Context.open do |cxt|
cxt.standard do |scope|
scope.put("foo", scope, "Hello World")
cxt.evaljs("foo", scope).should == "Hello World"
end
end
end
it "can call ruby functions from javascript" do
Rhino::Context.open do |cxt|
cxt.standard do |scope|
scope.put("say", scope, function {|word, times| word * times})
cxt.evaljs("say('Hello',2)", scope).should == "HelloHello"
end
end
end
it "has a private constructor" do
lambda {
Rhino::Context.new(nil)
}.should raise_error
end
end