ayl-beanstalk 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,34 @@ require 'ayl-beanstalk'
6
6
  # Requires supporting files with custom matchers and macros, etc,
7
7
  # in ./support/ and its subdirectories.
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
-
10
9
  RSpec.configure do |config|
11
10
 
12
11
  end
12
+ #
13
+ # The new RSpec exit_with_code handler doesn't support a block
14
+ # context, so we have to re-implement it.
15
+ RSpec::Matchers.define :exit_with_code do |exp_code|
16
+ actual = nil
17
+ match do |block|
18
+ begin
19
+ block.call
20
+ rescue SystemExit => e
21
+ actual = e.status
22
+ end
23
+ actual and actual == exp_code
24
+ end
25
+ failure_message_for_should do |block|
26
+ "expected block to call exit(#{exp_code}) but exit" +
27
+ (actual.nil? ? " not called" : "(#{actual}) was called")
28
+ end
29
+ failure_message_for_should_not do |block|
30
+ "expected block not to call exit(#{exp_code})"
31
+ end
32
+ description do
33
+ "expect block to call exit(#{exp_code})"
34
+ end
35
+ def supports_block_expectations?
36
+ true
37
+ end
38
+ end
39
+
data/spec/worker_spec.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'beanstalk-client'
3
2
  require 'active_record'
4
3
  require 'active_record/errors'
5
4
 
@@ -14,21 +13,24 @@ describe Ayl::Beanstalk::Worker do
14
13
  @worker.stub_chain(:logger, :error)
15
14
  @worker.stub_chain(:logger, :debug)
16
15
 
17
- @mock_pool = mock("Beanstalk::Pool")
16
+ @mock_pool = double("Beanstalk::Pool")
18
17
 
19
- ::Beanstalk::Pool.should_receive(:new).with([ "localhost:11300" ]).and_return(@mock_pool)
18
+ expect(Beaneater).to receive(:new).with("localhost:11300").and_return(@mock_pool)
20
19
  end
21
20
 
22
21
  it "should loop until there are no more jobs from beanstalk" do
23
- mock_job1 = mock("Beanstalk::Job")
24
- mock_job2 = mock("Beanstalk::Job")
22
+ mock_job1 = double("Beanstalk::Job")
23
+ mock_job2 = double("Beanstalk::Job")
25
24
 
26
- @mock_pool.should_receive(:reserve).and_return(mock_job1, mock_job2, nil)
25
+ mock_tubes = double("Tubes")
26
+ expect(mock_tubes).to receive(:reserve).and_return(mock_job1, mock_job2, nil)
27
+
28
+ expect(@mock_pool).to receive(:tubes).exactly(3).times.and_return(mock_tubes)
27
29
 
28
30
  index = 0
29
31
 
30
32
  @worker.send(:reserve_job) do | job |
31
- job.should == [ mock_job1, mock_job2 ][index]
33
+ expect(job).to eq([ mock_job1, mock_job2 ][index])
32
34
  index += 1
33
35
  end
34
36
 
@@ -37,12 +39,14 @@ describe Ayl::Beanstalk::Worker do
37
39
  end
38
40
 
39
41
  it "should report any exception while waiting for a job" do
40
- @mock_pool.should_receive(:reserve).and_raise('It blew')
42
+ mock_tubes = double("Tubes")
43
+ expect(mock_tubes).to receive(:reserve).and_raise('It blew')
44
+ expect(@mock_pool).to receive(:tubes).and_return(mock_tubes)
41
45
 
42
- mock_mailer = mock("Mailer")
43
- mock_mailer.should_receive(:deliver_message).with(any_args())
46
+ mock_mailer = double("Mailer")
47
+ expect(mock_mailer).to receive(:deliver_message).with(any_args())
44
48
 
45
- Ayl::Mailer.should_receive(:instance).and_return(mock_mailer)
49
+ expect(Ayl::Mailer).to receive(:instance).and_return(mock_mailer)
46
50
 
47
51
  @worker.send(:reserve_job) do | job |
