Entries from July 2006 ↓

View ActiveRecord attributes in TextMate

A very smart Textmate tip from my colleage, Chris

Look, no more scrabbling with the mysql console:

That he hacked it together on the train is even more impressive. Taking the ruby on rails on rails thing too far, I think.

Mocha-loka-choka

James Mead has released his Mocha stubbing and mocking framework for Ruby up on rubyforge.

From the README:

Mocha is a library for mocking and stubbing within tests using a syntax like that of JMock and SchMock.

Mocha comes in three parts:

1. Mocha – traditional mock objects with expectations and verification
2. Stubba – allows mocking and stubbing of methods on real (non-mock) classes
3. AutoMocha – magically provides mocks in the place of undefined classes

Stubba and AutoMocha are the main difference between this mocking library and others like FlexMock and RSpec.

It’s a smart bit of coding, and has good examples of meta-programming and fluent interfaces.

You can do cool things like this (but this just scratches the surface):


class StubbingLibrary
   def initialize(developers)
      @developers = developers
   end

   def release!
      @developers.each {|dev| dev.heap("praise","thanks")}
   end
end

class StubbingLibraryTest

   def test_should_heap_james_with_praise
      james = Developer.new
      james.expects(:heap).with("praise","thanks").at_least_once
      mocha = StubbingLibrary.new([james])
      mocha.release!
      james.verify
   end

end

I recommend you get it and read the README for yourselves – it has Star Trek examples, if you weren’t already convinced…