Skip to content

Commit

Permalink
improving my code climate score
Browse files Browse the repository at this point in the history
  • Loading branch information
brundage committed Dec 4, 2016
1 parent 91234d8 commit ea093ed
Showing 1 changed file with 20 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,53 +38,35 @@

end


describe 'closing' do
let(:pin) { 0 }
let(:subject) { described_class.new pin, close_direction: close_direction }

before do
subject.close
end

context 'when pulling high to close' do
let(:close_direction) { :high }
it 'sends #set_high to the gpio' do
expect(gpio).to have_received(:set_high)
end
end

context 'when pulling low to close' do
let(:close_direction) { :low }
it 'sends #set_low to the gpio' do
expect(gpio).to have_received(:set_low)
end
shared_examples_for 'opening or closing' do
it "sends the correct direction to the gpio" do
expect(gpio).to have_received(pull)
end
end

[ :close, :open ].each do |dir|

describe 'opening' do
let(:pin) { 0 }
let(:subject) { described_class.new pin, close_direction: close_direction }

before do
subject.open
end
describe "#{dir}ing" do
let(:pin) { 0 }
let(:pull) { "set_#{dir == :close ? close_direction : open_direction}" }
let(:subject) { described_class.new pin, close_direction: close_direction }
before do
subject.send dir
end

context 'when pulling high to open' do
let(:close_direction) { :high }
it 'sends #set_low to the gpio' do
expect(gpio).to have_received(:set_low)
context "when pulling high to close" do
let(:close_direction) { :high }
let(:open_direction) { :low }
it_behaves_like 'opening or closing'
end
end

context 'when pulling low to open' do
let(:close_direction) { :low }
it 'sends #set_high to the gpio' do
expect(gpio).to have_received(:set_high)
context "when pulling low to close" do
let(:close_direction) { :low }
let(:open_direction) { :high }
it_behaves_like 'opening or closing'
end
end

end
end

end

0 comments on commit ea093ed

Please sign in to comment.