[macruby-changes] [302] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 23 13:18:35 PDT 2008
Revision: 302
http://trac.macosforge.org/projects/ruby/changeset/302
Author: eloy.de.enige at gmail.com
Date: 2008-06-23 13:18:35 -0700 (Mon, 23 Jun 2008)
Log Message:
-----------
Merged current RubyCocoa layer from git://github.com/alloy/macruby_rubycocoa_layer.git. Didn't use test_rubycocoa.rb for the test case because when it it's required together with the other test cases things break, need to investigate this further.
Added Paths:
-----------
MacRuby/trunk/lib/osx/
MacRuby/trunk/lib/osx/cocoa.rb
MacRuby/trunk/lib/osx/rubycocoa.rb
MacRuby/trunk/sample-macruby/RubyCocoa/
MacRuby/trunk/sample-macruby/RubyCocoa/HelloWorld.rb
MacRuby/trunk/sample-macruby/RubyCocoa/README
MacRuby/trunk/sample-macruby/RubyCocoa/TransparentHello.rb
MacRuby/trunk/sample-macruby/RubyCocoa/darkroom.rb
MacRuby/trunk/sample-macruby/RubyCocoa/fontnames.rb
MacRuby/trunk/sample-macruby/RubyCocoa/sndplay.rb
MacRuby/trunk/test-macruby/rubycocoa_test.rb
Added: MacRuby/trunk/lib/osx/cocoa.rb
===================================================================
--- MacRuby/trunk/lib/osx/cocoa.rb (rev 0)
+++ MacRuby/trunk/lib/osx/cocoa.rb 2008-06-23 20:18:35 UTC (rev 302)
@@ -0,0 +1,2 @@
+require File.expand_path('../rubycocoa', __FILE__)
+Kernel.framework 'AppKit'
\ No newline at end of file
Added: MacRuby/trunk/lib/osx/rubycocoa.rb
===================================================================
--- MacRuby/trunk/lib/osx/rubycocoa.rb (rev 0)
+++ MacRuby/trunk/lib/osx/rubycocoa.rb 2008-06-23 20:18:35 UTC (rev 302)
@@ -0,0 +1,102 @@
+#!/usr/bin/env macruby
+
+module Kernel
+ class << self
+ alias_method :__framework_before_rubycocoa_layer, :framework
+ def framework(f)
+ $LOADING_FRAMEWORK = true
+ __framework_before_rubycocoa_layer(f)
+ $LOADING_FRAMEWORK = false
+ end
+ end
+end
+
+class NSObject
+ class << self
+ alias_method :ib_outlets, :ib_outlet
+
+ alias_method :__method_added_before_rubycocoa_layer, :method_added
+ def method_added(mname)
+ unless $LOADING_FRAMEWORK
+ mname_str = mname.to_s
+ unless mname_str =~ /^__|\s/
+ parts = mname_str.split('_')
+ if parts.length > 1 and parts.length == instance_method(mname).arity
+ class_eval { alias_method (parts.join(':') << ':').to_sym, mname }
+ return
+ end
+ end
+ end
+ __method_added_before_rubycocoa_layer(mname)
+ end
+ end
+
+ #alias_method :__init_added_before_rubycocoa_layer, :init
+ # def init
+ # #if __init_added_before_rubycocoa_layer
+ # # p self
+ # # p initialize
+ # initialize
+ # self
+ # #end
+ # end
+
+ def objc_send(*args)
+ if args.length > 1
+ selector, new_args = '', []
+ (args.length / 2).times do
+ selector << "#{args.shift}:"
+ new_args << args.shift
+ end
+ send(selector, *new_args)
+ else
+ send(args.first)
+ end
+ end
+
+ alias_method :__method_missing_before_rubycocoa_layer, :method_missing
+ def method_missing(mname, *args, &block)
+ if (parts = mname.to_s.split('_')).length > 1
+ # if parts.first == 'super'
+ # selector = args.empty? ? parts.last : parts[1..-1].join(':') << ':'
+ # if self.class.superclass.instance_methods.include?(selector.to_sym)
+ # # and now we need to somehow call the supers implementation of the caller
+ # end
+ # end
+
+ selector = parts.join(':') << ':'
+
+ #if respond_to? selector # doesn't find objc methods yet.
+ #if respondsToSelector(selector) # need to load foundation framework, but hangs...
+ if respondsToSelector(selector) == 1
+ eval "def #{mname}(*args); send('#{selector}', *args); end"
+ return send(selector, *args)
+ end
+ end
+ __method_missing_before_rubycocoa_layer(mname, *args, &block)
+ end
+end
+
+module OSX
+ class << self
+ def require_framework(framework)
+ Kernel.framework(framework)
+ end
+
+ def method_missing(mname, *args)
+ if Kernel.respond_to? mname
+ module_eval "def #{mname}(*args); Kernel.send(:#{mname}, *args); end"
+ Kernel.send(mname, *args)
+ else
+ super
+ end
+ end
+
+ def const_missing(constant)
+ Object.const_get(constant)
+ rescue NameError
+ super
+ end
+ end
+end
+include OSX
\ No newline at end of file
Added: MacRuby/trunk/sample-macruby/RubyCocoa/HelloWorld.rb
===================================================================
--- MacRuby/trunk/sample-macruby/RubyCocoa/HelloWorld.rb (rev 0)
+++ MacRuby/trunk/sample-macruby/RubyCocoa/HelloWorld.rb 2008-06-23 20:18:35 UTC (rev 302)
@@ -0,0 +1,70 @@
+# HelloWorld.rb
+#
+# Translate HelloWorld.py of PyObjc (Python Objective-C Bridge) to
+# Ruby with RubyCocoa.
+#
+# A quick guide to runtime name mangling:
+#
+# ObjC becomes Ruby
+# [obj method] obj.method
+# [obj method: arg] obj.method(arg)
+# [obj method: arg1 withOtherArgs: arg2]
+# obj.method_withOtherArgs(arg1, arg2)
+
+require 'osx/cocoa'
+include OSX
+
+class AppDelegate < NSObject
+ def applicationDidFinishLaunching(aNotification)
+ puts "Hello, World!"
+ end
+
+ def sayHello(sender)
+ puts "Hello again, World!"
+ speak "Hello again, World!"
+ end
+
+ def speak(str)
+ script = NSAppleScript.alloc.initWithSource("say \"#{str}\"")
+ script.performSelector_withObject('executeAndReturnError:', nil)
+ end
+end
+
+if $0 == __FILE__ then
+ $stderr.print "just wait..." ; $stderr.flush
+ app = NSApplication.sharedApplication
+
+ app.setDelegate AppDelegate.alloc.init
+
+ frame = NSRect.new(NSSize.new(200.0, 300.0), NSSize.new(250.0, 100.0))
+ win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(frame, 15, 2, 0)
+ win.setTitle 'HelloWorld'
+ # floating window
+ win.setLevel 3
+
+ hel = NSButton.alloc.initWithFrame(NSRect.new(NSSize.new(10.0, 10.0), NSSize.new(80.0, 80.0)))
+ win.contentView.addSubview(hel)
+ hel.setBezelStyle(4)
+ hel.setTitle( 'Hello!' )
+ hel.setTarget( app.delegate )
+ hel.setAction( "sayHello:" )
+
+ beep = NSSound.alloc.initWithContentsOfFile_byReference( '/System/Library/Sounds/Tink.Aiff', 1 )
+ hel.setSound( beep )
+
+ bye = NSButton.alloc.initWithFrame(NSRect.new(NSSize.new(100.0, 10.0), NSSize.new(80.0, 80.0)))
+ win.contentView.addSubview bye
+ bye.setBezelStyle 4
+ bye.setTarget app
+ bye.setAction 'stop:'
+ bye.setEnabled true
+ bye.setTitle 'Goodbye!'
+
+ adios = NSSound.alloc.initWithContentsOfFile_byReference('/System/Library/Sounds/Basso.aiff', true)
+ bye.setSound( adios )
+
+ win.display
+ win.orderFrontRegardless
+
+ app.run
+end
Added: MacRuby/trunk/sample-macruby/RubyCocoa/README
===================================================================
--- MacRuby/trunk/sample-macruby/RubyCocoa/README (rev 0)
+++ MacRuby/trunk/sample-macruby/RubyCocoa/README 2008-06-23 20:18:35 UTC (rev 302)
@@ -0,0 +1,5 @@
+sndplay.rb - Works.
+HelloWorld.rb - Sometimes hangs when pushing the hello button.
+fontnames.rb - Works.
+darkroom.rb - Works (when used with these options: --output=google.png --height=600 http://google.com, there's a bug in darkroom which triggers when a height isn't specified). But needed to move #initialize code into #init because #initialize isn't called when used with alloc.init. However #init can't be used either in a real RubyCocoa way, because that would mean calling super_init which also isn't implemented yet.
+TransparentHello.rb - Works, but trying to interrupt the runloop doesn't work.
\ No newline at end of file
Added: MacRuby/trunk/sample-macruby/RubyCocoa/TransparentHello.rb
===================================================================
--- MacRuby/trunk/sample-macruby/RubyCocoa/TransparentHello.rb (rev 0)
+++ MacRuby/trunk/sample-macruby/RubyCocoa/TransparentHello.rb 2008-06-23 20:18:35 UTC (rev 302)
@@ -0,0 +1,88 @@
+#
+# written by Chris Thomas for the article of DDJ May 2002.
+#
+
+require 'osx/cocoa'
+
+class HelloView < OSX::NSView
+ #
+ # When the Cocoa view system wants to draw a view,
+ # it calls the method -(void)drawRect:(NSRect)rect.
+ # The rectangle argument is relative to the origin
+ # of the view's frame, and it may only be a small
+ # portion of the view. For this reason, very
+ # simple views with only one or two graphical
+ # elements tend to ignore this parameter.
+ #
+ def drawRect(rect)
+
+ # Set the window background to transparent
+ OSX::NSColor.clearColor.set
+ OSX::NSRectFill(bounds)
+
+ # Draw the text in a shade of red and in a large system font
+ attributes = OSX::NSMutableDictionary.alloc.init
+
+ attributes.setObject_forKey(OSX::NSColor.redColor, OSX::NSForegroundColorAttributeName)
+ attributes.setObject_forKey(OSX::NSFont.boldSystemFontOfSize(48.0), OSX::NSFontAttributeName)
+
+ string = OSX::NSString.alloc.initWithString( "Hello, Ruby Baby" )
+ string.drawAtPoint_withAttributes(OSX::NSSize.new(0,0), attributes)
+
+ #
+ # Turn the window's shadow off and on --
+ # This is a kludge to get the shadow to recalculate
+ # for the new shape of the opaque window content.
+ #
+ viewWindow = window
+ window.setHasShadow(0)
+ window.setHasShadow(1)
+ end
+end
+
+#
+# If this file is the main file, then perform the followjng commands.
+# (This construct is often useful for adding simple unit tests to
+# library code.)
+#
+if __FILE__ == $0
+ #
+ # First, to establish a connection to the window server,
+ # we must initialize the application
+ #
+ $stderr.print "just wait ..." ; $stderr.flush
+ application = OSX::NSApplication.sharedApplication
+
+ # Create the window
+ window = OSX::NSWindow.alloc.
+ objc_send(:initWithContentRect, OSX::NSRect.new(OSX::NSSize.new(0, 0), OSX::NSSize.new(450, 200)),
+ :styleMask, OSX::NSBorderlessWindowMask,
+ :backing, OSX::NSBackingStoreBuffered,
+ :defer, 0)
+ # Allow the window to be partially transparent
+ window.setOpaque(0)
+
+ # Setup the window's root view
+ view = HelloView.alloc.initWithFrame(OSX::NSRect.new(OSX::NSSize.new(0, 0), OSX::NSSize.new(450, 200)))
+ window.setContentView(view)
+
+ # Place the window near the top of the screen.
+ # (Screen coordinates in Cocoa are always PostScript
+ # coordinates, which start from the bottom of the screen
+ # and increase as they go up, so we have to do some math
+ # to place the window at 100 pixels from the top of the
+ # screen.
+ #
+ screenFrame = OSX::NSScreen.mainScreen.frame
+ windowOriginPoint = OSX::NSSize.new(40, screenFrame.origin.y + screenFrame.size.height - 100)
+ window.setFrameOrigin( windowOriginPoint )
+
+ # Show the window
+ window.makeKeyAndOrderFront(nil)
+ window.orderFrontRegardless() ## but this one does
+
+ # And start the application event loop
+ $stderr.print "\rtype `Ctrl-C' for quit !\n"
+ trap('SIGINT') { $stderr.puts "bye." ; exit 0 }
+ application.run
+end
Added: MacRuby/trunk/sample-macruby/RubyCocoa/darkroom.rb
===================================================================
--- MacRuby/trunk/sample-macruby/RubyCocoa/darkroom.rb (rev 0)
+++ MacRuby/trunk/sample-macruby/RubyCocoa/darkroom.rb 2008-06-23 20:18:35 UTC (rev 302)
@@ -0,0 +1,128 @@
+#!/usr/bin/env ruby
+#
+# DarkRoom
+# Takes fullsize screenshots of a web page.
+# Copyright (c) 2007 Justin Palmer.
+#
+# Released under an MIT LICENSE
+#
+# Usage
+# ====
+# ruby ./darkroom.rb http://activereload.net
+# ruby ./darkroom.rb --output=google.png http://google.com
+# ruby ./darkroom.rb --width=400 --delay=5 http://yahoo.com
+#
+# As a fix for the current bug specify a height:
+# macruby darkroom.rb --output=google.png --height=600 http://google.com
+require 'optparse'
+require 'osx/cocoa'
+OSX.require_framework 'Webkit'
+
+module ActiveReload
+ module DarkRoom
+ USER_AGENT = "DarkRoom/0.1"
+ class Photographer
+ def initialize
+ options = {}
+ opts = OptionParser.new do |opts|
+ opts.banner = "Usage: #$0 [options] URL"
+
+ opts.on('-w', '--width=[WIDTH]', Integer, 'Force width of the screenshot') do |v|
+ options[:width] = v
+ end
+
+ opts.on('-h', '--height=[HEIGHT]', Integer, 'Force height of screenshot') do |v|
+ options[:height] = v
+ end
+
+ opts.on('-o', '--output=[FILENAME]', String, 'Specify filename for saving') do |v|
+ options[:output] = v
+ end
+
+ opts.on('-d', '--delay=[DELAY]', Integer, 'Delay in seconds to give web page assets time to load') do |v|
+ options[:delay] = v
+ end
+
+ opts.on_tail('-h', '--help', 'Display this message and exit') do
+ puts opts
+ exit
+ end
+ end.parse!
+ options[:width] ||= 1024
+ options[:height] ||= 0
+ options[:website] = ARGV.first || 'http://google.com'
+ Camera.shoot(options)
+ end
+ end
+
+ class Camera
+ def self.shoot(options)
+ app = OSX::NSApplication.sharedApplication
+ delegate = Processor.alloc.init!
+ delegate.options = options
+ app.setDelegate(delegate)
+ app.run
+ end
+ end
+
+ class Processor < OSX::NSObject
+ include OSX
+ attr_accessor :options, :web_view
+
+ # def initialize
+ # #puts 'inits'
+ # rect = [-16000.0, -16000.0, 100, 100]
+ # win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(rect, NSBorderlessWindowMask, 2, 0)
+ #
+ # @web_view = WebView.alloc.initWithFrame(rect)
+ # @web_view.mainFrame.frameView.setAllowsScrolling(false)
+ # @web_view.setApplicationNameForUserAgent(USER_AGENT)
+ # @web_view.setFrameLoadDelegate(self)
+ #
+ # win.setContentView(@web_view)
+ # end
+
+ def init!
+ if init
+ rect = NSRect.new(NSSize.new(-16000.0, -16000.0), NSSize.new(100, 100))
+ win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(rect, OSX::NSBorderlessWindowMask, 2, 0)
+
+ @web_view = WebView.alloc.initWithFrame(rect)
+ @web_view.mainFrame.frameView.setAllowsScrolling(false)
+ @web_view.setApplicationNameForUserAgent(USER_AGENT)
+ @web_view.setFrameLoadDelegate(self)
+ win.setContentView(@web_view)
+
+ self
+ end
+ end
+
+ def applicationDidFinishLaunching(notification)
+ @options[:output] ||= "#{Time.now.strftime('%m-%d-%y-%H%I%S')}.png"
+ @web_view.window.setContentSize(NSSize.new(@options[:width], @options[:height]))
+ @web_view.setFrameSize(NSSize.new(@options[:width], @options[:height]))
+ @web_view.mainFrame.loadRequest(NSURLRequest.requestWithURL(NSURL.URLWithString(@options[:website])))
+ end
+
+ def webView_didFinishLoadForFrame(web_view, frame)
+ viewport = web_view.mainFrame.frameView.documentView
+ viewport.window.orderFront(nil)
+ viewport.window.display
+ viewport.window.setContentSize(NSSize.new(@options[:width], (@options[:height] > 0 ? @options[:height] : viewport.bounds.height)))
+ viewport.setFrame(viewport.bounds)
+ sleep(@options[:delay]) if @options[:delay]
+ capture_and_save(viewport)
+ end
+
+ def capture_and_save(view)
+ view.lockFocus
+ bitmap = NSBitmapImageRep.alloc.initWithFocusedViewRect(view.bounds)
+ view.unlockFocus
+
+ bitmap.representationUsingType_properties(OSX::NSPNGFileType, nil).writeToFile_atomically(@options[:output], true)
+ NSApplication.sharedApplication.terminate(nil)
+ end
+ end
+ end
+end
+ActiveReload::DarkRoom::Photographer.new
Added: MacRuby/trunk/sample-macruby/RubyCocoa/fontnames.rb
===================================================================
--- MacRuby/trunk/sample-macruby/RubyCocoa/fontnames.rb (rev 0)
+++ MacRuby/trunk/sample-macruby/RubyCocoa/fontnames.rb 2008-06-23 20:18:35 UTC (rev 302)
@@ -0,0 +1,11 @@
+require 'osx/cocoa'
+
+fmgr = OSX::NSFontManager.sharedFontManager
+
+puts "## all fonts ##"
+fonts = fmgr.availableFonts.to_a.map{|i| i.to_s }
+fonts.each {|i| puts i }
+
+puts "## fixed pitch fonts ##"
+fixedfonts = fmgr.availableFontNamesWithTraits(OSX::NSFixedPitchFontMask).to_a
+fixedfonts.each {|i| puts i.to_s }
\ No newline at end of file
Added: MacRuby/trunk/sample-macruby/RubyCocoa/sndplay.rb
===================================================================
--- MacRuby/trunk/sample-macruby/RubyCocoa/sndplay.rb (rev 0)
+++ MacRuby/trunk/sample-macruby/RubyCocoa/sndplay.rb 2008-06-23 20:18:35 UTC (rev 302)
@@ -0,0 +1,14 @@
+require 'osx/cocoa'
+
+snd_files =
+ if ARGV.size == 0 then
+ `ls /System/Library/Sounds/*.aiff`.split
+ else
+ ARGV
+ end
+
+snd_files.each do |path|
+ snd = OSX::NSSound.alloc.initWithContentsOfFile_byReference(path, true)
+ snd.play
+ sleep 0.25 while snd.playing?
+end
\ No newline at end of file
Added: MacRuby/trunk/test-macruby/rubycocoa_test.rb
===================================================================
--- MacRuby/trunk/test-macruby/rubycocoa_test.rb (rev 0)
+++ MacRuby/trunk/test-macruby/rubycocoa_test.rb 2008-06-23 20:18:35 UTC (rev 302)
@@ -0,0 +1,151 @@
+#!/usr/local/bin/macruby
+
+require "test/spec"
+require 'mocha'
+require 'osx/cocoa'
+
+class TestRubyCocoaStyleMethod < OSX::NSObject
+ def initialize
+ @set_from_initialize = 'represent!'
+ end
+
+ def perform_selector_with_object(sel, obj)
+ callMethod_withArgs(sel, obj)
+ end
+
+ def callMethod(method, withArgs:args)
+ send(method, *args)
+ end
+
+ def method_rubyCocoaStyle_withExtraArg(mname, rc_style, arg)
+ "#{mname}(#{rc_style}, #{arg})"
+ end
+end
+
+class TestRubyCocoaStyleSuperMethod < OSX::NSObject
+ def init
+ self if super_init
+ end
+end
+
+class NSObjectSubclassWithInitialize < OSX::NSObject
+ def initialize
+ @set_from_initialize = 'represent!'
+ end
+end
+
+class NSObjectSubclassWithoutInitialize < OSX::NSObject; end
+
+CONSTANT_IN_THE_TOPLEVEL_OBJECT_INSTEAD_OF_OSX = true
+
+describe "RubyCocoa layer, in general" do
+ xit "should load AppKit when the osx/cocoa file is loaded" do
+ Kernel.expects(:framework).with('AppKit')
+ load 'osx/cocoa.rb'
+ end
+
+ it "should still raise a RuntimeError" do
+ lambda { Kernel.framework 'Foo' }.should.raise RuntimeError
+ end
+
+ it "should set a global variable which indicates that a framework is being loaded" do
+ Kernel.expects(:__framework_before_rubycocoa_layer).with do |f|
+ $LOADING_FRAMEWORK.should.be true
+ f == 'Foo'
+ end
+ Kernel.framework 'Foo'
+ $LOADING_FRAMEWORK.should.be false
+ end
+end
+
+describe "NSObject additions" do
+ before do
+ @obj = TestRubyCocoaStyleMethod.alloc.init
+ end
+
+ it "should alias ib_outlet to ib_outlets" do
+ TestRubyCocoaStyleMethod.private_methods.should.include :ib_outlets
+ end
+
+ it "should call initialize from init if it exists" do
+ NSObjectSubclassWithInitialize.alloc.init.instance_variable_get(:@set_from_initialize).should == 'represent!'
+ NSObjectSubclassWithoutInitialize.alloc.init.instance_variable_get(:@set_from_initialize).should.be nil
+ end
+
+ it "should catch RubyCocoa style method names, call the correct method and define a shortcut method" do
+ @obj.perform_selector_with_object('description', nil).should.match /^<TestRubyCocoaStyleMethod/
+ @obj.respond_to?(:callMethod_withArgs).should.be true
+ @obj.perform_selector_with_object('description', nil).should.match /^<TestRubyCocoaStyleMethod/
+ end
+
+ it "should also catch RubyCocoa style methods that end with a underscore" do
+ @obj.callMethod_withArgs_('description', nil).should.match /^<TestRubyCocoaStyleMethod/
+ @obj.respond_to?(:callMethod_withArgs_).should.be true
+ end
+
+ it "should also work on other regular NSObject subclasses" do
+ nsstring = 'foo'
+ nsstring.insertString_atIndex('bar', 3)
+ nsstring.should == 'foobar'
+ end
+
+ it "should still raise a NoMethodError if the selector doesn't exist (or rather call the previous implementation)" do
+ lambda { @obj.does_not_exist }.should.raise NoMethodError
+ lambda { @obj.doesnotexist_ }.should.raise NoMethodError
+ lambda { @obj.doesnotexist }.should.raise NoMethodError
+ end
+
+ it "should be possible to call super methods" do
+ lambda { TestRubyCocoaStyleSuperMethod.alloc.init }.should.not.raise.exception
+ end
+
+ it "should handle objc_send style methods" do
+ nsstring = 'foo'
+ nsstring.objc_send(:insertString, 'bar', :atIndex, 3)
+ nsstring.should == 'foobar'
+ nsstring.objc_send(:description).should == 'foobar'
+ lambda { nsstring.objc_send(:does_not_exist) }.should.raise NoMethodError
+ end
+
+ it "should create MacRuby style method aliases for any method containing underscores" do
+ @obj.respond_to?(:"method:rubyCocoaStyle:withExtraArg:").should.be true
+ @obj.method('foo', rubyCocoaStyle:true, withExtraArg:false).should == 'foo(true, false)'
+ end
+end
+
+describe 'OSX module' do
+ it "should exist" do
+ defined?(OSX).should.not.be nil # this is weird.. I haven't defined OSX yet?!
+ end
+
+ it "should load a framework into the runtime" do
+ OSX.require_framework 'WebKit'
+ defined?(WebView).should.not.be nil
+
+ OSX.require_framework '/System/Library/Frameworks/QTKit.framework'
+ defined?(QTMovie).should.not.be nil
+ end
+
+ it "should forward messages to Kernel if it responds to it" do
+ Kernel.expects(:NSRectFill).with(1, 2).times(2)
+ OSX::NSRectFill(1, 2)
+ OSX.respond_to?(:NSRectFill).should.be true
+ OSX::NSRectFill(1, 2)
+
+ lambda { OSX::NSRectFillllllll(1, 2) }.should.raise NoMethodError
+ end
+
+ it "should try to get missing constants from the toplevel object" do
+ OSX::CONSTANT_IN_THE_TOPLEVEL_OBJECT_INSTEAD_OF_OSX.should.be true
+ end
+
+ it "should still raise a NameError from OSX not the toplevel object" do
+ lambda { OSX::DOES_NOT_EXIST_IN_TOPLEVEL_OBJECT }.should.raise NameError
+
+ begin
+ OSX::DOES_NOT_EXIST_IN_TOPLEVEL_OBJECT
+ rescue NameError => e
+ e.message.should.include 'OSX::DOES_NOT_EXIST_IN_TOPLEVEL_OBJECT'
+ end
+ end
+end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080623/f5f3bc85/attachment-0001.htm
More information about the macruby-changes
mailing list