48
52
  end
@@ -61,68 +65,65 @@ describe Ayl::Beanstalk::Worker do
61
65
  end
62
66
 
63
67
  it "should call the job's handle_decay method if the message requires the job to decay" do
64
- mock_job = mock("Beanstalk::Job")
65
- mock_job.should_receive(:ayl_message).and_return do
66
- mock("message").tap do | mock_message |
67
- mock_message.should_receive(:options).and_return do
68
- mock("options").tap do | mock_options |
69
- mock_options.should_receive(:failed_job_handler).and_return('decay')
70
- end
71
- end
72
- end
73
- end
68
+ mock_job = double("Beanstalk::Job")
69
+
70
+ mock_options = double("options")
71
+ expect(mock_options).to receive(:failed_job_handler).and_return('decay')
72
+
73
+ mock_message = double("message")
74
+ mock_message.should_receive(:options).and_return(mock_options)
74
75
 
75
- mock_exception = mock("Exception")
76
- mock_exception.should_receive(:backtrace).and_return([])
77
- mock_job.should_receive(:handle_decay).with(mock_exception)
76
+ expect(mock_job).to receive(:ayl_message).and_return(mock_message)
77
+
78
+ mock_exception = double("Exception")
79
+ expect(mock_exception).to receive(:backtrace).and_return([])
80
+ expect(mock_job).to receive(:handle_decay).with(mock_exception)
78
81
 
79
82
  @worker.send(:deal_with_unexpected_exception, mock_job, mock_exception)
80
83
  end
81
84
 
82
85
  it "should call the job's ayl_delete method if the message requires the job to be deleted" do
83
- mock_job = mock("Beanstalk::Job")
84
- mock_job.should_receive(:ayl_message).and_return do
85
- mock("message").tap do | mock_message |
86
- mock_message.should_receive(:options).and_return do
87
- mock("options").tap do | mock_options |
88
- mock_options.should_receive(:failed_job_handler).and_return('delete')
89
- end
90
- end
91
- end
92
- end
86
+ mock_job = double("Beanstalk::Job")
87
+
88
+ mock_options = double("options")
89
+ expect(mock_options).to receive(:failed_job_handler).and_return('delete')
93
90
 
94
- mock_exception = mock("Exception")
95
- mock_exception.should_receive(:backtrace).and_return([])
96
- mock_job.should_receive(:ayl_delete)
91
+ mock_message = double("message")
92
+ expect(mock_message).to receive(:options).and_return(mock_options)
97
93
 
98
- mock_mailer = mock("Mailer")
99
- mock_mailer.should_receive(:deliver_message).with(any_args())
94
+ expect(mock_job).to receive(:ayl_message).and_return(mock_message)
100
95
 
101
- Ayl::Mailer.should_receive(:instance).and_return(mock_mailer)
96
+ mock_exception = double("Exception")
97
+ expect(mock_exception).to receive(:backtrace).and_return([])
98
+ expect(mock_job).to receive(:ayl_delete)
99
+
100
+ mock_mailer = double("Mailer")
101
+ expect(mock_mailer).to receive(:deliver_message).with(any_args())
102
+
103
+ expect(Ayl::Mailer).to receive(:instance).and_return(mock_mailer)
102
104
 
103
105
  @worker.send(:deal_with_unexpected_exception, mock_job, mock_exception)
104
106
  end
105
107
 
106
108
  it "should call the job's ayl_bury method if the message requires the job to be buried" do
107
- mock_job = mock("Beanstalk::Job")
108
- mock_job.should_receive(:ayl_message).and_return do
109
- mock("message").tap do | mock_message |
110
- mock_message.should_receive(:options).and_return do
111
- mock("options").tap do | mock_options |
112
- mock_options.should_receive(:failed_job_handler).and_return('bury')
113
- end
114
- end
115
- end
116
- end
109
+ mock_job = double("Beanstalk::Job")
110
+
111
+ mock_options = double("options")
112
+ expect(mock_options).to receive(:failed_job_handler).and_return('bury')
117
113
 
