diff options
Diffstat (limited to 'spec/chotto_spec.rb')
-rw-r--r-- | spec/chotto_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/chotto_spec.rb b/spec/chotto_spec.rb new file mode 100644 index 0000000..9e8650b --- /dev/null +++ b/spec/chotto_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'rspec' +require_relative '../lib/chotto' + +describe Chotto do + let(:db_double) { double('::Notmuch::Database') } + let(:db_instance_double) { double('::Notmuch::Database') } + let(:db_query_double) { double('::Notmuch::Query') } + let(:message_double) { double('::Notmuch::Message') } + + before do + $db_double = db_double # we need to access this double within block evaled elsewhere + + allow(db_double).to receive(:new).with('/path', mode: Notmuch::MODE_READ_WRITE).and_return(db_instance_double) + + allow(db_instance_double).to receive(:query).with(' (from:baltar@galactica.com)').and_return(db_query_double) + allow(db_query_double).to receive(:search_messages).and_return([message_double]) + + Chotto.configure do + config.database_path = '/path' + config.db_class = $db_double + end + + Chotto.rule_set 'sample' do + messages.or.filter(from: 'baltar@galactica.com').each do |msg| + msg.tags = msg.subject == 'Number Six' ? [:todo] : [:spam] + msg.save! + end + end + end + + it 'sends the rules to Notmuch - scenario 1' do + expect(message_double).to receive(:tags).and_return([]) + expect(message_double).to receive(:header).with('Subject').and_return('Number Six') + expect(message_double).to receive(:remove_all_tags) + expect(message_double).to receive(:add_tag).with('todo') + expect(db_instance_double).to receive(:close) + + eval_rules + end + + it 'sends the rules to Notmuch - scenario 2' do + expect(message_double).to receive(:tags).and_return([]) + expect(message_double).to receive(:header).with('Subject').and_return('Boomer') + expect(message_double).to receive(:remove_all_tags) + expect(message_double).to receive(:add_tag).with('spam') + expect(db_instance_double).to receive(:close) + + eval_rules + end +end |