Archive for July, 2007

BDD and RSpec

As a personal bookmark: There’s a pretty reasonable thread over on the Ruby on Rails: Talk list about BDD and RSpec. Reasonable arguments on both side of the RSpec fence:

Then I attended a lecture by Aslak Hellesøy. I mean, with so many people
around raving about RSpec, I must be missing the point right? But I was
let down: Alsak demonstrated it to be a wrapper DSL around Test::Unit
for “people who find it hard to come to gripes with TDD”. So it’s a sort
of workaround? I was disappointed by that statement of his.
He says Test::Unit is tightly coupled to the actual code and that that’s
a bad thing. I say I like that coupling, because it keeps a sharp edge
on the test-before-you-write principle: if you’re mucking around code or
tests that worked before, you’ll find yourself pressed to advocate that
change and express it in an additional or revised test.

then:

BDD comes from TDD, which comes from XP, which includes Refactoring as
an integral part of the process. Refactoring is more expensive as your
tests are more tightly coupled to the code, so one goal of TDD is to
decouple the tests from the detail of the code (which is what changes
most often). One thing that aids in this decoupling is focusing on
behaviour instead of internal implementation. BDD champions this goal
by putting it front and center. RSpec supports this by trying to use
words like “describe” instead of “TestCase” and “should” instead of
“assert.”

and further RSpec support:

It’s a small tweak, to refocus TDD practitioners a slight bit. They
think it produces better specs/tests, not because it’s something that
couldn’t be done before, but because it’s now more obvious what you
should be doing.

Terrence Parr on ANTLR at SJUG

Atlassian have published videos of Terrence Parr’s ANTLR presentation at SJUG.  And there is the back of my head right in the middle of the camera (actually, more bottom right.  Second row back, dark sweater).

Very interesting presentation, now I just need to get my hands on the new ANTLR book.  Thanks Terrence!

Extensible Ruby, and autoloading with attachment_fu

I wanted to load approximately 300 photos into my application, create all the associated thumbnails and store all the metadata in the database. Since the thumbnail generation is handled by the excellent attachment_fu, it made sense to load these via the model. But the model assumes that Ruby’s CGI handler has grabbed the data into a temp file and determined the content type. What’s the best way to do this?

Thanks to Ruby’s dynamic extensibility and duck typing, I was able to manually create a temp file, then add in the required methods on-the-fly. Thanks Ruby!
tempfile = Tempfile.new(“CGI”)
tempfile.write(File.open(f).read)
(class << tempfile; self; end).class_eval do
alias local_path path
define_method(:original_filename) {f.dup.taint}
define_method(:content_type) {“image/png”}
end
photo = photo.create! :uploaded_data => tempfile

Add a little bit of iteration, and you’re all done.

Ruby roundup

Here are a few important Ruby/Rails links I’ve come across over the last week or so, with commentary:

  • The beauty of Ruby – Glen Vandenburg does a good job of explaining the beauty of ruby. I didn’t watch all of it since I wasn’t really learning anything, but points he makes are: great syntax, mixins vs inheritance, OO to the core, and more.
  • Mingle – I’ve mentioned Mingle before, but this quick article gives an outline of what it will bring to agile project management. Most notable, it runs on JRuby, and thus on the JVM, which is a great Enterprise proposition.
  • Experts or Script Kiddies – Rails will have to fight against the notion that it is a toy scripting language to make it in the enterprise. Luckily there are plenty of reputable Java geniuses who are singing its praises. This article makes some great points about how Rails should be perceived — and refutes many reasons for denigrating it.

Clifford Stoll and The Cuckoo’s Egg

Reading Jeff Atwood’s latest blog post brought a flood of memories rushing back to me. When he mentioned Clifford Stoll, I was transported back to 1989/1990 when Cliff’s book about how he captured a KGB hacker, The Cuckoo’s Egg, was first published. Shortly after, the ABC had a special show dedicated to telling Cliff’s story.

Cliff Stoll

At the time, I was fascinated — I watched the show and read the book many times each. I’d already been exposed to computers a lot through my father (I programmed a bookkeeping system when I was 10, which I’m convinced was a big reason I received a scholarship to Shore), but I think the excitement that this show generated for me was the subconcious driving force behind wanting to work with computers, even though I went through a lengthy adolescent phase where I tried to ignore them. Cliff was a very engaging and humble figure. His explanations of the techniques he used to catch the hacker appealed to my logical senses, but were also very dramatic. And it was about connected networks and security — while I was well familiar with online life since dad ran three BBS’s from home, this was years before the Internet hit the collective consciousness.

It was such a pleasant surprise to be thinking about such a pivotal part of my childhood, and indirectly my adult life, I had to note it here. Thanks Cliff!

Cliff more recently