Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds error checking to all controls to verify that specified pins are…
… valid GPIO pins.
- Loading branch information
Showing
13 changed files
with
111 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
require 'spec_helper' | ||
|
||
describe WhippedCream::Button do | ||
subject(:button) { described_class.new(name, pin: pin, block: block) } | ||
context 'valid button' do | ||
subject(:button) { described_class.new(name, pin: valid_pin, block: block) } | ||
|
||
let(:name) { "Open/Close" } | ||
let(:pin) { nil } | ||
let(:block) { nil } | ||
let(:name) { "Open/Close" } | ||
let(:valid_pin) { 4 } | ||
let(:block) { nil } | ||
|
||
its(:name) { should eq(name) } | ||
its(:id) { should eq(:open_close) } | ||
its(:type) { should eq(:button) } | ||
its(:name) { should eq(name) } | ||
its(:id) { should eq(:open_close) } | ||
its(:type) { should eq(:button) } | ||
end | ||
|
||
context 'invalid button' do | ||
let(:invalid_pin) { 3 } | ||
|
||
it 'should raise an error on initialization' do | ||
expect { described_class.new(name, pin: invalid_pin) }.to raise_error | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,48 @@ | ||
require 'spec_helper' | ||
|
||
describe WhippedCream::Sensor do | ||
subject(:sensor) { described_class.new(name, options, &block) } | ||
|
||
let(:name) { "Door" } | ||
let(:options) { | ||
{ | ||
pin: 2, | ||
high: "Open", | ||
low: "Closed", | ||
on_high: :door_opened | ||
context 'valid sensor' do | ||
subject(:sensor) { described_class.new(name, valid_options, &block) } | ||
|
||
let(:name) { "Door" } | ||
let(:valid_options) { | ||
{ | ||
pin: 17, | ||
high: "Open", | ||
low: "Closed", | ||
on_high: :door_opened | ||
} | ||
} | ||
} | ||
let(:block) { nil } | ||
let(:block) { nil } | ||
|
||
its(:name) { should eq(name) } | ||
its(:id) { should eq(:door) } | ||
|
||
its(:name) { should eq(name) } | ||
its(:id) { should eq(:door) } | ||
its(:pin) { should eq(17) } | ||
|
||
its(:pin) { should eq(2) } | ||
its(:high) { should eq("Open") } | ||
its(:low) { should eq("Closed") } | ||
|
||
its(:high) { should eq("Open") } | ||
its(:low) { should eq("Closed") } | ||
its(:on_high) { should eq(:door_opened) } | ||
its(:on_low) { should be_nil } | ||
end | ||
|
||
context 'invalid sensor' do | ||
let(:name) { "Door" } | ||
let(:invalid_options) { | ||
{ | ||
pin: 3, | ||
high: "Open", | ||
low: "Closed", | ||
on_high: :door_opened | ||
} | ||
} | ||
let(:block) { nil } | ||
|
||
its(:on_high) { should eq(:door_opened) } | ||
its(:on_low) { should be_nil } | ||
it 'should raise an error on initialization' do | ||
expect { | ||
described_class.new(name, invalid_options, &block) | ||
}.to raise_error | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
require 'spec_helper' | ||
|
||
describe WhippedCream::Switch do | ||
subject(:switch) { described_class.new(name, pin: pin) } | ||
context 'valid switch' do | ||
subject(:switch) { described_class.new(name, pin: valid_pin) } | ||
|
||
let(:name) { "Light" } | ||
let(:pin) { 3 } | ||
let(:name) { "Light" } | ||
let(:valid_pin) { 18 } | ||
|
||
its(:name) { should eq(name) } | ||
its(:id) { should eq(:light) } | ||
its(:type) { should eq(:switch) } | ||
its(:pin) { should eq(3) } | ||
its(:name) { should eq(name) } | ||
its(:id) { should eq(:light) } | ||
its(:type) { should eq(:switch) } | ||
its(:pin) { should eq(18) } | ||
end | ||
|
||
context 'invalid switch' do | ||
let(:invalid_pin) { 3 } | ||
|
||
it 'should raise an error upon initialization' do | ||
expect { described_class.new(name, pin: invalid_pin) }.to raise_error | ||
end | ||
end | ||
end |