118
- mock_exception = mock("Exception")
119
- mock_exception.should_receive(:backtrace).and_return([])
120
- mock_job.should_receive(:ayl_bury)
114
+ mock_message = double("message")
115
+ expect(mock_message).to receive(:options).and_return(mock_options)
121
116
 
122
- mock_mailer = mock("Mailer")
123
- mock_mailer.should_receive(:deliver_message).with(any_args())
117
+ mock_job.should_receive(:ayl_message).and_return(mock_message)
124
118
 
125
- Ayl::Mailer.should_receive(:instance).and_return(mock_mailer)
119
+ mock_exception = double("Exception")
120
+ expect(mock_exception).to receive(:backtrace).and_return([])
121
+ expect(mock_job).to receive(:ayl_bury)
122
+
123
+ mock_mailer = double("Mailer")
124
+ expect(mock_mailer).to receive(:deliver_message).with(any_args())
125
+
126
+ expect(Ayl::Mailer).to receive(:instance).and_return(mock_mailer)
126
127
 
127
128
  @worker.send(:deal_with_unexpected_exception, mock_job, mock_exception)
128
129
  end
@@ -139,91 +140,94 @@ describe Ayl::Beanstalk::Worker do
139
140
  @worker.stub_chain(:logger, :debug)
140
141
  Ayl::MessageOptions.default_queue_name = 'the queue name'
141
142
 
142
- @mock_pool = mock("Beanstalk::Pool")
143
- @mock_pool.should_receive(:watch).with('the queue name')
143
+ mock_tubes = double("Tubes")
144
+ expect(mock_tubes).to receive(:watch!).with('the queue name')
145
+ @mock_pool = double("Beanstalk::Pool")
146
+ expect(@mock_pool).to receive(:tubes).and_return(mock_tubes)
144
147
  @worker.stub(:pool).and_return(@mock_pool)
145
148
  end
146
149
 
147
150
  it "should process a message received from beanstalk" do
148
- mock_message = mock("Ayl::Message")
151
+ mock_message = double("Ayl::Message")
152
+
153
+ mock_job = double("Beanstalk::Job")
154
+ expect(mock_job).to receive(:ayl_message).at_least(1).times.and_return(mock_message)
155
+ expect(mock_job).to receive(:ayl_delete)
149
156
 
150
- mock_job = mock("Beanstalk::Job")
151
- mock_job.should_receive(:ayl_message).at_least(1).times.and_return(mock_message)
152
- mock_job.should_receive(:ayl_delete)
157
+ expect(@worker).to receive(:process_message).with(mock_message)
153
158
 
154
- @worker.should_receive(:process_message).with(mock_message)
159
+ expect(@worker).to receive(:reserve_job).and_yield(mock_job)
155
160
 
156
- @worker.should_receive(:reserve_job).and_yield(mock_job)
157
161
 
158
162
  @worker.process_messages
159
163
  end
160
164
 
161
165
  it "should do nothing if the received message is invalid (nil)" do
162
- mock_job = mock("Beanstalk::Job")
163
- mock_job.should_receive(:ayl_message).at_least(1).times.and_return(nil)
164
- mock_job.should_receive(:ayl_delete)
166
+ mock_job = double("Beanstalk::Job")
167
+ expect(mock_job).to receive(:ayl_message).at_least(1).times.and_return(nil)
168
+ expect(mock_job).to receive(:ayl_delete)
165
169
 
166
- @worker.should_not_receive(:process_message)
170
+ expect(@worker).not_to receive(:process_message)
167
171
 
168
- @worker.should_receive(:reserve_job).and_yield(mock_job)
172
+ expect(@worker).to receive(:reserve_job).and_yield(mock_job)
169
173
 
170
174
  @worker.process_messages
171
175
  end
172
176
 
173
177
  it "should delete the job and re-raise the exception on a SystemExit" do
174
- mock_message = mock("Ayl::Message")
178
+ mock_message = double("Ayl::Message")
175
179
 
176
- mock_job = mock("Beanstalk::Job")
177
- mock_job.should_receive(:ayl_message).at_least(1).times.and_return(mock_message)
178
- mock_job.should_receive(:ayl_delete)
180
+ mock_job = double("Beanstalk::Job")
181
+ expect(mock_job).to receive(:ayl_message).at_least(1).times.and_return(mock_message)
182
+ expect(mock_job).to receive(:ayl_delete)
179
183
 
180
- @worker.should_receive(:process_message).with(mock_message).and_raise(SystemExit)
184
+ expect(@worker).to receive(:process_message).with(mock_message).and_raise(SystemExit)
181
185
 
182
- @worker.should_receive(:reserve_job).and_yield(mock_job)
186
+ expect(@worker).to receive(:reserve_job).and_yield(mock_job)
183
187
 
184
- lambda { @worker.process_messages }.should raise_error(SystemExit)
188
+ expect { @worker.process_messages }.to raise_error(SystemExit)
185
189
  end
186
190
 
187
191
  it "should decay the job if the message requires it" do
188
- mock_message = mock("Ayl::Message")
192
+ mock_message = double("Ayl::Message")
189
193
 
190
- mock_job = mock("Beanstalk::Job")
191
- mock_job.should_receive(:ayl_message).at_least(1).times.and_return(mock_message)
192
- mock_job.should_receive(:ayl_decay).with(20)
194
+ mock_job = double("Beanstalk::Job")
195
+ expect(mock_job).to receive(:ayl_message).at_least(1).times.and_return(mock_message)
196
+ expect(mock_job).to receive(:ayl_decay).with(20)
193
197
 
194
- @worker.should_receive(:process_message).with(mock_message).and_raise(Ayl::Beanstalk::RequiresJobDecay.new(20))
198
+ expect(@worker).to receive(:process_message).with(mock_message).and_raise(Ayl::Beanstalk::RequiresJobDecay.new(20))
195
199
 
196
- @worker.should_receive(:reserve_job).and_yield(mock_job)
200
+ expect(@worker).to receive(:reserve_job).and_yield(mock_job)
197
201
 
198
202
  @worker.process_messages
199
203
  end
200
204
 
201
205
  it "should bury the job if the message requires it" do
202
- mock_message = mock("Ayl::Message")
206
+ mock_message = double("Ayl::Message")
203
207
 
204
- mock_job = mock("Beanstalk::Job")
205
- mock_job.should_receive(:ayl_message).at_least(1).times.and_return(mock_message)
206
- mock_job.should_receive(:ayl_bury)
208
+ mock_job = double("Beanstalk::Job")
209
+ expect(mock_job).to receive(:ayl_message).at_least(1).times.and_return(mock_message)
210
+ expect(mock_job).to receive(:ayl_bury)
207
211
 
208
- @worker.should_receive(:process_message).with(mock_message).and_raise(Ayl::Beanstalk::RequiresJobBury)
212
+ expect(@worker).to receive(:process_message).with(mock_message).and_raise(Ayl::Beanstalk::RequiresJobBury)
209
213
 
210
- @worker.should_receive(:reserve_job).and_yield(mock_job)
214
+ expect(@worker).to receive(:reserve_job).and_yield(mock_job)
211
215
 
212
216
  @worker.process_messages
213
217
  end
214
218
 
215
219
  it "should handle all other unexpected exceptions" do
216
- mock_message = mock("Ayl::Message")
220
+ mock_message = double("Ayl::Message")
217
221
 
218
- mock_job = mock("Beanstalk::Job")
219
- mock_job.should_receive(:ayl_message).at_least(1).times.and_return(mock_message)
222
+ mock_job = double("Beanstalk::Job")
223
+ expect(mock_job).to receive(:ayl_message).at_least(1).times.and_return(mock_message)
220
224
 
221
225
  ex = Exception.new
222
226
 
223
- @worker.should_receive(:process_message).with(mock_message).and_raise(ex)
227
+ expect(@worker).to receive(:process_message).with(mock_message).and_raise(ex)
224
228
 
