spec/ezmlm/listdaemon_spec.rb
author Michael Granger <mgranger@laika.com>
Wed, 06 Aug 2008 17:38:56 +0000
changeset 8 308f7dc97753
parent 6 66beb495a861
permissions -rw-r--r--
Trying to fix the build again.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     1
#!/usr/bin/env ruby
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     2
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     3
BEGIN {
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     4
	require 'pathname'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     5
	basedir = Pathname.new( __FILE__ ).dirname.parent.parent
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     6
	
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     7
	libdir = basedir + "lib"
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     8
	
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     9
	$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    10
}
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    11
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    12
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    13
begin
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    14
	require 'ostruct'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    15
	require 'spec/runner'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    16
	require 'spec/lib/helpers'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    17
	require 'ezmlm/listdaemon'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    18
rescue LoadError
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    19
	unless Object.const_defined?( :Gem )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    20
		require 'rubygems'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    21
		retry
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    22
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    23
	raise
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    24
end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    25
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    26
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    27
describe Ezmlm::ListDaemon do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    28
	include Ezmlm::SpecHelpers
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    29
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    30
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    31
	DEFAULT_ADDRESS = Ezmlm::ListDaemon::DEFAULT_ADDRESS
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    32
	DEFAULT_PORT = Ezmlm::ListDaemon::DEFAULT_PORT
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    33
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    34
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    35
	it "can return a struct that contains its default options" do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    36
		opts = Ezmlm::ListDaemon.default_options
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    37
		
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    38
		opts.should be_an_instance_of( OpenStruct )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    39
		opts.bind_addr.should == DEFAULT_ADDRESS
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    40
		opts.bind_port.should == DEFAULT_PORT
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    41
		opts.debugmode.should == false
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    42
		opts.helpmode.should == false
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    43
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    44
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    45
	describe "created with defaults" do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    46
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    47
		DEFAULT_URL = "druby://%s:%d" % [ DEFAULT_ADDRESS, DEFAULT_PORT ]
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    48
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    49
		before( :each ) do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    50
			@test_list_dir = Pathname.new( 'lists' )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    51
			@daemon = Ezmlm::ListDaemon.new( @test_list_dir )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    52
		end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    53
		
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    54
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    55
		it "can be started and will return a thread" do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    56
			mock_drb_thread = mock( "drb thread" )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    57
			
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    58
			DRb.should_receive( :start_service ).with( DEFAULT_URL, @daemon.service )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    59
			DRb.should_receive( :thread ).and_return( mock_drb_thread )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    60
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    61
			@daemon.start.should == mock_drb_thread
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    62
		end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    63
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    64
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    65
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    66
	describe "created with an options struct" do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    67
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    68
		TEST_ADDRESS = '0.0.0.0'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    69
		TEST_PORT = 17771
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    70
		TEST_URL = "druby://%s:%d" % [ TEST_ADDRESS, TEST_PORT ]
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    71
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    72
		before( :each ) do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    73
			@test_list_dir = Pathname.new( 'lists' )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    74
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    75
			@opts = Ezmlm::ListDaemon.default_options
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    76
			@opts.bind_addr = TEST_ADDRESS
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    77
			@opts.bind_port = TEST_PORT
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    78
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    79
			@daemon = Ezmlm::ListDaemon.new( @test_list_dir, @opts )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    80
		end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    81
		
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    82
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    83
		it "can be started and will return a thread" do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    84
			mock_drb_thread = mock( "drb thread" )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    85
			
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    86
			DRb.should_receive( :start_service ).with( TEST_URL, @daemon.service )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    87
			DRb.should_receive( :thread ).and_return( mock_drb_thread )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    88
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    89
			@daemon.start.should == mock_drb_thread
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    90
		end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    91
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    92
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    93
end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    94
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    95
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    96
describe Ezmlm::ListDaemon::Service do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    97
	
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    98
	before( :each ) do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    99
		@dummydir = 'lists'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   100
		@service = Ezmlm::ListDaemon::Service.new( @dummydir )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   101
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   102
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   103
	
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   104
	it "can return a list object by name if there is a corresponding listdir" do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   105
		@service.get_list( 'announce' ).should be_an_instance_of( Ezmlm::List )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   106
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   107
	
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   108
	it "raises an exception when asked for a list whose name contains invalid characters" do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   109
		lambda {
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   110
			@service.get_list( 'glarg beegun' )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   111
		}.should raise_error( ArgumentError )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   112
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   113
	
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   114
	it "can iterate over listdirs, yielding each as a Ezmlm::List object" do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   115
		Ezmlm.should_receive( :each_list ).with( Pathname.new(@dummydir) ).and_yield( :a_list )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   116
		@service.each_list {|l| l.should == :a_list }
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   117
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   118
	
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   119
end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   120
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   121
# listservice = DRbObject.new( nil, 'druby://lists.laika.com:23431' )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   122
# announce = listservice.each_list do |list|
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   123
# 	last_posts << list.last_post
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   124
# end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   125
# announce = listservice.get_list( 'announce' )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   126
# 
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   127
# announce.last_post
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   128
# 
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   129
#