spec/ezmlm_spec.rb
author Mahlon E. Smith <mahlon@laika.com>
Wed, 24 May 2017 15:42:39 -0700
changeset 24 f8873b391f3d
parent 14 cba9fb39bcdb
permissions -rw-r--r--
Add a "last activity" method to quickly determine when a list was last used. Bump version.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     1
#!/usr/bin/env ruby
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     2
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     3
BEGIN {
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     4
	require 'pathname'
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     5
	basedir = Pathname.new( __FILE__ ).dirname.parent
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     6
	libdir = basedir + "lib"
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     7
	$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     8
}
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     9
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    10
require_relative 'spec_helpers'
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    11
require 'ezmlm'
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    12
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    13
describe Ezmlm do
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    14
6
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    15
	it "can fetch a list of all mailing list subdirectories beneath a given directory" do
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    16
		file_entry = double( "plain file" )
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    17
		expect( file_entry ).to receive( :directory? ).and_return( false )
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    18
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    19
		nonexistant_mlentry = double( "mailinglist path that doesn't exist", :exist? => false )
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    20
		nonml_dir_entry = double( "directory with no mailinglist file",
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    21
			:directory? => true, :+ => nonexistant_mlentry )
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    22
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    23
		existant_mlentry = double( "mailinglist path that does exist", :exist? => true )
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    24
		ml_dir_entry = double( "directory with a mailinglist file", :directory? => true, :+ => existant_mlentry )
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    25
14
cba9fb39bcdb Checkpoint commit.
Mahlon E. Smith <mahlon@laika.com>
parents: 12
diff changeset
    26
		sorted_dirs = double( "sorted dirs" )
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    27
		expect( Pathname ).to receive( :glob ).with( an_instance_of(Pathname) ).
14
cba9fb39bcdb Checkpoint commit.
Mahlon E. Smith <mahlon@laika.com>
parents: 12
diff changeset
    28
			and_return( sorted_dirs )
cba9fb39bcdb Checkpoint commit.
Mahlon E. Smith <mahlon@laika.com>
parents: 12
diff changeset
    29
		expect( sorted_dirs ).to receive( :sort ).
6
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    30
			and_return([ file_entry, nonml_dir_entry, ml_dir_entry ])
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    31
14
cba9fb39bcdb Checkpoint commit.
Mahlon E. Smith <mahlon@laika.com>
parents: 12
diff changeset
    32
		dirs = Ezmlm.find_directories( '/tmp' )
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    33
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    34
		expect( dirs.size ).to eq( 1 )
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    35
		expect( dirs ).to include( ml_dir_entry )
6
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    36
	end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    37
6
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    38
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    39
	it "can iterate over all mailing lists in a specified directory" do
14
cba9fb39bcdb Checkpoint commit.
Mahlon E. Smith <mahlon@laika.com>
parents: 12
diff changeset
    40
		expect( Ezmlm ).to receive( :find_directories ).with( '/tmp' ).and_return([ :listdir1, :listdir2 ])
6
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    41
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    42
		expect( Ezmlm::List ).to receive( :new ).with( :listdir1 ).and_return( :listobject1 )
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    43
		expect( Ezmlm::List ).to receive( :new ).with( :listdir2 ).and_return( :listobject2 )
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    44
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    45
		lists = []
14
cba9fb39bcdb Checkpoint commit.
Mahlon E. Smith <mahlon@laika.com>
parents: 12
diff changeset
    46
		Ezmlm.each_list( '/tmp' ) do |list|
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    47
			lists << list
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    48
		end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    49
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    50
		expect( lists.size ).to eq(2)
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    51
		expect( lists ).to include( :listobject1, :listobject2 )
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    52
	end
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    53
end
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    54
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    55