From 9cee3ff4c65d577e08de86cb5737a44e38c53c8c Mon Sep 17 00:00:00 2001 From: Laurent Sansonetti Date: Tue, 5 May 2009 22:50:52 +0000 Subject: [PATCH] added preliminary specs for the MacRuby class git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental@1537 23306eb0-4c56-4727-a40e-e92c0eb68959 --- spec/macruby/fixtures/test_objc1.rb | 1 + spec/macruby/fixtures/test_objc2.rb | 1 + spec/macruby/objc_spec.rb | 46 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 spec/macruby/fixtures/test_objc1.rb create mode 100644 spec/macruby/fixtures/test_objc2.rb create mode 100644 spec/macruby/objc_spec.rb diff --git a/spec/macruby/fixtures/test_objc1.rb b/spec/macruby/fixtures/test_objc1.rb new file mode 100644 index 000000000..19f508412 --- /dev/null +++ b/spec/macruby/fixtures/test_objc1.rb @@ -0,0 +1 @@ +1+2 diff --git a/spec/macruby/fixtures/test_objc2.rb b/spec/macruby/fixtures/test_objc2.rb new file mode 100644 index 000000000..257cc5642 --- /dev/null +++ b/spec/macruby/fixtures/test_objc2.rb @@ -0,0 +1 @@ +foo diff --git a/spec/macruby/objc_spec.rb b/spec/macruby/objc_spec.rb new file mode 100644 index 000000000..d12f70f67 --- /dev/null +++ b/spec/macruby/objc_spec.rb @@ -0,0 +1,46 @@ +require File.dirname(__FILE__) + "/spec_helper" +# TODO: the MacRuby class should also be tested from Objective-C. +#FixtureCompiler.require! "objc" + +describe "-[MacRuby sharedRuntime]" do + before :each do + @r = MacRuby.sharedRuntime + end + + it "initializes and return a singleton instance representing the runtime" do + @r.class.should == MacRuby + @r.should == MacRuby.sharedRuntime + end + + it "can evaluate a given Ruby expression" do + o = @r.evaluateString('1+2') + o.class.should == Fixnum + o.should == 3 + + lambda { @r.evaluateString('1+') }.should raise_error(SyntaxError) + lambda { @r.evaluateString('foo') }.should raise_error(NameError) + end + + it "can evaluate a given Ruby file using a path or an URL" do + p1 = File.dirname(__FILE__) + '/fixtures/test_objc1.rb' + p2 = File.dirname(__FILE__) + '/fixtures/test_objc2.rb' + + o = @r.evaluateFileAtPath(p1) + o.class.should == Fixnum + o.should == 3 + + o = @r.evaluateFileAtURL(NSURL.fileURLWithPath(p1)) + o.class.should == Fixnum + o.should == 3 + + lambda { @r.evaluateFileAtPath(p2) }.should raise_error(NameError) + lambda { @r.evaluateFileAtURL(NSURL.fileURLWithPath(p2)) }.should raise_error(NameError) + + # TODO: add tests that should raise_error for the following cases: + # - given path is nil + # - given path does not exist + # - given URL is nil + # - given file:// URL does not exist + # - given URL is not file:// + end +end