Skip to content

Commit

Permalink
Test 2.0.0, 2.2.0 and jruby. Bare minimum work to get tests passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
vickash committed Feb 21, 2015
1 parent c7a24e8 commit 7fa7fca
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
@@ -1,5 +1,8 @@
language: ruby
rvm:
- 2.2.0
- 2.0.0
- 1.9.3
- 1.9.2
script: bundle exec rspec spec
- jruby-19mode

script: bundle exec rspec spec
9 changes: 4 additions & 5 deletions lib/dino/components/shift_register.rb
Expand Up @@ -24,20 +24,21 @@ def write_state
write_bytes(bytes)
end

def write_bytes(bytes)
def write_bytes(*bytes)
latch.low
bytes.each do |byte|
bytes.flatten.each do |byte|
board.write Dino::Message.encode(command: 11, pin: data.pin, value: byte, aux_message: clock.pin)
end
latch.high
end

alias :write_byte :write_bytes
alias :write :write_bytes

#
# Make the shift register behave like a board.
# We can use each output pin on it individually for digital out components.
# To set up component, use the register object as the 'board', and the corresponding pin numbers.
# To instantiate a component, pass the register as a 'board' and the corresponding pin numbers on the register.
#
include Mixins::BoardProxy
include Mixins::Threaded
Expand All @@ -48,8 +49,6 @@ def digital_write(pin, value)
start_write
end

alias :write :digital_write

#
# Wait until we have not had a digital_write for 1ms before writing to the board.
# Reduces the amount of wrting required for things like SSDs that change many bits in sequence.
Expand Down
13 changes: 6 additions & 7 deletions spec/lib/board_spec.rb
Expand Up @@ -16,7 +16,7 @@ def io_mock(methods = {})
end

it 'should observe the io' do
io_mock.should_receive(:add_observer).with(subject)
expect(io_mock).to receive(:add_observer).with(subject)
subject.send(:initialize, io_mock)
end

Expand All @@ -26,11 +26,10 @@ def io_mock(methods = {})
end

it 'should define the logic properly' do
subject.should_receive(:analog_resolution=).with(8)

expect(subject).to receive(:analog_resolution=).with(8)
subject.send(:initialize, io_mock)
subject.high.should == 255
subject.low.should == 0
expect(subject.high).to equal(255)
expect(subject.low).to equal(0)
end
end

Expand Down Expand Up @@ -164,12 +163,12 @@ def io_mock(methods = {})

describe '#set_pullup' do
it 'should write high if pullup is enabled' do
io_mock.should_receive(:write).with(Dino::Message.encode(command: 1, pin: 13, value: subject.high))
expect(io_mock).to receive(:write).with(Dino::Message.encode(command: 1, pin: 13, value: subject.high))
subject.set_pullup(13, true)
end

it 'should write low if pullup is disabled' do
io_mock.should_receive(:write).with(Dino::Message.encode(command: 1, pin: 13, value: subject.low))
expect(io_mock).to receive(:write).with(Dino::Message.encode(command: 1, pin: 13, value: subject.low))
subject.set_pullup(13, false)
end
end
Expand Down
33 changes: 17 additions & 16 deletions spec/lib/components/basic/digital_input_spec.rb
Expand Up @@ -8,32 +8,33 @@ module Basic
let(:options) { { pin: 'A0', board: board } }
subject { DigitalInput.new(options) }

describe '#initialize' do
it 'should start listening immediately' do
board.should_receive(:digital_listen).with(14)

component = DigitalInput.new(options)
end
it 'should start listening immediately' do
expect(board).to receive(:digital_listen).with(14)
component = DigitalInput.new(options)
end

describe '#_read' do
it 'should send #digital_read to the board with its pin' do
board.should_receive(:digital_read).with(subject.pin)
it 'should call board#digital_read with its pin once' do
expect(board).to receive(:digital_read).with(subject.pin).once
subject._read
end
end

describe '#_listen' do
it 'should send #digital_listen to the board with its pin' do
subject.stop
board.should_receive(:digital_listen).with(subject.pin)

it 'should call board#digital_listen with its pin once' do
expect(board).to receive(:digital_listen).with(subject.pin).once
subject._listen
end
end

context 'callbacks' do
before :each do
# Simulate the mutex
mutex = double
allow(mutex).to receive(:synchronize).and_yield
subject.instance_variable_set(:@callback_mutex, mutex)
subject.instance_variable_set(:@callbacks, {})

@low_callback = double
@high_callback = double
subject.on_low { @low_callback.called }
Expand All @@ -42,17 +43,17 @@ module Basic

describe '#on_low' do
it 'should add a callback that only gets fired when LOW' do
@low_callback.should_receive(:called)
@high_callback.should_not_receive(:called)
expect(@low_callback).to receive(:called)
expect(@high_callback).not_to receive(:called)

subject.update(DigitalInput::LOW)
end
end

describe '#on_high' do
it 'should add a callback that only gets fired when HIGH' do
@low_callback.should_not_receive(:called)
@high_callback.should_receive(:called)
expect(@high_callback).to receive(:called)
expect(@low_callback).not_to receive(:called)

subject.update(DigitalInput::HIGH)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/components/setup/input_spec.rb
Expand Up @@ -29,8 +29,8 @@ class InputComponent
end

it 'should set the pulllup if included in options' do
board.should_receive(:set_pullup).with(subject.pin, true)
subject
expect(board).to receive(:set_pullup).with(subject.pin, true)
InputComponent.new(options)
end

it 'should tell the board to start reading' do
Expand Down

0 comments on commit 7fa7fca

Please sign in to comment.