Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm using Autumn gem to create a Ruby IRC bot for a game. However, it makes me feel rather embarrassed because I don't know how to test this kind of program...

I think I should mock the IO process to have a control over it but I can't see how in this case when using the gem.

Has anyone an idea ?

share|improve this question
    
Are you trying to perform manual or automated testing, or doesn't it matter? Are you testing your application or trying to create tests for the gem? –  Thomas Owens Jan 28 '12 at 14:08
    
I'm trying to perform automated testing on my bot. –  Skydreamer Jan 28 '12 at 15:06
add comment

3 Answers

up vote 2 down vote accepted

It is very, very difficult to test external dependencies in an automated repeatable fashion. At least without creating more framework to fake the external dependency than you've got code under test. And oftentimes that sort of thing is very fragile anyhow, leading to lots of false test failures.

I'm not a rubyist by any stretch of the measure, the following advise is going to be pretty language agnostic. What I would do here is to:

  • Wrap the external dependency in my own interface. All my code should talk to this interface. and not patch directly to the library. Depending on the complexity of what the return data was, I would consider building my own DTO objects as well.
  • Test my code against mocked or stubbed versions of this interface to ensure my end of the world is behaving correctly given correct inputs.
  • Finally, try and find a way to test my pass-through interface to the external service. But at the end of the day this class tends to be so simple as to be not worth the effort.

But trying to unit test external services in a conventional sense can be maddening and horribly noneffective.

PS: I should add I just wrote an IRC bot over the last weekend. I did largely use TDD in C#, and I most certainly did not test the IRC connection angle outside of using nUnit as a harness to stand up the experimental code I needed to understand how the library works.

share|improve this answer
add comment

Why don't you run a local IRC server? Restrict it to the local network, or even just localhost, and you can easily test your bot using your favorite IRC client.

share|improve this answer
1  
That's what I'm currently doing but I'd like to automate the testing with RSpec or another test framework. –  Skydreamer Jan 28 '12 at 15:06
add comment

A bot should be almost entirely event driven. In that case, you'll most likely have an event handler. In the case of an IRC bot, the event handler will just be reading a TCP input stream, detecting what event is happening, and then calling the event handler. If your events are built to an interface then you can quite easily fake events in your automated tests.

This all comes down to how Autumn works. I'm not familiar so it may do its own event handling in which case things may get a little more tricky.

share|improve this answer
    
What do you mean by "built to an interface" ? –  Skydreamer May 7 '12 at 16:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.