15
|
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 )
|
17
|
47 |
expect( list ).to receive( :archived? ).and_return( true )
|
15
|
48 |
expect {
|
|
49 |
described_class.new( list, 1 )
|
|
50 |
}.to raise_error( RuntimeError, /unable to determine message path/i )
|
|
51 |
end
|
|
52 |
|
|
53 |
it 'parses a message from the archive' do
|
|
54 |
message = described_class.new( list, 1 )
|
|
55 |
expect( message ).to be_a( Ezmlm::List::Message )
|
|
56 |
end
|
|
57 |
|
|
58 |
|
|
59 |
context 'an instance of' do
|
|
60 |
|
|
61 |
let( :message ) { described_class.new( list, 1 ) }
|
|
62 |
|
|
63 |
it 'can be stringified' do
|
|
64 |
expect( message.to_s ).to match( /need to copy the wireless/ )
|
|
65 |
end
|
|
66 |
|
|
67 |
it 'knows what thread it is a member of' do
|
|
68 |
expect( message.thread ).to be_a( Ezmlm::List::Thread )
|
|
69 |
expect( message.thread.id ).to eq( 'dipjdfoipmjmlcnacell' )
|
|
70 |
end
|
|
71 |
|
|
72 |
it 'knows the author' do
|
|
73 |
expect( message.author ).to be_a( Ezmlm::List::Author )
|
|
74 |
expect( message.author.id ).to eq( 'odhojfifmnbblilkmbfh' )
|
|
75 |
end
|
|
76 |
|
|
77 |
it 'passes all other method calls to the underlying Mail::Message' do
|
|
78 |
expect( message.to.first ).to eq( 'testlist@lists.laika.com' )
|
|
79 |
expect( message.body.to_s ).to match( /need to copy the wireless/ )
|
|
80 |
expect( message.subject ).to match( /Trying to compress/ )
|
|
81 |
end
|
|
82 |
end
|
|
83 |
end
|
|
84 |
end
|