Skip to content

Commit

Permalink
feat: Simplify light lock exception condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokideos committed Dec 10, 2022
1 parent 9d0076d commit bd1b473
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 21 deletions.
1 change: 0 additions & 1 deletion lib/stoplight/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ module Color
GREEN = 'green'
YELLOW = 'yellow'
RED = 'red'
LOCKABLE_COLORS = [GREEN, RED].freeze
end
end
3 changes: 1 addition & 2 deletions lib/stoplight/light/runnable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ def run
end

def lock(color)
raise Error::IncorrectColor unless Color::LOCKABLE_COLORS.include?(color)

state = case color
when Color::RED then State::LOCKED_RED
when Color::GREEN then State::LOCKED_GREEN
else raise Error::IncorrectColor
end

safely { data_store.set_state(self, state) }
Expand Down
18 changes: 0 additions & 18 deletions spec/stoplight/color_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,4 @@
expect(Stoplight::Color::RED).to be_frozen
end
end

describe '::LOCKABLE_COLORS' do
it 'is an array' do
expect(Stoplight::Color::LOCKABLE_COLORS).to be_a(Array)
end

it 'is frozen' do
expect(Stoplight::Color::LOCKABLE_COLORS).to be_frozen
end

it 'includes green color' do
expect(Stoplight::Color::LOCKABLE_COLORS).to include(Stoplight::Color::GREEN)
end

it 'includes red color' do
expect(Stoplight::Color::LOCKABLE_COLORS).to include(Stoplight::Color::RED)
end
end
end

0 comments on commit bd1b473

Please sign in to comment.