@@ -19,11 +19,35 @@ class OctocatalogDiff::CatalogDiff::Filter::Fake2 < OctocatalogDiff::CatalogDiff
1919 allow ( Kernel ) . to receive ( :const_get ) . with ( 'OctocatalogDiff::CatalogDiff::Filter::Fake2' ) . and_return ( @class_2 )
2020 end
2121
22+ describe '#filter?' do
23+ it 'should return false for non-existent filter' do
24+ expect ( described_class . filter? ( 'BlahBlahBlah' ) ) . to eq ( false )
25+ end
26+
27+ it 'should return true for valid filter' do
28+ expect ( described_class . filter? ( 'AbsentFile' ) ) . to eq ( true )
29+ end
30+ end
31+
32+ describe '#assert_that_filter_exists' do
33+ it 'should raise error for non-existent filter' do
34+ expect do
35+ described_class . assert_that_filter_exists ( 'BlahBlahBlah' )
36+ end . to raise_error ( ArgumentError , 'The filter BlahBlahBlah is not valid' )
37+ end
38+
39+ it 'should not raise error for valid filter' do
40+ expect { described_class . assert_that_filter_exists ( 'AbsentFile' ) } . not_to raise_error
41+ end
42+ end
43+
2244 describe '#apply_filters' do
2345 it 'should call self.filter() with appropriate options for each class' do
2446 result = [ false ]
2547 options = { foo : 'bar' }
2648 classes = %w( Fake1 Fake2 )
49+ allow ( described_class ) . to receive ( :"filter?" ) . with ( 'Fake1' ) . and_return ( true )
50+ allow ( described_class ) . to receive ( :"filter?" ) . with ( 'Fake2' ) . and_return ( true )
2751 expect_any_instance_of ( @class_1 ) . to receive ( :'filtered?' ) . with ( false , foo : 'bar' ) . and_return ( false )
2852 expect_any_instance_of ( @class_2 ) . to receive ( :'filtered?' ) . with ( false , foo : 'bar' ) . and_return ( false )
2953 expect { described_class . apply_filters ( result , classes , options ) } . not_to raise_error
@@ -34,6 +58,8 @@ class OctocatalogDiff::CatalogDiff::Filter::Fake2 < OctocatalogDiff::CatalogDiff
3458 describe '#filter' do
3559 it 'should call .filtered?() in a class and remove matching items' do
3660 result = [ false , true ]
61+ allow ( described_class ) . to receive ( :"filter?" ) . with ( 'Fake1' ) . and_return ( true )
62+ allow ( described_class ) . to receive ( :"filter?" ) . with ( 'Fake2' ) . and_return ( true )
3763 expect_any_instance_of ( @class_1 ) . to receive ( :'filtered?' ) . with ( false , { } ) . and_return ( false )
3864 expect_any_instance_of ( @class_1 ) . to receive ( :'filtered?' ) . with ( true , { } ) . and_return ( true )
3965 expect { described_class . filter ( result , 'Fake1' ) } . not_to raise_error
0 commit comments