blob: 48dd8ec364eace93b6154afd46d5f36e24bae105 (
plain)
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
58
59
60
61
|
require 'fileutils'
require './spec/spec_helper'
require './gpio'
RSpec.describe Gpio do
let(:gpio) { described_class.new(1, prefix: "./spec/fixtures") }
before do
gpio.value = false
end
describe "#export" do
subject { gpio.export }
before do
FileUtils.touch("./spec/fixtures/export")
end
after do
FileUtils.remove("./spec/fixtures/export")
end
it "writes the pin to the export file" do
subject
export_file = File.read("./spec/fixtures/export")
expect(export_file).to eq("1")
end
it "sets the pin as an output" do
subject
direction_file = File.read("./spec/fixtures/gpio1/direction")
expect(direction_file).to eq("out")
end
end
describe "#toggle" do
subject { gpio.toggle }
it "toggles the value to true" do
expect { subject }.to change { gpio.value }.from(false).to(true)
end
end
describe "#value" do
subject { gpio.value }
it "returns false" do
expect(subject).to be_falsey
end
context "value is set to true" do
before do
gpio.value = true
end
it "returns true" do
expect(subject).to be_truthy
end
end
end
end
|