gitlab-mail_room 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3aef2538505e8ae118f1a7ad8fe25d1ced7dff264f74427b0e8a4ebe4b07bec1
4
- data.tar.gz: f765a548cbb934e04a482852501b6c6d66055528649db07828a01315667f8f32
3
+ metadata.gz: 8ccfebf927b528ccf65a3c9abefe2bc01af5b65797cf37e8f8ac969e2ffb8542
4
+ data.tar.gz: e95297059e57bafea5ddb2a11a0d1394b2b7480c71cbef995644023a98b6fd18
5
5
  SHA512:
6
- metadata.gz: 041ee7bec2b17ce6af2de5db39a36403b8c51ea9ba58e0b4bfeb0cf5ca6298cae8ee8e902e8391c0f9200e3dfbf03bbf5831a4e938862ddf813b1229996c6f00
7
- data.tar.gz: 0f67f7e7f883b743f279f1af998f8172d47807592394318b7b1bcac7421ebc9d8400c3bd9c58648208a6dd3253cb3e652faf4b84c53e90e993360e1595bf05f5
6
+ metadata.gz: 934aa18912e38b2128a8409998610869441964d80c898b0f97de6e6abef96b9b8169640bb139fdfdaaa2b0f4ce8b05cd97f904b7be9355b7e68dea0d5fc3b928
7
+ data.tar.gz: 5ddae279a3821c965921e23694a5cf5a880f46ee1ba6b56aa7f6bf3b2b1c38df4e19df3a555382a52b2da127d16d0646f641bbe8f587a45c7612649f5f7a1988
@@ -1,9 +1,14 @@
1
1
  # Cache gems in between builds
2
2
 
3
+ services:
4
+ - redis:latest
5
+
3
6
  .test-template: &test
4
7
  cache:
5
8
  paths:
6
9
  - vendor/ruby
10
+ variables:
11
+ REDIS_URL: redis://redis:6379
7
12
  script:
8
13
  - bundle exec rspec spec
9
14
  before_script:
