Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix tests

  • Loading branch information...
commit e7ff676863bc00da8759bffa4fa59a0f056cd46b 1 parent 8ce13b6
@vickash vickash authored
Showing with 10 additions and 6 deletions.
  1. +2 −3 lib/dino/components/servo.rb
  2. +8 −3 spec/lib/components/servo_spec.rb
View
5 lib/dino/components/servo.rb
@@ -6,12 +6,11 @@ class Servo < BaseComponent
def after_initialize(options={})
set_pin_mode(:out)
board.servo_toggle(pin, 1)
- position = options[:position] || 0
+ self.position = options[:position] || 0
end
def position=(value)
- board.servo_write(pin, angle(value))
- @position = value
+ board.servo_write(pin, @position = angle(value))
end
def angle(value)
View
11 spec/lib/components/servo_spec.rb
@@ -3,7 +3,7 @@
module Dino
module Components
describe Servo do
- let(:board) { mock(:board, analog_write: true, set_pin_mode: true) }
+ let(:board) { mock(:board, analog_write: true, set_pin_mode: true, servo_toggle: true, servo_write: true) }
describe '#initialize' do
it 'should raise if it does not receive a pin' do
@@ -37,13 +37,18 @@ module Components
servo.instance_variable_get(:@position).should == 90
end
- it 'should modulate the position at 180' do
+ it 'should let you write up to 180' do
+ servo.position = 180
+ servo.instance_variable_get(:@position).should == 180
+ end
+
+ it 'should modulate when position > 180' do
servo.position = 190
servo.instance_variable_get(:@position).should == 10
end
it 'should write the new position to the board' do
- servo.should_receive(:analog_write).with(10)
+ board.should_receive(:servo_write).with(13, 10)
servo.position = 190
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.