Created
December 21, 2019 12:20
-
-
Save wshihadeh/aa68352ead0ac0bcdd9c4cfdad966fc3 to your computer and use it in GitHub Desktop.
PriorityList Rspec unit tests
This file contains hidden or 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
# frozen_string_literal: true | |
describe PriorityList do | |
let(:list) { [1, 4, 6, 3, 7, 3, 0, 20, 3] } | |
describe '#priority_list' do | |
context 'ascending mode' do | |
before do | |
allow(ENV).to receive(:fetch).with('APPLICATION_MODE', 'ascending') | |
.and_return('ascending') | |
end | |
it ' sorts ascending' do | |
subject = described_class.new(list) | |
expect(subject.priority_list).to eq list.sort | |
end | |
end | |
context 'descending mode' do | |
before do | |
allow(ENV).to receive(:fetch).with('APPLICATION_MODE', 'ascending') | |
.and_return('descending') | |
end | |
it ' sorts descending' do | |
subject = described_class.new(list) | |
expect(subject.priority_list).to eq list.sort.reverse | |
end | |
end | |
context 'default mode' do | |
it ' sorts ascending' do | |
subject = described_class.new(list) | |
expect(subject.priority_list).to eq list.sort | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment