spec/ezmlm_spec.rb
changeset 12 3cc813140c80
parent 6 66beb495a861
child 14 cba9fb39bcdb
equal deleted inserted replaced
11:7fc2d1713795 12:3cc813140c80
     1 #!/usr/bin/env ruby
     1 #!/usr/bin/env ruby
     2 
     2 
     3 BEGIN {
     3 BEGIN {
     4 	require 'pathname'
     4 	require 'pathname'
     5 	basedir = Pathname.new( __FILE__ ).dirname.parent
     5 	basedir = Pathname.new( __FILE__ ).dirname.parent
     6 	
       
     7 	libdir = basedir + "lib"
     6 	libdir = basedir + "lib"
     8 	
       
     9 	$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
     7 	$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
    10 }
     8 }
    11 
     9 
    12 begin
    10 require_relative 'spec_helpers'
    13 	require 'spec/runner'
    11 require 'ezmlm'
    14 	require 'spec/lib/helpers'
       
    15 	require 'ezmlm'
       
    16 rescue LoadError
       
    17 	unless Object.const_defined?( :Gem )
       
    18 		require 'rubygems'
       
    19 		retry
       
    20 	end
       
    21 	raise
       
    22 end
       
    23 
       
    24 
    12 
    25 describe Ezmlm do
    13 describe Ezmlm do
    26 	include Ezmlm::SpecHelpers
       
    27 
       
    28 	TEST_LISTSDIR = '/tmp/lists'
       
    29 
    14 
    30 	it "can fetch a list of all mailing list subdirectories beneath a given directory" do
    15 	it "can fetch a list of all mailing list subdirectories beneath a given directory" do
    31 		file_entry = mock( "plain file" )
    16 		file_entry = double( "plain file" )
    32 		file_entry.should_receive( :directory? ).and_return( false )
    17 		expect( file_entry ).to receive( :directory? ).and_return( false )
    33 
    18 
    34 		nonexistant_mlentry = stub( "mailinglist path that doesn't exist", :exist? => false )
    19 		nonexistant_mlentry = double( "mailinglist path that doesn't exist", :exist? => false )
    35 		nonml_dir_entry = stub( "directory with no mailinglist file",
    20 		nonml_dir_entry = double( "directory with no mailinglist file",
    36 		 	:directory? => true, :+ => nonexistant_mlentry )
    21 			:directory? => true, :+ => nonexistant_mlentry )
    37 
    22 
    38 		existant_mlentry = stub( "mailinglist path that does exist", :exist? => true )
    23 		existant_mlentry = double( "mailinglist path that does exist", :exist? => true )
    39 		ml_dir_entry = stub( "directory with a mailinglist file", :directory? => true, :+ => existant_mlentry )
    24 		ml_dir_entry = double( "directory with a mailinglist file", :directory? => true, :+ => existant_mlentry )
    40 		
    25 
    41 		Pathname.should_receive( :glob ).with( an_instance_of(Pathname) ).
    26 		expect( Pathname ).to receive( :glob ).with( an_instance_of(Pathname) ).
    42 			and_return([ file_entry, nonml_dir_entry, ml_dir_entry ])
    27 			and_return([ file_entry, nonml_dir_entry, ml_dir_entry ])
    43 
    28 
    44 		dirs = Ezmlm.find_directories( TEST_LISTSDIR )
    29 		dirs = Ezmlm.find_directories( TEST_LISTSDIR )
    45 		
    30 
    46 		dirs.should have(1).member
    31 		expect( dirs.size ).to eq( 1 )
    47 		dirs.should include( ml_dir_entry )
    32 		expect( dirs ).to include( ml_dir_entry )
    48 	end
    33 	end
    49 	
    34 
    50 
    35 
    51 	it "can iterate over all mailing lists in a specified directory" do
    36 	it "can iterate over all mailing lists in a specified directory" do
    52 		Ezmlm.should_receive( :find_directories ).with( TEST_LISTSDIR ).and_return([ :listdir1, :listdir2 ])
    37 		expect( Ezmlm ).to receive( :find_directories ).with( TEST_LISTSDIR ).and_return([ :listdir1, :listdir2 ])
    53 
    38 
    54 		Ezmlm::List.should_receive( :new ).with( :listdir1 ).and_return( :listobject1 )
    39 		expect( Ezmlm::List ).to receive( :new ).with( :listdir1 ).and_return( :listobject1 )
    55 		Ezmlm::List.should_receive( :new ).with( :listdir2 ).and_return( :listobject2 )
    40 		expect( Ezmlm::List ).to receive( :new ).with( :listdir2 ).and_return( :listobject2 )
    56 		
    41 
    57 		lists = []
    42 		lists = []
    58 		Ezmlm.each_list( TEST_LISTSDIR ) do |list|
    43 		Ezmlm.each_list( TEST_LISTSDIR ) do |list|
    59 			lists << list
    44 			lists << list
    60 		end
    45 		end
    61 		
    46 
    62 		lists.should have(2).members
    47 		expect( lists.size ).to eq(2)
    63 		lists.should include( :listobject1, :listobject2 )
    48 		expect( lists ).to include( :listobject1, :listobject2 )
    64 	end
    49 	end
    65 	
       
    66 end
    50 end
    67 
    51 
    68 
    52