My First Turkey


I don’t normally cook but this year my wife needed a break. Working in a retil store means she has to get up at 3am and drive 45 minutes out of town to her store adjust cameras and catch crooked people in the act before the crooked people get the jump on black Friday. This year it’d be a little different. The food would not taste the same, a given, because Daddy’s at the wheel. I’m not proud because I did a great job, I’m prooud because I finally overcame my fear of large poultry. The bird was a challenge but not unsurmountable. With a little more practice the bird my even be delivered to our table with flavor come next year. Who knows? I may even be brave enough to try to rub it down before I put it in the stove. (I heard some people do this but I’m not all into birds like that!) Not knowing how long to apply heat to the beast or what amount of heat to apply I consulted the Wrox Turkey Reference. According to the TurkeyDocs one must thaw in cold water for about 8-10 hours. One must also preheat the cooking device to roughly 325 degrees. The temperature should remain consistent for the entire baking duration of the feathered animal. (Feathers should be removed prior to the application of heat.) Seasoning is optional though recommended for pleasurable consumption. Fresh vegetation can also be used for both adornment and stuffing. Lesson learned, the potatoes are strictly for adornment and are not to be placed inside the bird.

My First Turkey
My First Turkey

For a cook, I’m one heck of a programmer!

When we used to play with power


Remember the glove? Tectites??? Tectites!!! E-Honda and King Hippo? Wouble Wibble? Yes, Konami had some of the best games! Next to Capcom that is… Nobody beats the Mega-Man series! Truly the best series in all gaming history! The only thing this line up misses is Rob the robot. Was I the only one who’s parents could/wouldn’t afford the spinning gyro wonder? Why was there always at least one kid that had the entire works from the robot to the glove to the power pad? And what’s with Atari? Balance your budget with the joystick touching a single button…




Can I get a wuh, wuh?


I’ve been busy… very busy trying to save my life from people that want money… lots of money. So much money that my checkbook grabs a deposit slip and uses it to cover itself and my wallet. So busy that I couldn’t even think of posting anything worthwhile. But I can’t, you hear me, can not pass up on linking to this here. I told y’all a while ago to check out Astrid cause she gotz John Blaze stuff. Just cause you not rekognizin’ I’m gonna bring it to ya here. Seriously, I always find something entertaining when I bring up the page.

Vodpod videos no longer available.

It’s about time!!!


I restarted Idea on my Mac after several weeks of having an old project loaded and to my surprise version 8 final was reportedly released! I’d been running 8.0M1 for a while and was wondering when it would happen. Browsing the JetBrains site led me promptly to the download section where I found the promised collection of random 1s and 0s comprising the dmg file that only OSX understands. I took a minute to browse the TeamCity section because the advertisement around it looks so tempting. I almost downloaded a free trial but resisted after toying with the live demo. I must admit that I’d grown sooo comfortable with Hudson lately that everything else is a bore.

Anywayz, after my download completed I unwrapped the dmg and was pleasantly rewarded with the new splash screen. Since I was already trying to start a new project prior to downloading the update, my mouse already knew where to navigate. I crossed my fingers as I clicked “Create a new project”, followed the prompts to what I was really hoping to eventually see. Rejoice! They’ve finally added create project from Maven archetype! It’s the little things that matter and lo, how I long waited for this one common-sense feature. I tried the earlier plugins (released during the plugin contest) that promised this same functionality. I could never get satisfactory results with any of them and always had to drop down to the command line. If you’re an Idea lover like myself head out to JetBrains and grab a fresh copy of V8.0. I’m sure there’s more beyond the slick splash and new create Maven project support.

Bugs in Ruby iPhone testing


I saw it yesterday but tried to play it off. Now the problem looks severe enough for me to abandon my efforts all together. It comes down to the difference between

This:

int val = (int) [self.pins intValue];
[self.bowling roll:[NSNumber numberWithInt:val]];

And this:

int val = (int) [self.pins intValue];
[self.bowling roll:[NSNumber numberWithInt:10]];

The first example results in an error:

..../Library/Ruby/Gems/1.8/gems/rspec-1.1.11/lib/spec/mocks/error_generator.rb:67: [BUG] Bus Error
ruby 1.8.6 (2008-03-03) [universal-darwin9.0]

