[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

irb session =

Caleb Clausen

6/5/2005 1:57:00 AM

Ok, so I have to admit that I hate writing unit tests. I know that's
not orthodox. But it just seems like... work. I didn't get into this
for drudgery.

On the other hand, playing around with irb doesn't seem like work. It
seems like playing. Even tho I might end up testing the exact same
things. Irb is kind of like a polaroid camera: instant gratification.
I want to bring this level of instant interactivity to the process of
writing
automated tests.

So, is there a way to save a set of irb commands that I just typed to
a file, so they can be rerun later? Better yet, I'd like to save the
results of the commands too, and check to see if any results have
changed on a re-run.


2 Answers

Assaph Mehr

6/6/2005 3:54:00 AM

0




> So, is there a way to save a set of irb commands that I just typed to
> a file, so they can be rerun later?

You can save the history of irb commands. See:
http://rubygarden.org/ruby?Irb/Tip...

> Better yet, I'd like to save the
> results of the commands too, and check to see if any results have
> changed on a re-run.

irb | tee log
If you're on *nix/cygwin.

HTH,
Assaph

Dave Burt

6/6/2005 9:20:00 AM

0

"Caleb Clausen" <vikkous@gmail.com> asked:
> So, is there a way to save a set of irb commands that I just typed to
> a file, so they can be rerun later? Better yet, I'd like to save the
> results of the commands too, and check to see if any results have
> changed on a re-run.

I added the following to my ~/.irbrc

module IRB
def IRB.history; @history; end
@history = ""
class WorkSpace
alias old_evaluate evaluate
def evaluate(context, statements, file = __FILE__, line = __LINE__)
result = old_evaluate(context, statements, file, line)
if /IRB\.history/.match(statements)
IRB.history << "#{statements.chomp}\n"
else
IRB.history << "#{statements.chomp} #=> #{result.inspect}\n"
end
result
end
end
end

This will automatically collect your irb session history in the string
IRB.history. It might look like this:
a = 1 + 2 #=> 3
puts a #=> nil

One difference between this and the history thing on the wiki is that this
one saves the expected result in a comment after the line. Another is that
this will save a whole session of commands, whereas the wiki version is for
persistent history between sessions.

Cheers,
Dave