Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

closed as too broad by MichaelT, ChrisF May 5 '14 at 10:38

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the 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
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

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
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

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

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