Test Driven Robotics
Artoo makes it easy to do Test Driven Development (TDD) of your robotic devices using your favorite Ruby test and mocking frameworks.
Here is an example that uses Minitest, Mocha, and Timecop:
require './test_helper' require './test_robot' describe 'sphero' do let(:robot) { Artoo::MainRobot.new } let (:start) { Time.now } before :each do Timecop.travel(start) robot.work end after :each do Timecop.return end it 'has work to do every 3 seconds' do robot.has_work?(:every, 3.seconds).wont_be_nil end it 'receives collision event' do robot.expects(:contact) robot.sphero.publish("collision", "clunk") sleep 0.05 end it 'must roll every 3 seconds' do Timecop.travel(start + 3.seconds) do robot.sphero.expects(:roll) sleep 0.05 end Timecop.travel(start + 6.seconds) do robot.sphero.expects(:roll) sleep 0.05 end end end
to describe the following Sphero robot:
require 'artoo' connection :sphero, :adaptor => :sphero, :port => '127.0.0.1:4560' device :sphero, :driver => :sphero def contact(*args) @contacts ||= 0 @contacts += 1 puts "Contact " end work do on sphero, :collision => :contact every(3.seconds) do sphero.roll 90, rand(360) end end
The repo with full example of using Artoo for test driven robotics is located at https://github.com/hybridgroup/artoo-test-example .