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


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.

4 thoughts on “Bugs in Ruby iPhone testing

  1. What is your prototype for -pins ?
    I’d be curious to see what “val” looks like in the debugger after the assignment. Also I wonder if it’s possible to get a longer backtrace…
    Also, numberWithInt; creates an autoreleased NSNumber; are you using it in the context of an autorelease pool or a garbage collector? (I dunno how this works in test cases on Leopard, haven’t gone there yet.) Might try alloc-initWithInt: just for the heck of it, not that that would be my most likely suspect.

  2. I saw -pins in your other post… dunno. Stupid question: the pins UITextField is getting allocated when your BowlingController inits, and is around when your test above runs, right?

  3. The UITextField is mocked by the RSpec test, as are all the other UI controls. You’re onto something though… I changed my NSNumber message to alloc and initWithInt and that nasty error went away. I’m now seeing something that popped up in one of my many trials yesterday.

    -(void) roll{
    int val = (int) [self.pins intValue];
    printf("Value is: %i", val);
    NSNumber* num = [[NSNumber alloc] initWithInt:val];
    [num retain];
    [self.bowling roll:num];
    [num release];

    gives me
    Mock ‘BowlingProtocol’ expected :roll with (#) but received it with (2890320)

    with my BowlingProtocol.h of:

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

    So it’s really just a couple of data type and memory management issues I strayed from the original tutorial when I first noticed the parameters were disappearing from the call. I’m supposed to use a primitive int but I changed it to NSNumber and then I started with the temporary variable to satisfy the other spec that required the intValue message be sent to the mocked text field.

  4. Yes simplifying things helps now that I know the true nature of the problem. I reverted back to primitive ints and I get greenbars.. woohoo! (Technically I only get “6 examples and 0 failures” text but its as close to a green bar as I’m gonna see… that reminds me, why don’t somebody do something fancy with green text in terminal output from the cmd line runners?) In summary, I need to wrap the mock in a mock, yuk! I need to then pass the wrapped mock into my code. Lastly I need to figure out how to dynamically forward messages from my wrapping mock to the real mock. (or better, I should probably dig into Ruby RSpec mocking code and fix the original problem.)

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s