# frozen_string_literal: true require 'rspec' require 'notmuch' 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