My theoretical GSpec

Yesterday I went bonkers over a Google talk on RSpec and even managed a half-baked version of the idea in a few lines of Groovy. (To be honest the RSpec project is way more involved than my humble Groovy 10-15 liner.) Today I’d just like to point out my biggest hurdle in trying to implement GSpec, stoopidity! Not that I’m stoopid, but that I have limited knowledge of Groovy and Ruby and such limits played out in my code example. The problem I had was with method and property interception. I tried the first thing that came to mind which was Categories and that fell apart due to what I believe was recursion. (The intercepted method was being delegated to in the interceptor.) I hit the delete key on my category class but I think it looked something like this:

class GSpecMethods {
   static Object getProperty(GroovyObject obj, String name) {
      if(name.startsWith('should_be_')) {
	 def prop = obj.getProperty(obj, name.substring(10))
	 assert true == prop : name
	 return prop
      else return obj.getProperty(obj, name)

That didn’t work out too well so I tried walking around recursion by using the MetaClass approach. The first couple of iterations were mixed in with the Category approach, (in the category I’d ask the object’s meta-class to get the real property) then the final iterations resulted in what I posted yesterday. I’m really new to M.O.P. (but not to M.O.P.) and method interception so if you have any clues or terrific ideas on how to best add dynamic properties to objects within a given context then drop your science below. I’d like to play with the GSpec idea a little more until I get it right. (…or at least until I get bored of it and toss it aside like my half working PC media center that only plays in black and white and doesn’t support remote control or the incomplete game of chess I started with myself many years ago where I couldn’t remember if it was my move or my move or the new storm door we bought over the summer that’s assembled but sitting in our basement because I didn’t have the right tools to cut it to the size of my door frame, or did I mention Groovy Invaders? Ok, that one I will finish, I promise. I just haven’t been able to configure my development environment at home correctly and I keep getting CNF exceptions that don’t make sense.) Hit me up people…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s