[rspec-users] testing scripts

barsalou barjunk at attglobal.net
Tue Nov 13 18:52:19 EST 2007

Ashley said:

Message: 7
Date: Tue, 13 Nov 2007 20:43:53 +0000
From: Ashley Moran <work at ashleymoran.me.uk>
Subject: Re: [rspec-users] testing scripts
To: rspec-users <rspec-users at rubyforge.org>
Message-ID: <84ECF846-4D27-428D-BCEA-785E60E02AA7 at ashleymoran.me.uk>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

On Nov 13, 2007, at 7:45 pm, barsalou wrote:

> What I'm doing now is wrapping the methods in a module, then including
> the module at the top of the script.

Can you post some examples of the modules, classes and methods you have?

Every script I've written is basically just a little object-oriented 
app that's got a bit at the end to fire off some "main" class with the 
command line args.  Testing one is no different than testing, say, lib 
code in Rails.  Ideally you want each bit of functionality in a class 
(and therefore file) of its own, so it can be tested in isolation.   
But without seeing what you've got, it's hard to guess where the 
problem lies.




I think what I've come to realize is that I need to refactor what I've 
done.  A quick example would be:

def exists?(device)
  # do device validation

device = Device.find(1)
if exists?(device) then  # do my thing

I realize that exists? should really be part of Device and doing 
testing on this script is helping me look at the objects differently 
and I'm starting to refactor.

So I think my initial problem with testing my script is that it's not 
really OO in the first place.

You've confirmed for me what I had been thinking and I'll work to that end.

Thanks for the feedback.

Mike B.

This message was sent using IMP, the Internet Messaging Program.

More information about the rspec-users mailing list