Last active
December 17, 2015 11:49
-
-
Save deadprogram/5605359 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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