While the second example runs without issue. The bowling object that I’m calling is my self rolled ObjCMock wrapper. It’s starting to look really hairy now so I’m backing off. I’m not happy about giving up but experience tells me that the effort involved in resolving some of these issues would be ongoing.

Dynamic Dispatch Discrepancy


*Update*
By the way I unsuccessfully tried overriding the methods() method and almost went as far as overriding send on my mock wrapping ObjCMock class. My experience in MOP tells me that overriding send is likely rooted in trouble so I decided against it.

Yesterday’s Ruby drama ended with my finding a hack around the dropped parameters. If I was more familiar with Ruby, had more time to kill, or if it were Groovy instead then my solution would be much cleaner.

The problem:
Ruby Mocks under RSpec (have no idea if the problem persists in other Ruby scripting environments) do not receive parameters correctly from native Cocoa objects.

The hack:
Use a home-grown mock to intercept the parameter and pass along to the Ruby mock.

The code: (bowling_controller_spec.rb)

require File.dirname(__FILE__) + ‘/test_helper’

require “BowlingController.bundle”
OSX::ns_import :BowlingController
OSX::ns_import :BowlingProtocol
require ‘delegate’

include OSX

class ObjCMock
attr_accessor :delegate
def roll(num)
@delegate.roll(num)
end

# def method_missing(m, *args)
# puts “Forwarding message”
# @delegate.send(m, args)
# end

def initialize(theMock)
@delegate = theMock
end
end

describe BowlingController do
before(:each) do
@controller = BowlingController.new
@bowling = mock(‘BowlingProtocol’)
@text_field = mock(‘Pins’)
@text_field.stub!(:intValue).and_return(10)
@controller.pins = @text_field
end

it “should roll a ball” do
@controller.roll
end

it “should roll a ball and get the value from the pins outlet” do
@text_field.should_receive(:intValue).and_return(0)
@controller.roll
end

it “should be an OSX::NSObject” do
@controller.is_a?(OSX::NSObject).should == true
end

it “should have an outlet to a bowling object” do
@controller.bowling = @bowling
end

it “should send the pin value to the bowling object” do
@controller.bowling = ObjCMock.new(@bowling)
# @controller.bowling = @bowling
@bowling.should_receive(:roll).with(NSNumber.numberWithInt(10))

@controller.roll
end
end

I left in the commented out method_missing magic that doesn’t work the way I’d expect it. Ideally I’d like to tuck this wrapping mock to the side without needing to define the specific signature I’m mocking. Ideally method_missing would give me the ability to answer any message. Alas, I get “does not reckognize selector” errors from NSProxy when I enable it. I have a feeling that NSProxy probably looks through the defined methods on it’s delegate and throws this error without 1st trying to invoke the method… effectively killing any dynamic magic ability from objects passed into Cocoa land. I also have a feeling that there are a few other holes in the proxy approach with Ruby/Cocoa. If anybody happens to know the details feel free to chime in.

Ruby mock objects drop parameters


Maybe it’s me but it sure seems like Ruby mocks are dropping the parameters passed in from Objective-C. I’m about to give up on this venture into RSpec for iPhone controller code development. In my mind I see it as a huge possibility and I’m willing to give it a few more shots before I wave the white flag. Here’s what I observed so far. (Keep in mind this is coming from a guy who just learned Objective-C, XCode, Ruby, and RubyCocoa reading Apple docs in the shower this morning!) If I call into a Ruby mock passing an int primitive directly from Objective-C while running under RSpec on the 10th day of the 11th month with 3/4th of my coffee mug occupied with the ol’ black magic juice (sorry but from my mobile experience it’s definitely important to set the stage listing all of your environment variables and making sure the stars are all aligned…) then I get a program crash. If I instead pass an NSNumber object wrapping the int then the parameter is silently ignored. If I call into a simple Ruby object defined inline in the spec then the parameter seems to come through just fine. If I then wrap the Ruby Mock with my own crude inlined mock passing the value from ObjC through my mock and into the Ruby Mock then all is right with the world… abusive husbands across America stop beating their wives while they join hands and sing Koom-by-ya… aggressive drivers let you over in heavy traffic, and the DOW jumps up 200 points. To see what I mean, here’s the updated spec code from my earlier posting:

