|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../spec_helper' |
| 4 | +require OctocatalogDiff::Spec.require_path('/catalog-diff/filter') |
| 5 | + |
| 6 | +describe OctocatalogDiff::CatalogDiff::Filter do |
| 7 | + before(:each) do |
| 8 | + @class_1 = double |
| 9 | + @class_2 = double |
| 10 | + allow(Kernel).to receive(:const_get).with('OctocatalogDiff::CatalogDiff::Filter::Fake1').and_return(@class_1) |
| 11 | + allow(Kernel).to receive(:const_get).with('OctocatalogDiff::CatalogDiff::Filter::Fake2').and_return(@class_2) |
| 12 | + end |
| 13 | + |
| 14 | + describe '#apply_filters' do |
| 15 | + it 'should call self.filter() with appropriate options for each class' do |
| 16 | + result = [false] |
| 17 | + options = { 'Fake1' => { foo: 'bar' } } |
| 18 | + classes = %w(Fake1 Fake2) |
| 19 | + expect(@class_1).to receive(:'filtered?').with(false, foo: 'bar').and_return(false) |
| 20 | + expect(@class_2).to receive(:'filtered?').with(false, {}).and_return(false) |
| 21 | + expect { described_class.apply_filters(result, classes, options) }.not_to raise_error |
| 22 | + expect(result).to eq([false]) |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + describe '#filter' do |
| 27 | + it 'should call .filtered?() in a class and remove matching items' do |
| 28 | + result = [false, true] |
| 29 | + expect(@class_1).to receive(:'filtered?').with(false, {}).and_return(false) |
| 30 | + expect(@class_1).to receive(:'filtered?').with(true, {}).and_return(true) |
| 31 | + expect { described_class.filter(result, 'Fake1') }.not_to raise_error |
| 32 | + expect(result).to eq([false]) |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + describe '#filtered?' do |
| 37 | + it 'should raise error' do |
| 38 | + expect { described_class.filtered?([]) }.to raise_error(RuntimeError, /No `filtered\?` method is implemented/) |
| 39 | + end |
| 40 | + end |
| 41 | +end |
0 commit comments