Skip to content

Commit

Permalink
added preliminary specs for the MacRuby class
Browse files Browse the repository at this point in the history
  • Loading branch information
lrz committed May 5, 2009
1 parent 07580b1 commit 9cee3ff
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/macruby/fixtures/test_objc1.rb
@@ -0,0 +1 @@
1+2
1 change: 1 addition & 0 deletions spec/macruby/fixtures/test_objc2.rb
@@ -0,0 +1 @@
foo
46 changes: 46 additions & 0 deletions 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

0 comments on commit 9cee3ff

Please sign in to comment.