aboutsummaryrefslogtreecommitdiff
path: root/spec/lib/database_spec.rb
blob: 8da04e45d76a00569a42def46fd444b02dc8bd0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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