Re: [MacRuby-devel] testing macruby/hotcocoa apps

2009-05-13 Thread Barry Wark
On Tue, May 12, 2009 at 3:26 PM, Jeremy Voorhis  wrote:
> I second the idea also. Tools like Squish have their place, but as a
> solo/hobbyist developer, I'd much rather put some faith in Apple's
> efforts to test that scrollbars scroll properly, buttons dispatch to
> actions, etc. and focus on how *my* code constructs views, binds data
> and generally assert that the state of my views is what I expect.
>
> On a related note, I just created my first custom view in macruby
> (just a throw-away tutorial app) and wondered what the best strategy
> for testing Cocoa graphics code might be. The most obvious answer
> would be to mock the critical parts of the API I am calling, but in
> practice I find that approach often leads to building a second
> implementation which isn't guaranteed to be any more correct than the
> code I am testing, and can become as much a liability as it is an
> asset. Does anyone know of a good model for testing graphics code that
> can actually account for how views *appear*?

Take a look at the Google Toolbox for Mac (on code.google.com). They
have an extension to the SenTesting framework (the standard unit
testing framework for ObjC) that handles this exact case. Categories
for NSView, CALayer, and UIView are already written, but any object
that can render into a CGGraphicsContext can participate. The code
compares the rendered output to a saved TIFF file (image files are
saved automatically by the framework) stored in the unit testing
bundle's Resources/ folder. We're using the GTM testing code a lot in
Core Plot (also code.google.com), an open source plotting framework
for OS X.

>
> Best,
>
> Jeremy Voorhis
>
> On Tue, May 12, 2009 at 2:45 PM, Alex Vollmer  wrote:
>> On May 11, 2009, at May 11, 11:18 PM, Matt Aimonetti wrote:
>>
>> Before I get too excited, I'd like to hear what you guys think and what you
>> believe you need to write better code?
>>
>> I love the concept, but have often found UI testing tools to be lacking. I
>> think that's because in the past I was always hoping to write *unit*-tests
>> for UIs which near-impossible to do without simply re-asserting the
>> implementation (which makes for a terrible unit-test). Having seen the
>> approach taken by Cucumber I'm more hopeful that this would get some
>> traction. Hell, even to have something that would step through all the
>> little manual scenarios automatically would be a great tool to have.
>> So, yeah, Matt. I'm all for it!
>> —Alex
>> 
>> http://alexvollmer.com
>> http://moochbot.com
>>
>>
>>
>>
>> ___
>> MacRuby-devel mailing list
>> [email protected]
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>
>>
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


[MacRuby-devel] Accessing constants/enums

2009-05-13 Thread Łukasz Adamczak
Hi,

After a few days smooth sailing and playing with MacRuby, I just hit a wall:

How do I invoke something like this in MacRuby:

[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];

I can't figure out where to find kInternetEventClass and kAEGetURL
constants. Are they available from MacRuby?

Thanks!

-- 
Regards,
Łukasz Adamczak
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] Accessing constants/enums

2009-05-13 Thread Laurent Sansonetti

Hi Łukasz,

On May 13, 2009, at 11:43 AM, Łukasz Adamczak wrote:


Hi,

After a few days smooth sailing and playing with MacRuby, I just hit  
a wall:


How do I invoke something like this in MacRuby:

[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];

I can't figure out where to find kInternetEventClass and kAEGetURL
constants. Are they available from MacRuby?


In MacRuby, in order to access C constants you must upcase the first  
letter (because constants in Ruby always start with an upcase  
character). So kInternetEventClass becomes KInternetEventClass.


Now, in your special case, these constants are defined in Carbon and  
are not available from MacRuby, because Carbon is not covered yet by  
the BridgeSupport mechanism. I would therefore recommend to define  
these constants in Ruby.


The constants in the header file are:

enum {
   kInternetEventClass = 'GURL',
   kAEGetURL = 'GURL',
   kAEFetchURL = 'FURL',
   keyAEAttaching = 'Atch'
};

Both kInternetEventClass and kAEGetURL have the same value, a four  
character code (a weird esoteric type). You can build the same thing  
in Ruby using String#unpack:


