spec/ezmlm_spec.rb
author Mahlon E. Smith <mahlon@martini.nu>
Fri, 03 Feb 2017 10:52:46 -0800
changeset 13 a03c08c289e9
parent 12 3cc813140c80
child 14 cba9fb39bcdb
permissions -rw-r--r--
Multiple changes. - Start converting from from the old 'config' file format where applicable. - Port the ezmlm address hashing algorithm for fast email lookups - Add subscription and unsubscription for primary and behavioral dirs - Add a safety check for writes to the list directory

#!/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 )
}

require_relative 'spec_helpers'
require 'ezmlm'

describe Ezmlm do

	it "can fetch a list of all mailing list subdirectories beneath a given directory" do
		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 )

		existant_mlentry = double( "mailinglist path that does exist", :exist? => true )
		ml_dir_entry = double( "directory with a mailinglist file", :directory? => true, :+ => existant_mlentry )

		expect( Pathname ).to receive( :glob ).with( an_instance_of(Pathname) ).
			and_return([ file_entry, nonml_dir_entry, ml_dir_entry ])

		dirs = Ezmlm.find_directories( TEST_LISTSDIR )

		expect( dirs.size ).to eq( 1 )
		expect( dirs ).to include( ml_dir_entry )
	end


	it "can iterate over all mailing lists in a specified directory" do
		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 )

		lists = []
		Ezmlm.each_list( TEST_LISTSDIR ) do |list|
			lists << list
		end

		expect( lists.size ).to eq(2)
		expect( lists ).to include( :listobject1, :listobject2 )
	end
end