summaryrefslogtreecommitdiff
path: root/spec/gpio_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/gpio_spec.rb')
-rw-r--r--spec/gpio_spec.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/gpio_spec.rb b/spec/gpio_spec.rb
new file mode 100644
index 0000000..48dd8ec
--- /dev/null
+++ b/spec/gpio_spec.rb
@@ -0,0 +1,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