KInternetEventClass = KAEGetURL = 'GURL'.unpack('N').first
# ...
NSAppleEventManager.sharedAppleEventManager.setEventHandler self,  
andSelector: :"getUrl:withReplyEvent:", forEventClass:  
KInternetEventClass, andEventID: KAEGetURL


HTH,
Laurent
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] Key-value observing

2009-05-13 Thread Laurent Sansonetti

Hi Jeremy,

That's a pretty good idea! Could you file a bug on the tracker so that  
we do not forget about it?


Thanks,
Laurent

On May 12, 2009, at 10:18 AM, Jeremy Voorhis wrote:


Hello,

I've been learning Cocoa, Objective-C and macruby in tandem and I was
just wondering, are there any plans to integrate the key-value
observing protocol with the attr_accessor family of methods? With a
little experimentation, I found KVO is definitely possible with
macruby, but the syntax is less than ideal (transcript made with the
0.4 release).

~ % macirb

class Notifier
 attr_accessor :value
end

=> nil

class Observer
 def observeValueForKeyPath(path, ofObject:object, change:change,  
context:context) puts change end

end

=> nil

n = Notifier.new

=> #
n.addObserver(Observer.new, forKeyPath:'value', options:0,  
context:nil)

=> nil

n.value = 42

=> 42

n.setValue 42

{"kind"=>1}
=> nil

Best,

Jeremy Voorhis
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


[MacRuby-devel] [MacRuby] #252: Support key-value observing via the attr_accessor family of methods

2009-05-13 Thread MacRuby
#252: Support key-value observing via the attr_accessor family of methods
+---
 Reporter:  jvoor...@…  |   Owner:  lsansone...@…   
  
 Type:  enhancement |  Status:  new 
  
 Priority:  minor   |   Milestone:  
  
Component:  MacRuby |Keywords:  key-value observing, 
attr_accessor
+---
 As per the email thread at http://lists.macosforge.org/pipermail/macruby-
 devel/2009-May/001705.html, extend attr_accessor and attr_writer to
 support key-value observing via setter methods.

 Example:

 class Notifier
   attr_writer :value
 end

 Notifier#value= could be implemented in terms of Notifier#setValue so
 observers of Notifier receive notification when the value is changed.

-- 
Ticket URL: 
MacRuby 

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] Key-value observing

2009-05-13 Thread Jeremy Voorhis
I've created a ticket at https://www.macruby.org/trac/ticket/252. I
might be wrong as I am still grokking the Objective-C runtime, but it
seems to me that this should be easy to implement if attr_accessor and
attr_writer generate the setKey: method first and then implement #key=
in terms of setKey:. Is there some requirement that key-value setter
methods return void, or is that just by convention?

Best,

Jeremy

On Wed, May 13, 2009 at 12:00 PM, Laurent Sansonetti
 wrote:
> Hi Jeremy,
>
> That's a pretty good idea! Could you file a bug on the tracker so that we do
> not forget about it?
>
> Thanks,
> Laurent
>
> On May 12, 2009, at 10:18 AM, Jeremy Voorhis wrote:
>
>> Hello,
>>
>> I've been learning Cocoa, Objective-C and macruby in tandem and I was
>> just wondering, are there any plans to integrate the key-value
>> observing protocol with the attr_accessor family of methods? With a
>> little experimentation, I found KVO is definitely possible with
>> macruby, but the syntax is less than ideal (transcript made with the
>> 0.4 release).
>>
>> ~ % macirb

 class Notifier
  attr_accessor :value
 end
>>
>> => nil

 class Observer
  def observeValueForKeyPath(path, ofObject:object, change:change,
 context:context) puts change end
 end
>>
>> => nil

 n = Notifier.new
>>
>> => #

 n.addObserver(Observer.new, forKeyPath:'value', options:0, context:nil)
>>
>> => nil

 n.value = 42
>>
>> => 42

 n.setValue 42
>>
>> {"kind"=>1}
>> => nil
>>
>> Best,
>>
>> Jeremy Voorhis
>> ___
>> MacRuby-devel mailing list
>> [email protected]
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel