Skip to content

Instantly share code, notes, and snippets.

@deadprogram
Last active December 17, 2015 11:49
Show Gist options
  • Select an option

  • Save deadprogram/5605359 to your computer and use it in GitHub Desktop.

Select an option

Save deadprogram/5605359 to your computer and use it in GitHub Desktop.
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 #{@contacts}"
end
work do
on sphero, :collision => :contact
every(3.seconds) do
puts "Rolling..."
sphero.roll 90, rand(360)
end
end
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
describe 'sphero' do
let(:robot) { Artoo::MainRobot.new }
it 'has work to do every 3 seconds' do
robot.work
robot.has_work?(:every, 3.seconds).wont_be_nil
end
it 'must roll every 3 seconds' do
robot.sphero.expects(:roll).twice
robot.work
sleep 6.1
end
it 'receives collision event' do
robot.expects(:contact)
robot.work
robot.sphero.publish("collision", "clunk")
sleep 0.1
end
end
ENV["ARTOO_TEST"] = 'true'
require File.expand_path '../../sphero.rb', __FILE__
Celluloid.logger = nil
require 'minitest/autorun'
require 'mocha/setup'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment