Everything is workin!
- Add a corpus of test messages to the spec data, with the script that generated them. - Add native objects for Authors, Messages, and Threads. - Tests!
This commit is contained in:
parent
7e2a6fe771
commit
7339802f34
334 changed files with 3978 additions and 71 deletions
83
spec/ezmlm/list/author_spec.rb
Normal file
83
spec/ezmlm/list/author_spec.rb
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
# vim: set nosta noet ts=4 sw=4 ft=rspec:
|
||||
|
||||
require_relative '../../spec_helpers'
|
||||
|
||||
|
||||
describe Ezmlm::List::Author do
|
||||
|
||||
before( :all ) do
|
||||
@listdir = make_listdir()
|
||||
end
|
||||
|
||||
after( :all ) do
|
||||
rm_r( @listdir )
|
||||
end
|
||||
|
||||
let( :list ) do
|
||||
Ezmlm::List.new( @listdir )
|
||||
end
|
||||
|
||||
let ( :author_id ) { "idijebinbeadbfecldlb" }
|
||||
|
||||
|
||||
context 'instantiating' do
|
||||
|
||||
it 'raises error if provided an unknown list object' do
|
||||
expect {
|
||||
described_class.new( true, 1 )
|
||||
}.to raise_error( ArgumentError, /unknown list/i )
|
||||
end
|
||||
|
||||
it 'raises error if thread indexing is disabled' do
|
||||
expect( list ).to receive( :threaded? ).and_return( false )
|
||||
expect {
|
||||
described_class.new( list, author_id )
|
||||
}.to raise_error( RuntimeError, /indexing is not enabled/i )
|
||||
end
|
||||
|
||||
it 'raises error if passed a malformed author ID' do
|
||||
expect {
|
||||
described_class.new( list, 'whatever' )
|
||||
}.to raise_error( ArgumentError, /malformed/i )
|
||||
end
|
||||
|
||||
it 'raises error when unable to read index file' do
|
||||
allow( list ).to receive( :listdir ).and_return( Pathname('/nope') )
|
||||
expect( list ).to receive( :threaded? ).and_return( true )
|
||||
expect {
|
||||
described_class.new( list, author_id )
|
||||
}.to raise_error( RuntimeError, /unknown author/i )
|
||||
end
|
||||
|
||||
it 'parses an author index from the archive' do
|
||||
author = described_class.new( list, author_id )
|
||||
expect( author ).to be_a( Ezmlm::List::Author )
|
||||
end
|
||||
|
||||
context 'an instance of' do
|
||||
|
||||
let( :author ) { described_class.new( list, author_id ) }
|
||||
|
||||
it 'knows the author name' do
|
||||
expect( author.name ).to match( /Jessy Labadie/i )
|
||||
end
|
||||
|
||||
it 'holds messages that belong to the author' do
|
||||
expect( author.messages.size ).to be( 1 )
|
||||
expect( author.first.subject ).to match( /interface/i )
|
||||
expect( author.first.body.to_s ).to match( /protocol/i )
|
||||
expect( author.first.from.first ).to match( /karianne@example.net/i )
|
||||
end
|
||||
|
||||
it 'holds threads that the author has participated in' do
|
||||
expect( author.threads.size ).to be( 1 )
|
||||
expect( author.threads.first ).to eq( 'caaabjkbghlcbokpfpeg' )
|
||||
end
|
||||
|
||||
it 'is enumerable' do
|
||||
expect( author.any?{|m| m.id == 111 }).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
83
spec/ezmlm/list/message_spec.rb
Normal file
83
spec/ezmlm/list/message_spec.rb
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
# vim: set nosta noet ts=4 sw=4 ft=rspec:
|
||||
|
||||
require_relative '../../spec_helpers'
|
||||
|
||||
|
||||
describe Ezmlm::List::Message do
|
||||
|
||||
before( :all ) do
|
||||
@listdir = make_listdir()
|
||||
end
|
||||
|
||||
after( :all ) do
|
||||
rm_r( @listdir )
|
||||
end
|
||||
|
||||
let( :list ) do
|
||||
Ezmlm::List.new( @listdir )
|
||||
end
|
||||
|
||||
|
||||
context 'instantiating' do
|
||||
|
||||
it 'raises error if provided an unknown list object' do
|
||||
expect {
|
||||
described_class.new( true, 1 )
|
||||
}.to raise_error( ArgumentError, /unknown list/i )
|
||||
end
|
||||
|
||||
it 'raises error if given a message number smaller than possible' do
|
||||
expect {
|
||||
described_class.new( list, -20 )
|
||||
}.to raise_error( ArgumentError, /invalid message number \(impossible/i )
|
||||
expect {
|
||||
described_class.new( list, 0 )
|
||||
}.to raise_error( ArgumentError, /invalid message number \(impossible/i )
|
||||
end
|
||||
|
||||
it 'raises error if given a message higher than the list count' do
|
||||
expect {
|
||||
described_class.new( list, 200 )
|
||||
}.to raise_error( ArgumentError, /invalid message number \(out of list/i )
|
||||
end
|
||||
|
||||
it 'raises error when unable to read message' do
|
||||
allow( list ).to receive( :listdir ).and_return( Pathname('/nope') )
|
||||
expect( list ).to receive( :message_count ).and_return( 1 )
|
||||
expect {
|
||||
described_class.new( list, 1 )
|
||||
}.to raise_error( RuntimeError, /unable to determine message path/i )
|
||||
end
|
||||
|
||||
it 'parses a message from the archive' do
|
||||
message = described_class.new( list, 1 )
|
||||
expect( message ).to be_a( Ezmlm::List::Message )
|
||||
end
|
||||
|
||||
|
||||
context 'an instance of' do
|
||||
|
||||
let( :message ) { described_class.new( list, 1 ) }
|
||||
|
||||
it 'can be stringified' do
|
||||
expect( message.to_s ).to match( /need to copy the wireless/ )
|
||||
end
|
||||
|
||||
it 'knows what thread it is a member of' do
|
||||
expect( message.thread ).to be_a( Ezmlm::List::Thread )
|
||||
expect( message.thread.id ).to eq( 'dipjdfoipmjmlcnacell' )
|
||||
end
|
||||
|
||||
it 'knows the author' do
|
||||
expect( message.author ).to be_a( Ezmlm::List::Author )
|
||||
expect( message.author.id ).to eq( 'odhojfifmnbblilkmbfh' )
|
||||
end
|
||||
|
||||
it 'passes all other method calls to the underlying Mail::Message' do
|
||||
expect( message.to.first ).to eq( 'testlist@lists.laika.com' )
|
||||
expect( message.body.to_s ).to match( /need to copy the wireless/ )
|
||||
expect( message.subject ).to match( /Trying to compress/ )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
87
spec/ezmlm/list/thread_spec.rb
Normal file
87
spec/ezmlm/list/thread_spec.rb
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
# vim: set nosta noet ts=4 sw=4 ft=rspec:
|
||||
|
||||
require_relative '../../spec_helpers'
|
||||
|
||||
|
||||
describe Ezmlm::List::Thread do
|
||||
|
||||
before( :all ) do
|
||||
@listdir = make_listdir()
|
||||
end
|
||||
|
||||
after( :all ) do
|
||||
rm_r( @listdir )
|
||||
end
|
||||
|
||||
let( :list ) do
|
||||
Ezmlm::List.new( @listdir )
|
||||
end
|
||||
|
||||
let ( :thread_id ) { "hdohjgmgfakappbhjnkp" }
|
||||
|
||||
|
||||
context 'instantiating' do
|
||||
|
||||
it 'raises error if provided an unknown list object' do
|
||||
expect {
|
||||
described_class.new( true, 1 )
|
||||
}.to raise_error( ArgumentError, /unknown list/i )
|
||||
end
|
||||
|
||||
it 'raises error if thread indexing is disabled' do
|
||||
expect( list ).to receive( :threaded? ).and_return( false )
|
||||
expect {
|
||||
described_class.new( list, thread_id )
|
||||
}.to raise_error( RuntimeError, /indexing is not enabled/i )
|
||||
end
|
||||
|
||||
it 'raises error if passed a malformed thread ID' do
|
||||
expect {
|
||||
described_class.new( list, 'whatever' )
|
||||
}.to raise_error( ArgumentError, /malformed/i )
|
||||
end
|
||||
|
||||
it 'raises error when unable to read thread file' do
|
||||
allow( list ).to receive( :listdir ).and_return( Pathname('/nope') )
|
||||
expect( list ).to receive( :threaded? ).and_return( true )
|
||||
expect {
|
||||
described_class.new( list, thread_id )
|
||||
}.to raise_error( RuntimeError, /unknown thread/i )
|
||||
end
|
||||
|
||||
it 'parses a thread index from the archive' do
|
||||
thread = described_class.new( list, thread_id )
|
||||
expect( thread ).to be_a( Ezmlm::List::Thread )
|
||||
end
|
||||
|
||||
|
||||
context 'an instance of' do
|
||||
|
||||
let( :thread ) { described_class.new( list, thread_id ) }
|
||||
|
||||
it 'knows its subject' do
|
||||
expect( thread.subject ).to match( /ai on the microchip/i )
|
||||
end
|
||||
|
||||
it 'contains a list of message ids' do
|
||||
expect( thread.messages ).to eq( [20, 108] )
|
||||
end
|
||||
|
||||
it 'contains a list of author ids' do
|
||||
expect( thread.authors ).to eq( ["mdncdmmkeffdjkopffbj", "ffcambaeljjifcodfjoc"] )
|
||||
end
|
||||
|
||||
it 'holds messages that belong to the thread' do
|
||||
expect( thread.messages.size ).to be( 2 )
|
||||
expect( thread.first.subject ).to match( /microchip/i )
|
||||
expect( thread.first.body.to_s ).to match( /protocol/i )
|
||||
expect( thread.first.from.first ).to match( /block@example.net/i )
|
||||
end
|
||||
|
||||
it 'is enumerable' do
|
||||
expect( thread.any?{|m| m.id == 20 }).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue