ryespy 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81189d612d2169d1f39164bac11198586502d33a
4
- data.tar.gz: b256a8dd802f5e3502e72562a003319ea07693f9
3
+ metadata.gz: 9950cd62c7ec9aea8a7b08fb0c1cfbfdcdee22e9
4
+ data.tar.gz: 4ac0a03ecbff1abf251f528f5c46ca5f9c024534
5
5
  SHA512:
6
- metadata.gz: 3ae2702a04cc80734d1bc5fc2d8eed1b48ecff1f1c7fc32e0bd20b6755acb9a77541e748d5c39c728e017e1ae3f1b92292cc83c6a93a2574a6b65a8ddafec8a9
7
- data.tar.gz: 7ba4e48afe98b6a815621ed7266b2fa2494cef1ebf6b67b937aeac25cd6d18953f5485357096d8c693f828b84929d5832b73a96a34655f0a15ee39192a190ac0
6
+ metadata.gz: b3267a88b15e58b90813a5842ed494f7c1aa49b30bbc3da4f6eaa56b9b3cf36281356006fda06531810a47d916bb1efc77d5af86f050039684ad92ffd3cdbace
7
+ data.tar.gz: 76c90341a60f6c9213e9e5fb8a7c5531434e3e410f93b1e373bcad9cb74e49f443059510ade46d9fa5a28a61a6a4b326fb6646d94b081649c568ba7a05251b84
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
data/README.md CHANGED
@@ -10,6 +10,8 @@ it's sometimes possible to inspire oneself. Ryespy with my little eye.
10
10
 
