|
654 | 654 |
|
655 | 655 | # end |
656 | 656 |
|
657 | | -# describe "Calling JavaScript Code From Within Ruby", :compat => '0.1.0' do |
| 657 | + describe "Calling JavaScript Code From Within Ruby", :compat => '0.1.0' do |
658 | 658 |
|
659 | | -# before(:each) do |
660 | | -# @cxt = V8::Context.new |
661 | | -# end |
| 659 | + before(:each) do |
| 660 | + @cxt = V8::Context.new |
| 661 | + end |
662 | 662 |
|
663 | | -# xit "allows you to capture a reference to a javascript function and call it" do |
664 | | -# f = @cxt.eval('(function add(lhs, rhs) {return lhs + rhs})') |
665 | | -# f.call(1,2).should == 3 |
666 | | -# end |
| 663 | + it "allows you to capture a reference to a javascript function and call it" do |
| 664 | + f = @cxt.eval('(function add(lhs, rhs) {return lhs + rhs})') |
| 665 | + expect(f.call 1,2).to eql 3 |
| 666 | + end |
667 | 667 |
|
668 | | -# xit "can path the 'this' object into a function as context with methodcall()" do |
669 | | -# obj = @cxt.eval('({num: 5})') |
670 | | -# times = @cxt.eval('(function times(num) {return this.num * num})') |
671 | | -# times.methodcall(obj, 5).should == 25 |
672 | | -# end |
| 668 | + it "can path the 'this' object into a function as context with methodcall()" do |
| 669 | + obj = @cxt.eval('({num: 5})') |
| 670 | + times = @cxt.eval('(function times(num) {return this.num * num})') |
| 671 | + expect(times.methodcall obj, 5).to eql 25 |
| 672 | + end |
673 | 673 |
|
674 | | -# xit "unwraps objects that are backed by javascript objects to pass their native equivalents" do |
675 | | -# @cxt.eval('obj = {foo: "bar"}') |
676 | | -# f = @cxt.eval('(function() {return this == obj})') |
677 | | -# f.methodcall(@cxt['obj']).should be(true) |
678 | | -# end |
| 674 | + it "unwraps objects that are backed by javascript objects to pass their native equivalents" do |
| 675 | + @cxt.eval('obj = {foo: "bar"}') |
| 676 | + f = @cxt.eval('(function() {return this == obj})') |
| 677 | + expect(f.methodcall @cxt['obj']).to be true |
| 678 | + end |
679 | 679 |
|
680 | | -# xit "can invoke a javacript constructor and return the new object reflected into ruby" do |
681 | | -# wrapper = @cxt.eval('(function Wrapper(value) {this.value = value})') |
682 | | -# wrapper.new(5)['value'].should == 5 |
683 | | -# end |
| 680 | + it "can invoke a javacript constructor and return the new object reflected into ruby" do |
| 681 | + wrapper = @cxt.eval('(function Wrapper(value) {this.value = value})') |
| 682 | + wrapper.new(5)['value'].should == 5 |
| 683 | + end |
684 | 684 |
|
685 | | -# xit "can call a javascript method directly from a ruby object" do |
686 | | -# obj = @cxt.eval('Object').new |
687 | | -# obj.should respond_to(:toString) |
688 | | -# obj.toString().should == '[object Object]' |
689 | | -# end |
| 685 | + it "can call a javascript method directly from a ruby object" do |
| 686 | + obj = @cxt.eval('Object').new |
| 687 | + expect(obj).to respond_to(:toString) |
| 688 | + expect(obj.toString()).to eql '[object Object]' |
| 689 | + end |
690 | 690 |
|
691 | | -# xit "can access properties defined on a javascript object through ruby" do |
692 | | -# obj = @cxt.eval('({ str: "bar", num: 5 })') |
693 | | -# obj.str.should == "bar" |
694 | | -# obj.num.should == 5 |
695 | | -# end |
| 691 | + it "can access properties defined on a javascript object through ruby" do |
| 692 | + obj = @cxt.eval('({ str: "bar", num: 5 })') |
| 693 | + expect(obj.str).to eql "bar" |
| 694 | + expect(obj.num).to eql 5 |
| 695 | + end |
696 | 696 |
|
697 | 697 | # xit "can set properties on the javascript object via ruby setter methods" do |
698 | 698 | # obj = @cxt.eval('({ str: "bar", num: 5 })') |
|
706 | 706 | # obj.array.to_a.should == [1,2,3] |
707 | 707 | # end |
708 | 708 |
|
709 | | -# xit "is an error to try and pass parameters to a property" do |
710 | | -# obj = @cxt.eval('({num: 1})') |
711 | | -# lambda { |
712 | | -# obj.num(5) |
713 | | -# }.should raise_error(ArgumentError) |
714 | | -# end |
715 | | -# end |
| 709 | + it "is an error to try and pass parameters to a property" do |
| 710 | + obj = @cxt.eval('({num: 1})') |
| 711 | + expect { obj.num(5) }.to raise_error(ArgumentError) |
| 712 | + end |
| 713 | + end |
716 | 714 |
|
717 | 715 | # describe "Setting up the Host Environment", :compat => '0.1.0' do |
718 | 716 |
|
|
0 commit comments