2008-05-07 18:22:04 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
|
require 'pathname'
|
|
|
|
|
basedir = Pathname.new( __FILE__ ).dirname.parent
|
|
|
|
|
libdir = basedir + "lib"
|
|
|
|
|
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 15:35:35 -08:00
|
|
|
require_relative 'spec_helpers'
|
|
|
|
|
require 'ezmlm'
|
2008-05-07 18:22:04 +00:00
|
|
|
|
|
|
|
|
describe Ezmlm do
|
|
|
|
|
|
2008-08-06 17:24:00 +00:00
|
|
|
it "can fetch a list of all mailing list subdirectories beneath a given directory" do
|
2017-02-01 15:35:35 -08:00
|
|
|
file_entry = double( "plain file" )
|
|
|
|
|
expect( file_entry ).to receive( :directory? ).and_return( false )
|
|
|
|
|
|
|
|
|
|
nonexistant_mlentry = double( "mailinglist path that doesn't exist", :exist? => false )
|
|
|
|
|
nonml_dir_entry = double( "directory with no mailinglist file",
|
|
|
|
|
:directory? => true, :+ => nonexistant_mlentry )
|
2008-05-07 18:22:04 +00:00
|
|
|
|
2017-02-01 15:35:35 -08:00
|
|
|
existant_mlentry = double( "mailinglist path that does exist", :exist? => true )
|
|
|
|
|
ml_dir_entry = double( "directory with a mailinglist file", :directory? => true, :+ => existant_mlentry )
|
2008-05-07 18:22:04 +00:00
|
|
|
|
2017-02-01 15:35:35 -08:00
|
|
|
expect( Pathname ).to receive( :glob ).with( an_instance_of(Pathname) ).
|
2008-08-06 17:24:00 +00:00
|
|
|
and_return([ file_entry, nonml_dir_entry, ml_dir_entry ])
|
|
|
|
|
|
|
|
|
|
dirs = Ezmlm.find_directories( TEST_LISTSDIR )
|
2017-02-01 15:35:35 -08:00
|
|
|
|
|
|
|
|
expect( dirs.size ).to eq( 1 )
|
|
|
|
|
expect( dirs ).to include( ml_dir_entry )
|
2008-08-06 17:24:00 +00:00
|
|
|
end
|
2017-02-01 15:35:35 -08:00
|
|
|
|
2008-08-06 17:24:00 +00:00
|
|
|
|
|
|
|
|
it "can iterate over all mailing lists in a specified directory" do
|
2017-02-01 15:35:35 -08:00
|
|
|
expect( Ezmlm ).to receive( :find_directories ).with( TEST_LISTSDIR ).and_return([ :listdir1, :listdir2 ])
|
|
|
|
|
|
|
|
|
|
expect( Ezmlm::List ).to receive( :new ).with( :listdir1 ).and_return( :listobject1 )
|
|
|
|
|
expect( Ezmlm::List ).to receive( :new ).with( :listdir2 ).and_return( :listobject2 )
|
2008-05-07 18:22:04 +00:00
|
|
|
|
|
|
|
|
lists = []
|
2008-08-06 17:24:00 +00:00
|
|
|
Ezmlm.each_list( TEST_LISTSDIR ) do |list|
|
2008-05-07 18:22:04 +00:00
|
|
|
lists << list
|
|
|
|
|
end
|
2017-02-01 15:35:35 -08:00
|
|
|
|
|
|
|
|
expect( lists.size ).to eq(2)
|
|
|
|
|
expect( lists ).to include( :listobject1, :listobject2 )
|
2008-05-07 18:22:04 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|