11
11
  More sleep lost by [tiredpixel](http://www.tiredpixel.com).
12
12
 
13
+ [![Build Status](https://travis-ci.org/tiredpixel/ryespy.png?branch=master,develop)](https://travis-ci.org/tiredpixel/ryespy)
14
+
13
15
 
14
16
  ## Installation
15
17
 
@@ -57,14 +59,14 @@ doing or planning to do, or if you get stuck on something, then just wave. :)
57
59
  Do whatever makes you happy. We'll probably still like you. :)
58
60
 
59
61
  Tests are written using [minitest](https://github.com/seattlerb/minitest), which
60
- is included by default in Ruby 1.9 onwards. To run all tests in a pretty way:
62
+ is included by default in Ruby 1.9 onwards. To run all tests:
61
63
 
62
- ruby -rminitest/pride test/ryespy.rb
64
+ rake test
63
65
 
64
66
  Or, if you're of that turn of mind, use [TURN](https://github.com/TwP/turn)
65
67
  (`gem install turn`):
66
68
 
67
- turn test/ryespy.rb
69
+ turn test/
68
70
 
69
71
 
70
72
  ## Blessing
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs.push 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => 'test'
data/bin/ryespy CHANGED
@@ -48,6 +48,10 @@ OptionParser.new do |opts|
48
48
  options[:redis_ns_ryespy] = o
49
49
  end
50
50
 
51
+ opts.on("--redis-ns-notifiers [NS]", "Namespace notifiers Redis 'resque:' as NS") do |o|
52
+ options[:redis_ns_notifiers] = o
53
+ end
54
+
51
55
  opts.separator ""
52
56
  opts.separator "Listener imap:"
53
57
 
@@ -143,11 +147,12 @@ Ryespy.configure do |c|
143
147
  :polling_interval,
144
148
  :redis_url,
145
149
  :redis_ns_ryespy,
150
+ :redis_ns_notifiers,
146
151
  :notifiers,
147
152
  ]
148
153
 
149
- params.concat case c.listener
150
- when :imap
154
+ params.concat case c.listener.to_s
155
+ when 'imap'
151
156
  [
152
157
  :imap_host,
153
158
  :imap_port,
@@ -156,7 +161,7 @@ Ryespy.configure do |c|
156
161
  :imap_password,
157
162
  :imap_mailboxes,
158
163
  ]
159
- when :ftp
164
+ when 'ftp'
160
165
  [
161
166
  :ftp_host,
162
167
  :ftp_passive,
@@ -177,7 +182,12 @@ end
177
182
  # = Main loop
178
183
 
179
184
  loop do
180
- Ryespy.check_listener
185
+ listener = {
186
+ 'imap' => Ryespy::Listener::IMAP,
187
+ 'ftp' => Ryespy::Listener::FTP,
188
+ }[Ryespy.config.listener.to_s].new
189
+
190
+ listener.check_all
181
191
 
182
192
  break unless options[:eternal]
183
193
 
@@ -34,80 +34,20 @@ module Ryespy
34
34
  @logger
35
35
  end
36
36
 
37
- def check_listener
38
- redis_prefix = "#{Ryespy.config.redis_ns_ryespy}#{Ryespy.config.listener}:"
39
-
40
- notifiers = []
41
-
42
- begin
43
- Ryespy.config.notifiers[:sidekiq].each do |notifier_instance|
44
- notifiers << Ryespy::Notifier::Sidekiq.new(notifier_instance)
45
- end
46
-
47
- Ryespy::RedisConn.new(Ryespy.config.redis_url) do |redis|
48
- Ryespy.send("check_#{Ryespy.config.listener}", redis, redis_prefix, notifiers)
49
- end
50
- ensure
51
- notifiers.each { |n| n.close }
52
- end
37
+ def redis
38
+ @redis ||= Ryespy::RedisConn.new(Ryespy.config.redis_url).redis
53
39
  end
54
40
 
55
- def check_imap(redis, redis_prefix, notifiers)
56
- redis_prefix += "#{Ryespy.config.imap_host},#{Ryespy.config.imap_port}:#{Ryespy.config.imap_username}:"
57
-
58
- Ryespy::Listener::IMAP.new do |listener|
59
- Ryespy.config.imap_mailboxes.each do |mailbox|
60
- Ryespy.logger.debug { "mailbox:#{mailbox}" }
61
-
62
- redis_key = redis_prefix + "#{mailbox}"
63
-
64
- Ryespy.logger.debug { "redis_key:#{redis_key}" }
65
-
66
- new_items = listener.check({
67
- :mailbox => mailbox,
68
- :last_seen_uid => redis.get(redis_key).to_i,
69
- })
70
-
71
- Ryespy.logger.debug { "new_items:#{new_items}" }
72
-
73
- new_items.each do |uid|
74
- redis.set(redis_key, uid)
75
-
76
- notifiers.each { |n| n.notify('RyespyIMAPJob', [mailbox, uid]) }
77
- end
78
-
79
- Ryespy.logger.info { "#{mailbox} has #{new_items.count} new emails" }
41
+ def notifiers
42
+ unless @notifiers
43
+ @notifiers = []
44
+
45
+ Ryespy.config.notifiers[:sidekiq].each do |notifier_instance|
46
+ @notifiers << Ryespy::Notifier::Sidekiq.new(notifier_instance)
80
47
  end
81
48
  end
82
- end
83
-
84
- def check_ftp(redis, redis_prefix, notifiers)
85
- redis_prefix += "#{Ryespy.config.ftp_host}:#{Ryespy.config.ftp_username}:"
86
49
 
87
- Ryespy::Listener::FTP.new do |listener|
88
- Ryespy.config.ftp_dirs.each do |dir|
89
- Ryespy.logger.debug { "dir:#{dir}" }
90
-
91
- redis_key = redis_prefix + "#{dir}"
92
-
93
- Ryespy.logger.debug { "redis_key:#{redis_key}" }
94
-
95
- new_items = listener.check({
96
- :dir => dir,
97
- :seen_files => redis.hgetall(redis_key),
98
- })
99
-
100
- Ryespy.logger.debug { "new_items:#{new_items}" }
101
-
102
- new_items.each do |filename, checksum|
103
- redis.hset(redis_key, filename, checksum)
104
-
105
- notifiers.each { |n| n.notify('RyespyFTPJob', [dir, filename]) }
106
- end
107
-
108
- Ryespy.logger.info { "#{dir} has #{new_items.count} new files" }
109
- end
110
- end
50
+ @notifiers
111
51
  end
112
52
 
113
53
  end
@@ -6,6 +6,7 @@ module Ryespy
6
6
  attr_accessor :polling_interval
7
7
  attr_accessor :redis_url
8
8
  attr_accessor :redis_ns_ryespy
9
+ attr_accessor :redis_ns_notifiers
9
10
  attr_accessor :notifiers
10
11
 
11
12
  attr_accessor :imap_host
@@ -22,10 +23,11 @@ module Ryespy
22
23
  attr_accessor :ftp_dirs
23
24
 
24
25
  def initialize
25
- @log_level = 'INFO'
26
- @polling_interval = 60
27
- @redis_ns_ryespy = 'ryespy:'
28
- @notifiers = {
26
+ @log_level = 'INFO'
27
+ @polling_interval = 60
28
+ @redis_ns_ryespy = 'ryespy:'
29
+ @redis_ns_notifiers = 'resque:'
30
+ @notifiers = {
29
31
  :sidekiq => [],
30
32
  }
31
33
 
@@ -44,11 +46,12 @@ module Ryespy
44
46
  :polling_interval,
45
47
  :redis_url,
46
48
  :redis_ns_ryespy,
49
+ :redis_ns_notifiers,
47
50
  :notifiers,
48
51
  ]
49
52
 
50
- params.concat case @listener
51
- when :imap
53
+ params.concat case @listener.to_s
54
+ when 'imap'
52
55
  [
53
56
  :imap_host,
54
57
  :imap_port,
@@ -56,7 +59,7 @@ module Ryespy
56
59
  :imap_username,
57
60
  :imap_password,
58
61
  ]
59
- when :ftp
62
+ when 'ftp'
60
63
  [
61
64
  :ftp_host,
62
65
  :ftp_passive,
@@ -72,5 +75,9 @@ module Ryespy
72
75
  Hash[params].to_s
73
76
  end
74
77
 
78
+ def redis_prefix_ryespy
79
+ "#{Ryespy.config.redis_ns_ryespy}#{Ryespy.config.listener}:"
80
+ end
81
+
75
82
  end
76
83
  end
@@ -56,6 +56,31 @@ module Ryespy
56
56
  end
57
57
  end
58
58
 
59
+ def check_all
60
+ Ryespy.config.ftp_dirs.each do |dir|
61
+ Ryespy.logger.debug { "dir:#{dir}" }
62
+
63
+ redis_key = "#{Ryespy.config.redis_prefix_ryespy}#{Ryespy.config.ftp_host}:#{Ryespy.config.ftp_username}:#{dir}"
64
+
65
+ Ryespy.logger.debug { "redis_key:#{redis_key}" }
66
+
67
+ new_items = check({
68
+ :dir => dir,
69
+ :seen_files => Ryespy.redis.hgetall(redis_key),
70
+ })
71
+
72
+ Ryespy.logger.debug { "new_items:#{new_items}" }
73
+
74
+ new_items.each do |filename, checksum|
75
+ Ryespy.redis.hset(redis_key, filename, checksum)
76
+
77
+ Ryespy.notifiers.each { |n| n.notify('RyespyFTPJob', [dir, filename]) }
78
+ end
79
+
80
+ Ryespy.logger.info { "#{dir} has #{new_items.count} new files" }
81
+ end
82
+ end
83
+
59
84
  end
60
85
  end
61
86
  end
@@ -27,8 +27,6 @@ module Ryespy
27
27
  end
28
28
 
29
29
  def close
30
- @imap.logout
31
-
32
30
  @imap.disconnect
33
31
  end
34
32
 
@@ -46,6 +44,31 @@ module Ryespy
46
44
  end
47
45
  end
48
46
 
47
+ def check_all
48
+ Ryespy.config.imap_mailboxes.each do |mailbox|
49
+ Ryespy.logger.debug { "mailbox:#{mailbox}" }
50
+
51
+ redis_key = "#{Ryespy.config.redis_prefix_ryespy}#{Ryespy.config.imap_host},#{Ryespy.config.imap_port}:#{Ryespy.config.imap_username}:#{mailbox}"
52
+
53
+ Ryespy.logger.debug { "redis_key:#{redis_key}" }
54
+
55
+ new_items = check({
56
+ :mailbox => mailbox,
57
+ :last_seen_uid => Ryespy.redis.get(redis_key).to_i,
58
+ })
59
+
60
+ Ryespy.logger.debug { "new_items:#{new_items}" }
61
+
62
+ new_items.each do |uid|
63
+ Ryespy.redis.set(redis_key, uid)
64
+
65
+ Ryespy.notifiers.each { |n| n.notify('RyespyIMAPJob', [mailbox, uid]) }
66
+ end
67
+
68
+ Ryespy.logger.info { "#{mailbox} has #{new_items.count} new emails" }
69
+ end
70
+ end
71
+
49
72
  end
50
73
  end
51
74
  end
@@ -8,8 +8,7 @@ module Ryespy
8
8
  module Notifier
9
9
  class Sidekiq
10
10
 
11
- REDIS_NS_RESQUE = 'resque'
12
- RESQUE_QUEUE = 'ryespy'
11
+ RESQUE_QUEUE = 'ryespy'
13
12
 
14
13
  def initialize(url = nil)
15
14
  begin
@@ -32,9 +31,9 @@ module Ryespy
32
31
  end
33
32
 
34
33
  def notify(job_class, args)
35
- @redis_conn.redis.sadd("#{REDIS_NS_RESQUE}:queues", RESQUE_QUEUE)
34
+ @redis_conn.redis.sadd("#{Ryespy.config.redis_ns_notifiers}queues", RESQUE_QUEUE)
36
35
 
37
- @redis_conn.redis.rpush("#{REDIS_NS_RESQUE}:queue:#{RESQUE_QUEUE}", {
36
+ @redis_conn.redis.rpush("#{Ryespy.config.redis_ns_notifiers}queue:#{RESQUE_QUEUE}", {
38
37
  # resque
39
38
  :class => job_class,
40
39
  :args => args,
@@ -1,5 +1,5 @@
1
1
  module Ryespy
2
2
 
3
- VERSION = "0.6.1"
3
+ VERSION = "0.7.0"
4
4
 
5
5
  end
@@ -0,0 +1,223 @@
1
+ require 'minitest/autorun'
2
+
3
+ require_relative '../../lib/ryespy'
4
+ require_relative '../../lib/ryespy/config'
5
+
6
+
7
+ describe Ryespy::Config do
8
+
9
+ describe "default" do
10
+ before do
11
+ @config = Ryespy::Config.new
12
+ end
13
+
14
+ it "sets log_level to INFO" do
15
+ @config.log_level.must_equal 'INFO'
16
+ end
17
+
18
+ it "sets polling_interval to 60" do
19
+ @config.polling_interval.must_equal 60
20
+ end
21
+
22
+ it "sets redis_ns_ryespy to ryespy:" do
23
+ @config.redis_ns_ryespy.must_equal 'ryespy:'
24
+ end
25
+
26
+ it "sets redis_ns_notifiers to resque:" do
27
+ @config.redis_ns_notifiers.must_equal 'resque:'
28
+ end
29
+
30
+ it "sets notifiers hash structure" do
31
+ @config.notifiers.must_equal({ :sidekiq => [] })
32
+ end
33
+
34
+ it "sets imap_port to 993" do
35
+ @config.imap_port.must_equal 993
36
+ end
37
+
38
+ it "sets imap_ssl to true" do
39
+ @config.imap_ssl.must_equal true
40
+ end
41
+
42
+ it "sets imap_mailboxes to INBOX" do
43
+ @config.imap_mailboxes.must_equal ['INBOX']
44
+ end
45
+
46
+ it "sets ftp_passive to false" do
47
+ @config.ftp_passive.must_equal false
48
+ end
49
+
50
+ it "sets ftp_dirs to /" do
51
+ @config.ftp_dirs.must_equal ['/']
52
+ end
53
+ end
54
+
55
+ describe "configure block main" do
56
+ before do
57
+ Ryespy.configure do |c|
58
+ c.log_level = 'ERROR'
59
+ c.listener = 'imap'
60
+ c.polling_interval = 13
61
+ c.redis_url = 'redis://127.0.0.1:6379/1'
62
+ c.redis_ns_ryespy = 'WithMyLittleEye!'
63
+ c.redis_ns_notifiers = 'LaLaLiLi-'
64
+ c.notifiers = [{ :sidekiq => 'redis://127.0.0.1:6379/2' }]
65
+ end
66
+
67
+ @config = Ryespy.config
68
+ end
69
+
70
+ it "configures log_level" do
71
+ @config.log_level.must_equal 'ERROR'
72
+ end
73
+
74
+ it "configures listener" do
75
+ @config.listener.must_equal 'imap'
76
+ end
77
+
78
+ it "configures polling_interval" do
79
+ @config.polling_interval.must_equal 13
80
+ end
81
+
82
+ it "configures redis_url" do
83
+ @config.redis_url.must_equal 'redis://127.0.0.1:6379/1'
84
+ end
85
+
86
+ it "configures redis_ns_ryespy" do
87
+ @config.redis_ns_ryespy.must_equal 'WithMyLittleEye!'
88
+ end
89
+
90
+ it "configures redis_ns_notifiers" do
91
+ @config.redis_ns_notifiers.must_equal 'LaLaLiLi-'
92
+ end
93
+
94
+ it "configures notifiers" do
95
+ @config.notifiers.must_equal [{ :sidekiq => 'redis://127.0.0.1:6379/2' }]
96
+ end
97
+ end
98
+
99
+ describe "configure block listener IMAP" do
100
+ before do
101
+ Ryespy.configure do |c|
102
+ c.imap_host = 'imap.example.com'
103
+ c.imap_port = 143
104
+ c.imap_ssl = false
105
+ c.imap_username = 'lucy.westenra@example.com'
106
+ c.imap_password = 'white'
107
+ c.imap_mailboxes = 'BoxA,Sent Messages'
108
+
109
+ @config = Ryespy.config
110
+ end
111
+ end
112
+
113
+ it "configures imap_host" do
114
+ @config.imap_host.must_equal 'imap.example.com'
115
+ end
116
+
117
+ it "configures imap_port" do
118
+ @config.imap_port.must_equal 143
119
+ end
120
+
121
+ it "configures imap_ssl" do
122
+ @config.imap_ssl.must_equal false
123
+ end
124
+
125
+ it "configures imap_username" do
126
+ @config.imap_username.must_equal 'lucy.westenra@example.com'
127
+ end
128
+
129
+ it "configures imap_password" do
130
+ @config.imap_password.must_equal 'white'
131
+ end
132
+
133
+ it "configures imap_mailboxes" do
134
+ @config.imap_mailboxes.must_equal 'BoxA,Sent Messages'
135
+ end
136
+ end
137
+
138
+ describe "configure block listener FTP" do
139
+ before do
140
+ Ryespy.configure do |c|
141
+ c.ftp_host = 'ftp.example.org'
142
+ c.ftp_passive = true
143
+ c.ftp_username = 'madam.mina@example.com'
144
+ c.ftp_password = 'black'
145
+ c.ftp_dirs = ['BoxA', 'Sent Messages']
146
+
147
+ @config = Ryespy.config
148
+ end
149
+ end
150
+
151
+ it "configures ftp_host" do
152
+ @config.ftp_host.must_equal 'ftp.example.org'
153
+ end
154
+
155
+ it "configures ftp_passive" do
156
+ @config.ftp_passive.must_equal true
157
+ end
158
+
159
+ it "configures ftp_username" do
160
+ @config.ftp_username.must_equal 'madam.mina@example.com'
161
+ end
162
+
163
+ it "configures ftp_password" do
164
+ @config.ftp_password.must_equal 'black'
165
+ end
166
+
167
+ it "configures ftp_dirs" do
168
+ @config.ftp_dirs.must_equal ['BoxA', 'Sent Messages']
169
+ end
170
+ end
171
+
172
+ describe "#to_s" do
173
+ before do
174
+ @config = Ryespy::Config.new
175
+ end
176
+
177
+ describe "when listener NULL" do
178
+ before do
179
+ @config.listener = nil
180
+ end
181
+
182
+ it "stringifies hash of config" do
183
+ @config.to_s.must_equal '{:log_level=>"INFO", :listener=>nil, :polling_interval=>60, :redis_url=>nil, :redis_ns_ryespy=>"ryespy:", :redis_ns_notifiers=>"resque:", :notifiers=>{:sidekiq=>[]}}'
184
+ end
185
+ end
186
+
187
+ describe "when listener IMAP" do
188
+ before do
189
+ @config.listener = 'imap'
190
+ end
191
+
192
+ it "stringifies hash of config" do
193
+ @config.to_s.must_equal '{:log_level=>"INFO", :listener=>"imap", :polling_interval=>60, :redis_url=>nil, :redis_ns_ryespy=>"ryespy:", :redis_ns_notifiers=>"resque:", :notifiers=>{:sidekiq=>[]}, :imap_host=>nil, :imap_port=>993, :imap_ssl=>true, :imap_username=>nil, :imap_password=>nil}'
194
+ end
195
+ end
196
+
197
+ describe "when listener FTP" do
198
+ before do
199
+ @config.listener = 'ftp'
200
+ end
201
+
202
+ it "stringifies hash of config" do
203
+ @config.to_s.must_equal '{:log_level=>"INFO", :listener=>"ftp", :polling_interval=>60, :redis_url=>nil, :redis_ns_ryespy=>"ryespy:", :redis_ns_notifiers=>"resque:", :notifiers=>{:sidekiq=>[]}, :ftp_host=>nil, :ftp_passive=>false, :ftp_username=>nil, :ftp_dirs=>["/"]}'
204
+ end
205
+ end
206
+ end
207
+
208
+ describe "#redis_prefix_ryespy" do
209
+ before do
210
+ Ryespy.configure do |c|
211
+ c.listener = 'earear'
212
+ c.redis_ns_ryespy = 'LittleEye:'
213
+ end
214
+
215
+ @config = Ryespy.config
216
+ end
217
+
218
+ it "returns key prefix" do
219
+ @config.redis_prefix_ryespy.must_equal "LittleEye:earear:"
220
+ end
221
+ end
222
+
223
+ end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ryespy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tiredpixel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-25 00:00:00.000000000 Z
11
+ date: 2013-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -67,6 +67,7 @@ files:
67
67
  - .gitignore
68
68
  - .ruby-gemset
69
69
  - .ruby-version
70
+ - .travis.yml
70
71
  - Gemfile
71
72
  - LICENSE.txt
72
73
  - README.md
@@ -80,9 +81,9 @@ files:
80
81
  - lib/ryespy/redis_conn.rb
81
82
  - lib/ryespy/version.rb
82
83
  - ryespy.gemspec
83
- - test/ryespy.rb
84
- - test/ryespy/config.rb
85
- - test/ryespy/version.rb
84
+ - test/ryespy/config_test.rb
85
+ - test/ryespy/version_test.rb
86
+ - test/ryespy_test.rb
86
87
  homepage: https://github.com/tiredpixel/ryespy
87
88
  licenses:
88
89
  - MIT
@@ -108,6 +109,6 @@ signing_key:
108
109
  specification_version: 4
109
110
  summary: Ryespy listens to IMAP and FTP and queues in Redis (Sidekiq/Resque).
110
111
  test_files:
111
- - test/ryespy.rb
112
- - test/ryespy/config.rb
113
- - test/ryespy/version.rb
112
+ - test/ryespy/config_test.rb
113
+ - test/ryespy/version_test.rb
114
+ - test/ryespy_test.rb
@@ -1,2 +0,0 @@
1
- require_relative 'ryespy/version'
2
- require_relative 'ryespy/config'
@@ -1,71 +0,0 @@
1
- require 'minitest/autorun'
2
-
3
- require_relative '../../lib/ryespy'
4
- require_relative '../../lib/ryespy/config'
5
-
6
-
7
- describe Ryespy::Config do
8
-
9
- describe "default" do
10
- before do
11
- @config = Ryespy::Config.new
12
- end
13
-
14
- it "sets log_level to INFO" do
15
- @config.log_level.must_equal 'INFO'
16
- end
17
-
18
- it "sets polling_interval to 60" do
19
- @config.polling_interval.must_equal 60
20
- end
21
-
22
- it "sets redis_ns_ryespy to ryespy:" do
23
- @config.redis_ns_ryespy.must_equal 'ryespy:'
24
- end
25
- end
26
-
27
- describe "configure block" do
28
- before do
29
- Ryespy.configure do |c|
30
- c.log_level = 'ERROR'
31
- c.listener = 'imap'
32
- c.polling_interval = 13
33
- c.redis_url = 'redis://127.0.0.1:6379/1'
34
- c.redis_ns_ryespy = 'WithMyLittleEye!'
35
- end
36
-
37
- @config = Ryespy.config
38
- end
39
-
40
- it "configures log_level" do
41
- @config.log_level.must_equal 'ERROR'
42
- end
43
-
44
- it "configures listener" do
45
- @config.listener.must_equal 'imap'
46
- end
47
-
48
- it "configures polling_interval" do
49
- @config.polling_interval.must_equal 13
50
- end
51
-
52
- it "configures redis_url" do
53
- @config.redis_url.must_equal 'redis://127.0.0.1:6379/1'
54
- end
55
-
56
- it "configures redis_ns_ryespy" do
57
- @config.redis_ns_ryespy.must_equal 'WithMyLittleEye!'
58
- end
59
- end
60
-
61
- describe "#to_s" do
62
- before do
63
- @config = Ryespy::Config.new
64
- end
65
-
66
- it "stringifies hash of config" do
67
- @config.to_s.must_equal '{:log_level=>"INFO", :listener=>nil, :polling_interval=>60, :redis_url=>nil, :redis_ns_ryespy=>"ryespy:", :notifiers=>{:sidekiq=>[]}}'
68
- end
69
- end
70
-
71
- end