-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shared specs for Stoplight::Light::Runnable (#176)
- Loading branch information
Showing
5 changed files
with
312 additions
and
258 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'runnable/color' | ||
require_relative 'runnable/run' |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples 'Stoplight::Light::Runnable#color' do | ||
it 'is initially green' do | ||
expect(light.color).to eql(Stoplight::Color::GREEN) | ||
end | ||
|
||
context 'when its locked green' do | ||
before do | ||
light.data_store.set_state(light, Stoplight::State::LOCKED_GREEN) | ||
end | ||
|
||
it 'is green' do | ||
expect(light.color).to eql(Stoplight::Color::GREEN) | ||
end | ||
end | ||
|
||
context 'when its locked red' do | ||
before do | ||
light.data_store.set_state(light, Stoplight::State::LOCKED_RED) | ||
end | ||
|
||
it 'is red' do | ||
expect(light.color).to eql(Stoplight::Color::RED) | ||
end | ||
end | ||
|
||
context 'when there are many failures' do | ||
it 'turns red' do | ||
expect do | ||
light.threshold.times do | ||
light.data_store.record_failure(light, failure) | ||
end | ||
end.to change(light, :color).to be(Stoplight::Color::RED) | ||
end | ||
end | ||
|
||
context 'when the most recent failure is old' do | ||
let(:other) do | ||
Stoplight::Failure.new( | ||
error.class.name, error.message, Time.new - light.cool_off_time | ||
) | ||
end | ||
|
||
before do | ||
(light.threshold - 1).times do | ||
light.data_store.record_failure(light, failure) | ||
end | ||
end | ||
|
||
it 'turns yellow' do | ||
expect do | ||
light.data_store.record_failure(light, other) | ||
end.to change(light, :color).to be(Stoplight::Color::YELLOW) | ||
end | ||
end | ||
|
||
context 'when the least recent failure is old' do | ||
let(:other) do | ||
Stoplight::Failure.new(error.class.name, error.message, Time.new - light.cool_off_time) | ||
end | ||
|
||
before do | ||
light.data_store.record_failure(light, other) | ||
end | ||
|
||
it 'is red when the least recent failure is old' do | ||
expect do | ||
(light.threshold - 1).times do | ||
light.data_store.record_failure(light, failure) | ||
end | ||
end.to change(light, :color).to be(Stoplight::Color::RED) | ||
end | ||
end | ||
end |
Oops, something went wrong.