/
digital_output_spec.rb
57 lines (50 loc) · 1.58 KB
/
digital_output_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'spec_helper'
module Dino
module Components
module Basic
describe DigitalOutput do
include BoardMock
let(:options) { { pin: '13', board: board } }
subject { DigitalOutput.new(options) }
describe '#after_initialize' do
it 'should set mode to out and go low' do
expect(board).to receive(:digital_write).with(13, board.low)
subject
end
end
describe '#digital_write' do
it 'should update the @state instance variable and call #digital_write on the board' do
subject
expect(board).to receive(:digital_write).with(subject.pin, board.high).once
subject.digital_write(board.high)
expect(subject.state).to eq(board.high)
end
end
describe '#high' do
it 'should call #digital_write with HIGH' do
expect(subject).to receive(:digital_write).with(board.high)
subject.high
end
end
describe '#low' do
it 'should call #digital_write with LOW' do
expect(subject).to receive(:digital_write).with(board.low)
subject.low
end
end
describe '#toggle' do
it 'should call high if currently LOW' do
subject.low
expect(subject).to receive(:high)
subject.toggle
end
it 'should call LOW if anything else' do
subject.high
expect(subject).to receive(:low)
subject.toggle
end
end
end
end
end
end