Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performing semi-automated testing with ruby

I am writing an open source gem that interacts with an sms service. I want to test the interaction, however it needs account information and a phone number to run. It also needs feedback to determine if sms messages were being sent correctly. This causes two problems:

  1. I can't put the account information in the test file, as the gem is open source and anyone could get to it.

  2. I need the person running the test to give information to the script as it is running (eg checking the phone to see if a message was received).

What techniques or libraries are available that can help with this? I'm currently using rspec and making it prompt for parameters (using gets), however it is pretty cluncky at the moment. I can't be the first person using ruby to have this problem, and I feel that I'm missing a gem or something that solves this problem.

like image 979
David Miani Avatar asked Feb 24 '26 07:02

David Miani


1 Answers

Use mocks

What are your tests testing, specifically? That a given login/password works? Probably not. Most likely you want to make sure your code reacts to the API properly. Therefore, I'd suggest mocking. Save the output of the API calls and use a mock service to return those responses. Then test. Your tests will be faster and less brittle as a happy side-effect.

More information on mocking with RSpec is here: http://rspec.info/documentation/mocks/

like image 110
Mark Thomas Avatar answered Feb 25 '26 20:02

Mark Thomas