225
- @worker.should_receive(:reserve_job).and_yield(mock_job)
226
- @worker.should_receive(:deal_with_unexpected_exception).with(mock_job, ex)
229
+ expect(@worker).to receive(:reserve_job).and_yield(mock_job)
230
+ expect(@worker).to receive(:deal_with_unexpected_exception).with(mock_job, ex)
227
231
 
228
232
  @worker.process_messages
229
233
  end
metadata CHANGED
@@ -1,145 +1,129 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ayl-beanstalk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - j0hnds@gmail.com
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-07 00:00:00.000000000 Z
11
+ date: 2015-06-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ayl
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 0.3.0
19
+ version: '0.4'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 0.3.0
26
+ version: '0.4'
30
27
  - !ruby/object:Gem::Dependency
31
- name: beanstalk-client
28
+ name: beaneater
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: 1.1.0
33
+ version: '1.0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: 1.1.0
40
+ version: '1.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: daemons
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: 1.1.0
47
+ version: '1.1'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
- version: 1.1.0
54
+ version: '1.1'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
- version: 2.3.0
61
+ version: '2.14'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
- version: 2.3.0
68
+ version: '2.14'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: bundler
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
- version: 1.0.0
75
+ version: '1.10'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
- version: 1.0.0
82
+ version: '1.10'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: jeweler
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - "~>"
100
88
  - !ruby/object:Gem::Version
101
- version: 1.6.4
89
+ version: '2.0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - "~>"
108
95
  - !ruby/object:Gem::Version
109
- version: 1.6.4
96
+ version: '2.0'
110
97
  - !ruby/object:Gem::Dependency
111
- name: rcov
98
+ name: rails
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: '0'
103
+ version: '4.1'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - "~>"
124
109
  - !ruby/object:Gem::Version
125
- version: '0'
110
+ version: '4.1'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: pry
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - "~>"
132
116
  - !ruby/object:Gem::Version
133
- version: '0'
117
+ version: '0.9'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - "~>"
140
123
  - !ruby/object:Gem::Version
141
- version: '0'
142
- description: Ayl extension to provide beanstalk support.
124
+ version: '0.9'
125
+ description: Ayl extension to provide beanstalk support for applications requiring
126
+ async processing.
143
127
  email: j0hnds@gmail.com
144
128
  executables:
145
129
  - ayl_beanstalk
@@ -150,8 +134,8 @@ extra_rdoc_files:
150
134
  - LICENSE.txt
151
135
  - README.rdoc
152
136
  files:
153
- - .document
154
- - .rspec
137
+ - ".document"
138
+ - ".rspec"
155
139
  - Gemfile
156
140
  - Gemfile.lock
157
141
  - LICENSE.txt
@@ -181,29 +165,25 @@ files:
181
165
  homepage: http://github.com/j0hnds/ayl-beanstalk
182
166
  licenses:
183
167
  - MIT
168
+ metadata: {}
184
169
  post_install_message:
185
170
  rdoc_options: []
186
171
  require_paths:
187
172
  - lib
188
173
  required_ruby_version: !ruby/object:Gem::Requirement
189
- none: false
190
174
  requirements:
191
- - - ! '>='
175
+ - - ">="
192
176
  - !ruby/object:Gem::Version
193
177
  version: '0'
194
- segments:
195
- - 0
196
- hash: -3806134538379917538
197
178
  required_rubygems_version: !ruby/object:Gem::Requirement
198
- none: false
199
179
  requirements:
200
- - - ! '>='
180
+ - - ">="
201
181
  - !ruby/object:Gem::Version
202
182
  version: '0'
203
183
  requirements: []
204
184
  rubyforge_project:
205
- rubygems_version: 1.8.23
185
+ rubygems_version: 2.4.6
206
186
  signing_key:
207
- specification_version: 3
187
+ specification_version: 4
208
188
  summary: Ayl extension to provide beanstalk support.
209
189
  test_files: []