bowling_controller_spec.rb

require File.dirname(__FILE__) + ‘/test_helper’

require “BowlingController.bundle”
OSX::ns_import :BowlingController
OSX::ns_import :BowlingProtocol

include OSX

class MyMock
attr_accessor :delegate
def roll(num)
puts “Number is #{num}”
puts “Calling delegate #{@delegate}…”
@delegate.roll(num)
puts “Done with delegate…”
end
end

describe BowlingController do
before(:each) do
@controller = BowlingController.new
@bowling = mock(‘BowlingProtocol’)
@text_field = mock(‘Pins’)
@text_field.stub!(:intValue).and_return(10)
@controller.pins = @text_field
end

it “should roll a ball” do
@controller.roll
end

it “should roll a ball and get the value from the pins outlet” do
@text_field.should_receive(:intValue).and_return(0)
@controller.roll
end

it “should be an OSX::NSObject” do
@controller.is_a?(OSX::NSObject).should == true
end

it “should have an outlet to a bowling object” do
@controller.bowling = @bowling
end

it “should send the pin value to the bowling object” do
mock = MyMock.new
puts “Setting delegate to #{@bowling}”
mock.delegate = @bowling
puts “Now passing mock into real code…”
@controller.bowling = mock
# @controller.bowling = @bowling
@bowling.should_receive(:roll).with(NSNumber.numberWithInt(10))

@controller.roll
end
end

I updated the controller to use a protocol:
BowlingController.h

//
// BowlingController.h
// BowlingController
//
// Created by FIXME on 2008-11-10.
// Copyright 2008 FIXME. All rights reserved.
//

#import

@class UITextField;
@protocol BowlingProtocol;

@interface BowlingController : NSObject {
UITextField* pins;
id bowling;
}
@property (nonatomic, retain) UITextField* pins;
@property (nonatomic, retain) id bowling;

-(void) roll;
@end

bowling_controller_spec.rb

//
// BowlingController.h
// BowlingController
//
// Created by FIXME on 2008-11-10.
// Copyright 2008 FIXME. All rights reserved.
//

#import “BowlingController.h”
#import “BowlingProtocol.h”

@implementation BowlingController
@synthesize pins;
@synthesize bowling;

-(void) roll{
int val = [self.pins intValue];
[self.bowling roll:[NSNumber numberWithInt:10]];
}

@end

// This initialization function gets called when we import the Ruby module.
// It doesn’t need to do anything because the RubyCocoa bridge will do
// all the initialization work.
// The rbiphonetest test framework automatically generates bundles for
// each objective-c class containing the following line. These
// can be used by your tests.
void Init_BowlingController() { }

BowlingProtocol.h

@protocol BowlingProtocol
-(void) roll:(NSNumber*)pins;
@end

More on this later as I explore…

RSpec for iPhone development


So last night I did some laundry, taught my oldest daughter how to write code, took both of my girls shoe shopping, washed the little one’s hair, raked the leaves cooked dinner, then finally got a start on trying RSpec against a Cocoa Touch controller class. Yep, I was kinda sorta busy. Had I a little more time I wouldn’t be stumped where I am now but since my schedule is as packed as a VW beetle carrying a family of 6 on a Ski vacation for 2 months there’s little wiggle room for discovery and surprises, so instead I ask you, my humble readers (all three of you) to figure out the hard stuff for me. I will gladly repay you by splattering your hard work across the internets next to a picture of my smiling eyebrows and deep claims referencing my name exclusively.

