[rspec-users] BlackBox testing
dchelimsky at gmail.com
Mon Jun 18 21:08:13 EDT 2007
On 6/18/07, Jed Hurt <jed.hurt at gmail.com> wrote:
> I am porting SWX (swxformat.org) to Ruby. It's a data exchange format
> that assembles data structures into native SWF bytecode.
> Here's my dilemma: The original SWX implementation (PHP) tests a lot
> of methods that wouldn't be included in the public API (if PHP
> properly supported encapsulation that is). The PHP implementation
> really only includes a single public method—writeSWF. Basically, you
> pass writeSWF a data structure, and it returns SWF bytecode.
> Pretty simple on the surface, but the actual SwfCompiler class is
> monolithic ( http://svn1.cvsdude.com/osflash/swx/trunk/php/SwfCompiler.php
That's the beauty of porting stuff - you get to redesign it as you go.
I'd take the opportunity to improve the design and break it up into a
few smaller classes that do targeted parts of the job. You can pass
mock instances of them in on the constructor in your rspec examples to
describe how the main object uses the helper objects, and then make
things public on the helper objects. Unless they're maintaining state
(which they probably shouldn't) you run no risk by having them public
on those objects. And then you get the benefit of focusing on little
bits as you go.
> Here's my question: I lean towards protecting as many methods of my
> classes as possible. Protect first, then make public if it becomes
> necessary to do so. Following the original implementation, my only
> public method would be SwfCompiler#write_swf.
> But how can I drive my implementation by specifying only one method?
> I'd have to blindly write a couple hundred lines of protected methods
> before I implemented any examples.
> What is the common prescription to overcome such a scenario?
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users