mirror of
https://github.com/rubyjs/therubyrhino
synced 2023-03-27 23:21:34 -04:00
36 lines
865 B
Ruby
36 lines
865 B
Ruby
|
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
|