spec/ezmlm/list/message_spec.rb
changeset 15 a38e6916504c
child 17 23c7f5c8ee39
equal deleted inserted replaced
14:cba9fb39bcdb 15:a38e6916504c
       
     1 # vim: set nosta noet ts=4 sw=4 ft=rspec:
       
     2 
       
     3 require_relative '../../spec_helpers'
       
     4 
       
     5 
       
     6 describe Ezmlm::List::Message do
       
     7 
       
     8 	before( :all ) do
       
     9 		@listdir = make_listdir()
       
    10 	end
       
    11 
       
    12 	after( :all ) do
       
    13 		rm_r( @listdir )
       
    14 	end
       
    15 
       
    16 	let( :list ) do
       
    17 		Ezmlm::List.new( @listdir )
       
    18 	end
       
    19 
       
    20 
       
    21 	context 'instantiating' do
       
    22 
       
    23 		it 'raises error if provided an unknown list object' do
       
    24 			expect {
       
    25 				described_class.new( true, 1 )
       
    26 			}.to raise_error( ArgumentError, /unknown list/i )
       
    27 		end
       
    28 
       
    29 		it 'raises error if given a message number smaller than possible' do
       
    30 			expect {
       
    31 				described_class.new( list, -20 )
       
    32 			}.to raise_error( ArgumentError, /invalid message number \(impossible/i )
       
    33 			expect {
       
    34 				described_class.new( list, 0 )
       
    35 			}.to raise_error( ArgumentError, /invalid message number \(impossible/i )
       
    36 		end
       
    37 
       
    38 		it 'raises error if given a message higher than the list count' do
       
    39 			expect {
       
    40 				described_class.new( list, 200 )
       
    41 			}.to raise_error( ArgumentError, /invalid message number \(out of list/i )
       
    42 		end
       
    43 
       
    44 		it 'raises error when unable to read message' do
       
    45 			allow( list ).to receive( :listdir ).and_return( Pathname('/nope') )
       
    46 			expect( list ).to receive( :message_count ).and_return( 1 )
       
    47 			expect {
       
    48 				described_class.new( list, 1 )
       
    49 			}.to raise_error( RuntimeError, /unable to determine message path/i )
       
    50 		end
       
    51 
       
    52 		it 'parses a message from the archive' do
       
    53 			message = described_class.new( list, 1 )
       
    54 			expect( message ).to be_a( Ezmlm::List::Message )
       
    55 		end
       
    56 
       
    57 
       
    58 		context 'an instance of' do
       
    59 
       
    60 			let( :message ) { described_class.new( list, 1 ) }
       
    61 
       
    62 			it 'can be stringified' do
       
    63 				expect( message.to_s ).to match( /need to copy the wireless/ )
       
    64 			end
       
    65 
       
    66 			it 'knows what thread it is a member of' do
       
    67 				expect( message.thread ).to be_a( Ezmlm::List::Thread )
       
    68 				expect( message.thread.id ).to eq( 'dipjdfoipmjmlcnacell' )
       
    69 			end
       
    70 
       
    71 			it 'knows the author' do
       
    72 				expect( message.author ).to be_a( Ezmlm::List::Author )
       
    73 				expect( message.author.id ).to eq( 'odhojfifmnbblilkmbfh' )
       
    74 			end
       
    75 
       
    76 			it 'passes all other method calls to the underlying Mail::Message' do
       
    77 				expect( message.to.first ).to eq( 'testlist@lists.laika.com' )
       
    78 				expect( message.body.to_s ).to match( /need to copy the wireless/ )
       
    79 				expect( message.subject ).to match( /Trying to compress/ )
       
    80 			end
       
    81 		end
       
    82 	end
       
    83 end