diff options
Diffstat (limited to 'spec/lib/database_spec.rb')
-rw-r--r-- | spec/lib/database_spec.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/lib/database_spec.rb b/spec/lib/database_spec.rb new file mode 100644 index 0000000..8da04e4 --- /dev/null +++ b/spec/lib/database_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'rspec' +require_relative '../../lib/chotto/database' + +RSpec.describe Chotto::Database do + let(:db_double) { double('Notmuch::Database') } + let(:db_instance_double) { double('Notmuch::Database') } + let(:query_double) { double('Notmuch::Query') } + let(:query) { 'from:baltar@battlestar.com' } + let(:path) { '/var/db/mail' } + let(:subject) { Chotto::Database } + + before do + expect(db_double).to receive(:new).with(path, mode: Notmuch::MODE_READ_WRITE).and_return(db_instance_double) + end + + it 'initializes the database instance' do + subject.new(path: path, db_class: db_double) + end + + describe '#search_messages' do + it 'uses the correct method chain' do + expect(db_instance_double).to receive(:query).with(query).and_return(query_double) + expect(query_double).to receive(:search_messages) + + db = subject.new(path: path, db_class: db_double) + db.search_messages(query) + end + end +end |