Friday, July 20, 2012

Old stuff dug up.

This is old, I just found it sitting in my drafts from a couple years back. I believe I was writing a tutorial on how to do this in ActionScript 3, but I'm to old to remember that far back now... :(

Anyhow, it was a world of warcraft inspired character inventory/backpack system in flash.

And the pieces:

Ruby/RSpec Callback Argument Capture

Yesterday I had been poking around trying to get a parameter passed into something I was stubbing out in Ruby & RSpec. Like I had mentioned before in .net with rhinomocks, moq or similar mocking frameworks I would do something of the sort:

var repository = Mocks.Get();
  .Stub(r => r.Save(null))
  .Callback((Player entity) =>
    _player = entity;
    return true;

Due to terminology differences, unfamiliarity with Ruby and my shifting understanding of testing; I was having trouble figuring out how to do that. After a bit of searching and experimenting I pieced together what I needed to do as so:

board = nil
@game_runner.stub(:draw) do |arg|
  board = arg

And then as the design changed as I continued testing, it was no longer needed. It was good to poke around it and figure it out, funny that it didn't survive more than an hour or so in my code.