Skip to content

Instantly share code, notes, and snippets.

@wshihadeh
Created December 21, 2019 12:20
Show Gist options
  • Save wshihadeh/aa68352ead0ac0bcdd9c4cfdad966fc3 to your computer and use it in GitHub Desktop.
Save wshihadeh/aa68352ead0ac0bcdd9c4cfdad966fc3 to your computer and use it in GitHub Desktop.
PriorityList Rspec unit tests
# 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