I’m working through a Bowled over by Ruby/Cocoa example written against Mac OSX Cocoa APIs and trying to adapt it to CocoaTouch. The first challenge comes from trying to use RubyCocoa to access a controller bound to certain CocoaTouch APIs like UIKit. It doesn’t work. So instead I was clever enough to side step the problem and generate my BowlingController as a vanilla NSObject using the “script/generate model” command from Dr. Nic’s RBiPhoneTest. I use rbiPhoneTest to setup the project test structure as well so now I have a rake file in my root that I use to build the necessary BowlingController.bundle for RSpec (or any Ruby code) to access. I will plan a write up on all of this after I get through the entire tutorial. Long story lengthened I have RSpec loading and running my BowlingController, I’ve made several iterations even into creating IBOutlet/IBAction bindings for Interface Builder. (I’m not sure if they work b/c I haven’t gotten that far yet.) I get stuck at the part where my controller is supposed to pass the pins value from the text field into the bowling model object. My Ruby bowling stub reports that roll has been invoked with no arguments even though I am most definitely passing a value into the method. I keep getting, “Spec::Mocks::MockExpectationError in ‘OSX::BowlingController should send the pin value to the bowling object’
Mock ‘Bowling’ expected :roll with (10) but received it with (no args)
./test/bowling_controller_spec.rb:38:”
I’ve even went as far as passing a literal 10 into the call. At this point it looks like some sort of Ruby/Cocoa alignment issue or something.

bowling_controller_spec.rb

require File.dirname(__FILE__) + ‘/test_helper’

require “BowlingController.bundle”
OSX::ns_import :BowlingController

include OSX

describe BowlingController do
before(:each) do
@controller = BowlingController.new
@bowling = mock(‘Bowling’)
@text_field = mock(‘Pins’)
@text_field.stub!(:intValue).and_return(10)
@controller.pins = @text_field
end

it “should roll a ball” do
@controller.roll
end

it “should roll a ball and get the value from the pins outlet” do
@text_field.should_receive(:intValue).and_return(0)
@controller.roll
end

it “should be an OSX::NSObject” do
@controller.is_a?(OSX::NSObject).should == true
end

it “should have an outlet to a bowling object” do
@controller.bowling = @bowling
end

it “should send the pin value to the bowling object” do
@controller.bowling = @bowling
@bowling.should_receive(:roll).with(10)

@controller.roll
end
end

BowlingController.h

#import

@class UITextField;
@class Bowling;

@interface BowlingController : NSObject {
UITextField* pins;
Bowling* bowling;
}
@property (nonatomic, retain) UITextField* pins;
@property (nonatomic, retain) Bowling* bowling;

-(void) roll;
@end

BowlingController.m

#import “BowlingController.h”
#import “Bowling.h”

@implementation BowlingController
@synthesize pins;
@synthesize bowling;

-(void) roll{
[self.bowling roll:[self.pins intValue]];
}

@end

// This initialization function gets called when we import the Ruby module.
// It doesn’t need to do anything because the RubyCocoa bridge will do
// all the initialization work.
// The rbiphonetest test framework automatically generates bundles for
// each objective-c class containing the following line. These
// can be used by your tests.
void Init_BowlingController() { }

Bowling.h

#import

@interface Bowling : NSObject {

}
– (void) roll:(int) pins;
@end

Bowling.m

#import “Bowling.h”

@implementation Bowling
– (void) roll:(int) pins{
}

@end

// This initialization function gets called when we import the Ruby module.
// It doesn’t need to do anything because the RubyCocoa bridge will do
// all the initialization work.
// The rbiphonetest test framework automatically generates bundles for
// each objective-c class containing the following line. These
// can be used by your tests.
void Init_Bowling() { }

Note to self: I gotta find better analogies. These are really starting to suck.

Murder me!


I’m spending too much time trying to figure out how to assert that a string is properly URL encoded! I refuse to take the traditional approach of running code in the application and peeking through debugger goggles or some obscure log output. Unit tests are made for this sorta thing! I’e had some tips that suggest how to perform URL encoding but experience teaches me not to trust any particular tip unless I can confirm it in a learning unit test. That’s how I self-educated myself on Ruby over the weekend. I wrote a bunch of learning tests to confirm every code snippet I read online. So why is it that when I assert @”ab%%c” == @”ab c” the error message echoes back “ab != ab c”??? I’m using Google tools for Mac to run iPhone unit test suites.

One other thing… could somebody please invent/has somebody invented an “automatic add new files to svn” plugin for XCode? If I botch one more commit my team is going to cut off my water supply and replace my contact lens solution with Windsor’s clear hot sauce. I love the clear stuff because I can dump a whole bunch on my meal without my wife nagging me about my heartburn.