@@ -0,0 +1,7 @@
1
+ # GitLab mail_room release checklist
2
+
3
+ - [ ] create tag in https://gitlab.com/gitlab-org/gitlab-mail_room/
4
+ - [ ] publish gem from this tag to rubygems.org
5
+ - [ ] update https://gitlab.com/gitlab-org/gitlab/-/blob/master/Gemfile to use the new gem version
6
+ - [ ] update gitlab-org/build/CNG to build container images from the new gem (example: https://gitlab.com/gitlab-org/build/CNG/-/merge_requests/451/diffs)
7
+ - [ ] to deploy the new version to gitlab.com, update gitlab-com/gl-infra/k8s-workloads/gitlab-com to pin the new mailroom container image version and assign it the [release managers](https://about.gitlab.com/community/release-managers/) (example: https://gitlab.com/gitlab-com/gl-infra/k8s-workloads/gitlab-com/-/merge_requests/236/diffs)
@@ -57,7 +57,7 @@ module MailRoom
57
57
 
58
58
  coordinator.run
59
59
  rescue Exception => e # not just Errors, but includes lower-level Exceptions
60
- CrashHandler.new(error: e, format: @options[:exit_error_format]).handle
60
+ CrashHandler.new.handle(e, @options[:exit_error_format])
61
61
  exit
62
62
  end
63
63
  end
@@ -27,7 +27,7 @@ module MailRoom
27
27
  # is the imap connection closed?
28
28
  # @return [Boolean]
29
29
  def disconnected?
30
- @imap.disconnected?
30
+ imap.disconnected?
31
31
  end
32
32
 
33
33
  # is the connection ready to idle?
@@ -174,7 +174,7 @@ module MailRoom
174
174
  # @return [Array<Integer>] message ids
175
175
  def new_message_ids
176
176
  # uid_search still leaves messages UNSEEN
177
- all_unread = @imap.uid_search(@mailbox.search_command)
177
+ all_unread = imap.uid_search(@mailbox.search_command)
178
178
 
179
179
  to_deliver = all_unread.select { |uid| @mailbox.deliver?(uid) }
180
180
  @mailbox.logger.info({ context: @mailbox.context, action: "Getting new messages", unread: {count: all_unread.count, ids: all_unread}, to_be_delivered: { count: to_deliver.count, ids: all_unread } })
@@ -2,28 +2,24 @@
2
2
  module MailRoom
3
3
  class CrashHandler
4
4
 
5
- attr_reader :error, :format
5
+ SUPPORTED_FORMATS = %w[json none]
6
6
 
7
- SUPPORTED_FORMATS = %w[json plain]
8
-
9
- def initialize(error:, format:)
10
- @error = error
11
- @format = format
7
+ def initialize(stream=STDOUT)
8
+ @stream = stream
12
9
  end
13
10
 
14
- def handle
11
+ def handle(error, format)
15
12
  if format == 'json'
16
- puts json
13
+ @stream.puts json(error)
17
14
  return
18
15
  end
19
16
 
20
- # 'plain' is equivalent to outputting the error into stdout as-is
21
17
  raise error
22
18
  end
23
19
 
24
20
  private
25
21
 
26
- def json
22
+ def json(error)
27
23
  { time: Time.now, severity: :fatal, message: error.message, backtrace: error.backtrace }.to_json
28
24
  end
29
25
  end
@@ -1,4 +1,4 @@
1
1
  module MailRoom
2
- # Current version of MailRoom gem
3
- VERSION = "0.0.4"
2
+ # Current version of gitlab-mail_room gem
3
+ VERSION = "0.0.6"
4
4
  end
@@ -18,9 +18,8 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_development_dependency "rake"
21
- gem.add_development_dependency "rspec"
22
- gem.add_development_dependency "mocha"
23
- gem.add_development_dependency "bourne"
21
+ gem.add_development_dependency "rspec", "~> 3.9"
22
+ gem.add_development_dependency "mocha", "~> 1.11"
24
23
  gem.add_development_dependency "simplecov"
25
24
 
26
25
  # for testing delivery methods
@@ -5,7 +5,8 @@ describe MailRoom::Arbitration::Redis do
5
5
  let(:mailbox) {
6
6
  build_mailbox(
7
7
  arbitration_options: {
8
- namespace: "mail_room"
8
+ namespace: "mail_room",
9
+ redis_url: ENV['REDIS_URL']
9
10
  }
10
11
  )
11
12
  }
@@ -78,7 +79,7 @@ describe MailRoom::Arbitration::Redis do
78
79
 
79
80
  context 'redis client connection params' do
80
81
  context 'when only url is present' do
81
- let(:redis_url) { "redis://localhost:6379" }
82
+ let(:redis_url) { ENV.fetch('REDIS_URL', 'redis://localhost:6379') }
82
83
  let(:mailbox) {
83
84
  build_mailbox(
84
85
  arbitration_options: {
@@ -4,23 +4,35 @@ describe MailRoom::CLI do
4
4
  let(:config_path) {File.expand_path('../fixtures/test_config.yml', File.dirname(__FILE__))}
5
5
  let!(:configuration) {MailRoom::Configuration.new({:config_path => config_path})}
6
6
  let(:coordinator) {stub(:run => true, :quit => true)}
7
+ let(:configuration_args) { anything }
8
+ let(:coordinator_args) { anything }
7
9
 
8
10
  describe '.new' do
9
11
  let(:args) {["-c", "a path"]}
10
12
 
11
13
  before :each do
12
- MailRoom::Configuration.stubs(:new).returns(configuration)
13
- MailRoom::Coordinator.stubs(:new).returns(coordinator)
14
+ MailRoom::Configuration.expects(:new).with(configuration_args).returns(configuration)
15
+ MailRoom::Coordinator.stubs(:new).with(coordinator_args).returns(coordinator)
14
16
  end
15
17
 
16
- it 'parses arguments into configuration' do
17
- expect(MailRoom::CLI.new(args).configuration).to eq(configuration)
18
- expect(MailRoom::Configuration).to have_received(:new).with({:config_path => 'a path'})
18
+ context 'with configuration args' do
19
+ let(:configuration_args) do
20
+ {:config_path => 'a path'}
21
+ end
22
+
23
+ it 'parses arguments into configuration' do
24
+ expect(MailRoom::CLI.new(args).configuration).to eq configuration
25
+ end
19
26
  end
20
27
 
21
- it 'creates a new coordinator with configuration' do
22
- expect(MailRoom::CLI.new(args).coordinator).to eq(coordinator)
23
- expect(MailRoom::Coordinator).to have_received(:new).with(configuration.mailboxes)
28
+ context 'with coordinator args' do
29
+ let(:coordinator_args) do
30
+ configuration.mailboxes
31
+ end
32
+
33
+ it 'creates a new coordinator with configuration' do
34
+ expect(MailRoom::CLI.new(args).coordinator).to eq(coordinator)
35
+ end
24
36
  end
25
37
  end
26
38
 
@@ -30,30 +42,33 @@ describe MailRoom::CLI do
30
42
  before :each do
31
43
  cli.configuration = configuration
32
44
  cli.coordinator = coordinator
45
+ cli.stubs(:exit)
33
46
  end
34
47
 
35
48
  it 'starts running the coordinator' do
36
- cli.start
49
+ coordinator.expects(:run)
37
50
 
38
- expect(coordinator).to have_received(:run)
51
+ cli.start
39
52
  end
40
53
 
41
54
  context 'on error' do
42
- let(:error_message) { "oh noes!" }
43
- let(:coordinator) { OpenStruct.new(run: true, quit: true) }
55
+ let(:error) { RuntimeError.new("oh noes!") }
56
+ let(:coordinator) { stub(run: true, quit: true) }
57
+ let(:crash_handler) { stub(handle: nil) }
44
58
 
45
59
  before do
46
60
  cli.instance_variable_set(:@options, {exit_error_format: error_format})
47
- coordinator.stubs(:run).raises(RuntimeError, error_message)
61
+ coordinator.stubs(:run).raises(error)
62
+ MailRoom::CrashHandler.stubs(:new).returns(crash_handler)
48
63
  end
49
64
 
50
65
  context 'json format provided' do
51
66
  let(:error_format) { 'json' }
52
67
 
53
68
  it 'passes onto CrashHandler' do
54
- cli.start
69
+ crash_handler.expects(:handle).with(error, error_format)
55
70
 
56
- expect(MailRoom::CrashHandler).to have_received(:new).with a_hash_including({format: error_format})
71
+ cli.start
57
72
  end
58
73
  end
59
74
  end
@@ -19,10 +19,9 @@ describe MailRoom::Configuration do
19
19
 
20
20
  it 'sets mailboxes to an empty set' do
21
21
  MailRoom::Mailbox.stubs(:new)
22
+ MailRoom::Mailbox.expects(:new).never
22
23
 
23
24
  expect(configuration.mailboxes).to eq([])
24
-
25
- expect(MailRoom::Mailbox).to have_received(:new).never
26
25
  end
27
26
  end
28
27
  end
@@ -44,22 +44,14 @@ describe MailRoom::Connection do
44
44
  true
45
45
  end
46
46
 
47
- mailbox.stubs(:deliver?).returns(true)
48
-
49
- imap.stubs(:idle)
50
- imap.stubs(:uid_search).returns([]).then.returns([1])
51
- imap.stubs(:uid_fetch).returns([new_message])
52
- imap.stubs(:store)
53
- imap.stubs(:expunge)
47
+ imap.expects(:idle)
48
+ imap.stubs(:uid_search).with(mailbox.search_command).returns([], [1])
49
+ imap.expects(:uid_fetch).with([1], "RFC822").returns([new_message])
50
+ mailbox.expects(:deliver?).with(1).returns(true)
51
+ imap.expects(:store).with(8, "+FLAGS", [Net::IMAP::DELETED])
52
+ imap.expects(:expunge).once
54
53
 
55
54
  connection.wait
56
-
57
- expect(imap).to have_received(:idle)
58
- expect(imap).to have_received(:uid_search).with(mailbox.search_command).twice
59
- expect(imap).to have_received(:uid_fetch).with([1], "RFC822")
60
- expect(mailbox).to have_received(:deliver?).with(1)
61
- expect(imap).to have_received(:store).with(8, "+FLAGS", [Net::IMAP::DELETED])
62
- expect(imap).to have_received(:expunge).once
63
55
  end
64
56
  end
65
57
  end
@@ -3,14 +3,12 @@ require 'spec_helper'
3
3
  describe MailRoom::Coordinator do
4
4
  describe '#initialize' do
5
5
  it 'builds a watcher for each mailbox' do
6
- MailRoom::MailboxWatcher.stubs(:new).returns('watcher1', 'watcher2')
6
+ MailRoom::MailboxWatcher.expects(:new).with('mailbox1').returns('watcher1')
7
+ MailRoom::MailboxWatcher.expects(:new).with('mailbox2').returns('watcher2')
7
8
 
8
9
  coordinator = MailRoom::Coordinator.new(['mailbox1', 'mailbox2'])
9
10
 
10
11
  expect(coordinator.watchers).to eq(['watcher1', 'watcher2'])
11
-
12
- expect(MailRoom::MailboxWatcher).to have_received(:new).with('mailbox1')
13
- expect(MailRoom::MailboxWatcher).to have_received(:new).with('mailbox2')
14
12
  end
15
13
 
16
14
  it 'makes no watchers when mailboxes is empty' do
@@ -27,24 +25,27 @@ describe MailRoom::Coordinator do
27
25
  MailRoom::MailboxWatcher.stubs(:new).returns(watcher)
28
26
  coordinator = MailRoom::Coordinator.new(['mailbox1'])
29
27
  coordinator.stubs(:sleep_while_running)
28
+ watcher.expects(:run)
29
+ watcher.expects(:quit)
30
+
30
31
  coordinator.run
31
- expect(watcher).to have_received(:run)
32
- expect(watcher).to have_received(:quit)
33
32
  end
34
33
 
35
34
  it 'should go to sleep after running watchers' do
36
35
  coordinator = MailRoom::Coordinator.new([])
37
36
  coordinator.stubs(:running=)
38
37
  coordinator.stubs(:running?).returns(false)
38
+ coordinator.expects(:running=).with(true)
39
+ coordinator.expects(:running?)
40
+
39
41
  coordinator.run
40
- expect(coordinator).to have_received(:running=).with(true)
41
- expect(coordinator).to have_received(:running?)
42
42
  end
43
43
 
44
44
  it 'should set attribute running to true' do
45
45
  coordinator = MailRoom::Coordinator.new([])
46
46
  coordinator.stubs(:sleep_while_running)
47
47
  coordinator.run
48
+
48
49
  expect(coordinator.running).to eq(true)
49
50
  end
50
51
  end
@@ -54,8 +55,9 @@ describe MailRoom::Coordinator do
54
55
  watcher = stub(:quit)
55
56
  MailRoom::MailboxWatcher.stubs(:new).returns(watcher)
56
57
  coordinator = MailRoom::Coordinator.new(['mailbox1'])
58
+ watcher.expects(:quit)
59
+
57
60
  coordinator.quit
58
- expect(watcher).to have_received(:quit)
59
61
  end
60
62
  end
61
63
  end
@@ -4,21 +4,22 @@ describe MailRoom::CrashHandler do
4
4
 
5
5
  let(:error_message) { "oh noes!" }
6
6
  let(:error) { RuntimeError.new(error_message) }
7
+ let(:stdout) { StringIO.new }
7
8
 
8
9
  describe '#handle' do
9
10
 
10
- subject{ described_class.new(error: error, format: format) }
11
+ subject{ described_class.new(stdout).handle(error, format) }
11
12
 
12
13
  context 'when given a json format' do
13
14
  let(:format) { 'json' }
14
- let(:fake_json) do
15
- { message: error_message }.to_json
16
- end
17
15
 
18
- it 'outputs the result of json to stdout' do
19
- subject.stubs(:json).returns(fake_json)
16
+ it 'writes a json message to stdout' do
17
+ subject
18
+ stdout.rewind
19
+ output = stdout.read
20
20
 
21
- expect{ subject.handle }.to output(/\"message\":\"#{error_message}\"/).to_stdout
21
+ expect(output).to end_with("\n")
22
+ expect(JSON.parse(output)['message']).to eq(error_message)
22
23
  end
23
24
  end
24
25
 
@@ -26,7 +27,7 @@ describe MailRoom::CrashHandler do
26
27
  let(:format) { "" }
27
28
 
28
29
  it 'raises an error as designed' do
29
- expect{ subject.handle }.to raise_error(error.class, error_message)
30
+ expect{ subject }.to raise_error(error.class, error_message)
30
31
  end
31
32
  end
32
33
 
@@ -34,7 +35,7 @@ describe MailRoom::CrashHandler do
34
35
  let(:format) { "nonsense" }
35
36
 
36
37
  it 'raises an error as designed' do
37
- expect{ subject.handle }.to raise_error(error.class, error_message)
38
+ expect{ subject }.to raise_error(error.class, error_message)
38
39
  end
39
40
  end
40
41
  end
@@ -10,20 +10,24 @@ describe MailRoom::Delivery::LetterOpener do
10
10
  before :each do
11
11
  Mail.stubs(:read_from_string).returns(mail)
12
12
  ::LetterOpener::DeliveryMethod.stubs(:new).returns(delivery_method)
13
-
14
- MailRoom::Delivery::LetterOpener.new(mailbox).deliver('a message')
15
13
  end
16
14
 
17
15
  it 'creates a new LetterOpener::DeliveryMethod' do
18
- expect(::LetterOpener::DeliveryMethod).to have_received(:new).with(:location => '/tmp/somewhere')
16
+ ::LetterOpener::DeliveryMethod.expects(:new).with(:location => '/tmp/somewhere').returns(delivery_method)
17
+
18
+ MailRoom::Delivery::LetterOpener.new(mailbox).deliver('a message')
19
19
  end
20
20
 
21
21
  it 'parses the message string with Mail' do
22
- expect(::Mail).to have_received(:read_from_string).with('a message')
22
+ ::Mail.expects(:read_from_string).with('a message')
23
+
24
+ MailRoom::Delivery::LetterOpener.new(mailbox).deliver('a message')
23
25
  end
24
26
 
25
27
  it 'delivers the mail message' do
26
- expect(delivery_method).to have_received(:deliver!).with(mail)
28
+ delivery_method.expects(:deliver!).with(mail)
29
+
30
+ MailRoom::Delivery::LetterOpener.new(mailbox).deliver('a message')
27
31
  end
28
32
  end
29
33
  end
@@ -9,9 +9,9 @@ describe MailRoom::Delivery::Logger do
9
9
  it 'creates a new ruby logger' do
10
10
  ::Logger.stubs(:new)
11
11
 
12
- MailRoom::Delivery::Logger.new(mailbox)
12
+ ::Logger.expects(:new).with(STDOUT)
13
13
 
14
- expect(::Logger).to have_received(:new).with(STDOUT)
14
+ MailRoom::Delivery::Logger.new(mailbox)
15
15
  end
16
16
  end
17
17
 
@@ -19,14 +19,12 @@ describe MailRoom::Delivery::Logger do
19
19
  let(:mailbox) {build_mailbox(:log_path => '/var/log/mail-room.log')}
20
20
 
21
21
  it 'creates a new file to append to' do
22
- ::Logger.stubs(:new)
23
22
  file = stub(:sync=)
24
- ::File.stubs(:open).returns(file)
25
23
 
26
- MailRoom::Delivery::Logger.new(mailbox)
24
+ File.expects(:open).with('/var/log/mail-room.log', 'a').returns(file)
25
+ ::Logger.stubs(:new).with(file)
27
26
 
28
- expect(File).to have_received(:open).with('/var/log/mail-room.log', 'a')
29
- expect(::Logger).to have_received(:new).with(file)
27
+ MailRoom::Delivery::Logger.new(mailbox)
30
28
  end
31
29
  end
32
30
  end
@@ -38,9 +36,9 @@ describe MailRoom::Delivery::Logger do
38
36
  logger = stub(:info)
39
37
  ::Logger.stubs(:new).returns(logger)
40
38
 
41
- MailRoom::Delivery::Logger.new(mailbox).deliver('a message')
39
+ logger.expects(:info).with('a message')
42
40
 
43
- expect(logger).to have_received(:info).with('a message')
41
+ MailRoom::Delivery::Logger.new(mailbox).deliver('a message')
44
42
  end
45
43
  end
46
44
  end
@@ -18,19 +18,13 @@ describe MailRoom::Delivery::Postback do
18
18
  request = stub
19
19
  Faraday.stubs(:new).returns(connection)
20
20
 
21
- connection.stubs(:token_auth)
22
- connection.stubs(:post).yields(request)
21
+ connection.expects(:token_auth).with('abcdefg')
22
+ connection.expects(:post).yields(request)
23
23
 
24
- request.stubs(:url)
25
- request.stubs(:body=)
24
+ request.expects(:url).with('http://localhost/inbox')
25
+ request.expects(:body=).with('a message')
26
26
 
27
27
  MailRoom::Delivery::Postback.new(delivery_options).deliver('a message')
28
-
29
- expect(connection).to have_received(:token_auth).with('abcdefg')
30
- expect(connection).to have_received(:post)
31
-
32
- expect(request).to have_received(:url).with('http://localhost/inbox')
33
- expect(request).to have_received(:body=).with('a message')
34
28
  end
35
29
  end
36
30
 
@@ -52,19 +46,13 @@ describe MailRoom::Delivery::Postback do
52
46
  request = stub
53
47
  Faraday.stubs(:new).returns(connection)
54
48
 
55
- connection.stubs(:basic_auth)
56
- connection.stubs(:post).yields(request)
49
+ connection.expects(:basic_auth).with('user1', 'password123abc')
50
+ connection.expects(:post).yields(request)
57
51
 
58
- request.stubs(:url)
59
- request.stubs(:body=)
52
+ request.expects(:url).with('http://localhost/inbox')
53
+ request.expects(:body=).with('a message')
60
54
 
61
55
  MailRoom::Delivery::Postback.new(delivery_options).deliver('a message')
62
-
63
- expect(connection).to have_received(:basic_auth).with('user1', 'password123abc')
64
- expect(connection).to have_received(:post)
65
-
66
- expect(request).to have_received(:url).with('http://localhost/inbox')
67
- expect(request).to have_received(:body=).with('a message')
68
56
  end
69
57
 
70
58
  context 'with content type in the delivery options' do
@@ -86,18 +74,14 @@ describe MailRoom::Delivery::Postback do
86
74
  connection = stub
87
75
  request = stub
88
76
  Faraday.stubs(:new).returns(connection)
89
-
90
- connection.stubs(:basic_auth)
91
- connection.stubs(:post).yields(request)
92
-
77
+
78
+ connection.expects(:post).yields(request)
93
79
  request.stubs(:url)
94
80
  request.stubs(:body=)
95
81
  request.stubs(:headers).returns({})
82
+ connection.expects(:basic_auth).with('user1', 'password123abc')
96
83
 
97
84
  MailRoom::Delivery::Postback.new(delivery_options).deliver('a message')
98
-
99
- expect(connection).to have_received(:basic_auth).with('user1', 'password123abc')
100
- expect(connection).to have_received(:post)
101
85
 
102
86
  expect(request.headers['Content-Type']).to eq('text/plain')
103
87
  end
@@ -18,20 +18,15 @@ describe MailRoom::Delivery::Que do
18
18
  let(:options) {MailRoom::Delivery::Que::Options.new(mailbox)}
19
19
 
20
20
  it 'stores the message in que_jobs table' do
21
- PG.stubs(:connect).returns(connection)
22
- connection.stubs(:exec)
23
-
24
- MailRoom::Delivery::Que.new(options).deliver('email')
25
-
26
- expect(PG).to have_received(:connect).with({
21
+ PG.expects(:connect).with({
27
22
  host: 'localhost',
28
23
  port: 5432,
29
24
  dbname: 'delivery_test',
30
25
  user: 'postgres',
31
26
  password: ''
32
- })
27
+ }).returns(connection)
33
28
 
34
- expect(connection).to have_received(:exec).with(
29
+ connection.expects(:exec).with(
35
30
  "INSERT INTO que_jobs (priority, job_class, queue, args) VALUES ($1, $2, $3, $4)",
36
31
  [
37
32
  5,
@@ -40,6 +35,8 @@ describe MailRoom::Delivery::Que do
40
35
  JSON.dump(['email'])
41
36
  ]
42
37
  )
38
+
39
+ MailRoom::Delivery::Que.new(options).deliver('email')
43
40
  end
44
41
  end
45
42
  end
@@ -12,9 +12,9 @@ describe MailRoom::Mailbox do
12
12
 
13
13
  uid = 123
14
14
 
15
- mailbox.deliver?(uid)
15
+ noop.expects(:deliver?).with(uid)
16
16
 
17
- expect(noop).to have_received(:deliver?).with(uid)
17
+ mailbox.deliver?(uid)
18
18
  end
19
19
  end
20
20
 
@@ -23,12 +23,10 @@ describe MailRoom::Mailbox do
23
23
  mailbox = build_mailbox({:arbitration_method => 'redis'})
24
24
  redis = stub(:deliver?)
25
25
  MailRoom::Arbitration['redis'].stubs(:new => redis)
26
-
27
26
  uid = 123
27
+ redis.expects(:deliver?).with(uid)
28
28
 
29
29
  mailbox.deliver?(uid)
30
-
31
- expect(redis).to have_received(:deliver?).with(uid)
32
30
  end
33
31
  end
34
32
 
@@ -38,9 +36,9 @@ describe MailRoom::Mailbox do
38
36
  noop = stub(:deliver)
39
37
  MailRoom::Delivery['noop'].stubs(:new => noop)
40
38
 
41
- mailbox.deliver(stub(:attr => sample_message))
39
+ noop.expects(:deliver).with('a message')
42
40
 
43
- expect(noop).to have_received(:deliver).with('a message')
41
+ mailbox.deliver(stub(:attr => sample_message))
44
42
  end
45
43
  end
46
44
 
@@ -50,9 +48,9 @@ describe MailRoom::Mailbox do
50
48
  logger = stub(:deliver)
51
49
  MailRoom::Delivery['logger'].stubs(:new => logger)
52
50
 
53
- mailbox.deliver(stub(:attr => sample_message))
51
+ logger.expects(:deliver).with('a message')
54
52
 
55
- expect(logger).to have_received(:deliver).with('a message')
53
+ mailbox.deliver(stub(:attr => sample_message))
56
54
  end
57
55
  end
58
56
 
@@ -62,9 +60,9 @@ describe MailRoom::Mailbox do
62
60
  postback = stub(:deliver)
63
61
  MailRoom::Delivery['postback'].stubs(:new => postback)
64
62
 
65
- mailbox.deliver(stub(:attr => sample_message))
63
+ postback.expects(:deliver).with('a message')
66
64
 
67
- expect(postback).to have_received(:deliver).with('a message')
65
+ mailbox.deliver(stub(:attr => sample_message))
68
66
  end
69
67
  end
70
68
 
@@ -74,9 +72,9 @@ describe MailRoom::Mailbox do
74
72
  letter_opener = stub(:deliver)
75
73
  MailRoom::Delivery['letter_opener'].stubs(:new => letter_opener)
76
74
 
77
- mailbox.deliver(stub(:attr => sample_message))
75
+ letter_opener.expects(:deliver).with('a message')
78
76
 
79
- expect(letter_opener).to have_received(:deliver).with('a message')
77
+ mailbox.deliver(stub(:attr => sample_message))
80
78
  end
81
79
  end
82
80
 
@@ -85,10 +83,9 @@ describe MailRoom::Mailbox do
85
83
  mailbox = build_mailbox({ name: "magic mailbox", delivery_method: 'noop' })
86
84
  noop = stub(:deliver)
87
85
  MailRoom::Delivery['noop'].stubs(:new => noop)
86
+ noop.expects(:deliver).never
88
87
 
89
88
  mailbox.deliver(stub(:attr => {'FLAGS' => [:Seen, :Recent]}))
90
-
91
- expect(noop).to have_received(:deliver).never
92
89
  end
93
90
  end
94
91
 
@@ -20,19 +20,15 @@ describe MailRoom::MailboxWatcher do
20
20
 
21
21
  it 'loops over wait while running' do
22
22
  connection = MailRoom::Connection.new(mailbox)
23
- connection.stubs(:on_new_message)
24
- connection.stubs(:wait)
25
23
 
26
24
  MailRoom::Connection.stubs(:new).returns(connection)
27
25
 
28
- watcher.stubs(:running?).returns(true).then.returns(false)
26
+ watcher.expects(:running?).twice.returns(true, false)
27
+ connection.expects(:wait).once
28
+ connection.expects(:on_new_message).once
29
29
 
30
30
  watcher.run
31
31
  watcher.watching_thread.join # wait for finishing run
32
-
33
- expect(watcher).to have_received(:running?).times(2)
34
- expect(connection).to have_received(:wait).once
35
- expect(connection).to have_received(:on_new_message).once
36
32
  end
37
33
  end
38
34
 
@@ -55,9 +51,10 @@ describe MailRoom::MailboxWatcher do
55
51
 
56
52
  expect(watcher.running?).to eq(true)
57
53
 
54
+ connection.expects(:quit)
55
+
58
56
  watcher.quit
59
57
 
60
- expect(connection).to have_received(:quit)
61
58
  expect(watcher.running?).to eq(false)
62
59
  end
63
60
  end
@@ -5,7 +5,6 @@ require 'bundler/setup'
5
5
 
6
6
  require 'rspec'
7
7
  require 'mocha/api'
8
- require 'bourne'
9
8
 
10
9
  require File.expand_path('../../lib/mail_room', __FILE__)
11
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-mail_room
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-06 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -28,44 +28,30 @@ dependencies:
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.9'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '3.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mocha
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: bourne
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
45
+ - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '0'
47
+ version: '1.11'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ">="
52
+ - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '0'
54
+ version: '1.11'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: simplecov
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +174,7 @@ extra_rdoc_files: []
188
174
  files:
189
175
  - ".gitignore"
190
176
  - ".gitlab-ci.yml"
177
+ - ".gitlab/issue_templates/Release.md"
191
178
  - ".ruby-version"
192
179
  - ".travis.yml"
193
180
  - CHANGELOG.md