queue-bus 0.5.9 → 0.6.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.
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe QueueBus::Middleware do
6
+ subject { described_class::Stack.new }
7
+
8
+ let(:args) { { rand: rand } }
9
+ let(:inner) { proc {} }
10
+
11
+ let(:base_class) do
12
+ # Creates a unique base class that provides tracking of calls.
13
+ Class.new(QueueBus::Middleware::Abstract) do
14
+ class << self
15
+ attr_accessor :called_at
16
+ end
17
+
18
+ def call(_args)
19
+ self.class.called_at = Time.now
20
+ @app.call
21
+ end
22
+ end
23
+ end
24
+
25
+ context 'with none configured' do
26
+ it 'falls through' do
27
+ expect(inner).to receive(:call)
28
+ subject.run(args, &inner)
29
+ end
30
+ end
31
+
32
+ context 'with the abstract class configured' do
33
+ before do
34
+ subject.use(QueueBus::Middleware::Abstract)
35
+ end
36
+
37
+ it 'runs the inner' do
38
+ expect(inner).to receive(:call).and_call_original
39
+ subject.run(args, &inner)
40
+ end
41
+ end
42
+
43
+ context 'with one middleware' do
44
+ let(:middleware) do
45
+ Class.new(base_class) do
46
+ class << self
47
+ attr_accessor :args
48
+ end
49
+
50
+ def call(args)
51
+ self.class.args = args
52
+ super
53
+ end
54
+ end
55
+ end
56
+
57
+ before do
58
+ subject.use(middleware)
59
+ end
60
+
61
+ it 'calls the middleware with the args' do
62
+ subject.run(args, &inner)
63
+
64
+ expect(middleware.args).to eql args
65
+ end
66
+
67
+ it 'calls the middleware and then inner' do
68
+ expect(inner).to receive(:call).and_call_original
69
+ subject.run(args, &inner)
70
+ expect(middleware.called_at).not_to be_nil
71
+ end
72
+
73
+ context 'and the middleware does not yield' do
74
+ let(:middleware) do
75
+ Class.new(base_class) do
76
+ def call(_args)
77
+ self.class.called_at = Time.now
78
+ # no-op
79
+ end
80
+ end
81
+ end
82
+
83
+ it 'does not run inner' do
84
+ expect(inner).not_to receive(:call).and_call_original
85
+ subject.run(args, &inner)
86
+ expect(middleware.called_at).not_to be_nil
87
+ end
88
+ end
89
+ end
90
+
91
+ context 'with more than one middleware' do
92
+ let(:middlewares) do
93
+ Array.new(rand(2..20)).map do
94
+ Class.new(base_class)
95
+ end
96
+ end
97
+
98
+ before do
99
+ middlewares.each do |middleware|
100
+ subject.use(middleware)
101
+ end
102
+ end
103
+
104
+ it 'calls all the middlewares in order' do
105
+ expect(inner).to receive(:call).and_call_original
106
+ subject.run(args, &inner)
107
+ # Test by sorting by when it was called. This should be in a strict
108
+ # order based on call order.
109
+ expect(middlewares.sort_by(&:called_at)).to eq middlewares
110
+ end
111
+ end
112
+ end
data/spec/publish_spec.rb CHANGED
@@ -4,7 +4,7 @@ describe "Publishing an event" do
4
4
 
5
5
  before(:each) do
6
6
  Timecop.freeze
7
- QueueBus.stub(:generate_uuid).and_return("idfhlkj")
7
+ allow(QueueBus).to receive(:generate_uuid).and_return("idfhlkj")
8
8
  end
9
9
  after(:each) do
10
10
  Timecop.return
@@ -19,15 +19,15 @@ describe "Publishing an event" do
19
19
  event_name = "event_name"
20
20
 
21
21
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
22
- val.should == nil
22
+ expect(val).to eq(nil)
23
23
 
24
24
  QueueBus.publish(event_name, hash)
25
25
 
26
26
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
27
27
  hash = JSON.parse(val)
28
- hash["class"].should == "QueueBus::Worker"
29
- hash["args"].size.should == 1
30
- JSON.parse(hash["args"].first).should == {"bus_event_type" => event_name, "two"=>"here", "one"=>1, "id" => 12}.merge(bus_attrs)
28
+ expect(hash["class"]).to eq("QueueBus::Worker")
29
+ expect(hash["args"].size).to eq(1)
30
+ expect(JSON.parse(hash["args"].first)).to eq({"bus_event_type" => event_name, "two"=>"here", "one"=>1, "id" => 12}.merge(bus_attrs))
31
31
 
32
32
  end
33
33
 
@@ -36,15 +36,15 @@ describe "Publishing an event" do
36
36
  event_name = "event_name"
37
37
 
38
38
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
39
- val.should == nil
39
+ expect(val).to eq(nil)
40
40
 
41
41
  QueueBus.publish(event_name, hash)
42
42
 
43
43
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
44
44
  hash = JSON.parse(val)
45
- hash["class"].should == "QueueBus::Worker"
46
- hash["args"].size.should == 1
47
- JSON.parse(hash["args"].first).should == {"bus_event_type" => event_name, "two"=>"here", "one"=>1}.merge(bus_attrs).merge("bus_id" => 'app-given')
45
+ expect(hash["class"]).to eq("QueueBus::Worker")
46
+ expect(hash["args"].size).to eq(1)
47
+ expect(JSON.parse(hash["args"].first)).to eq({"bus_event_type" => event_name, "two"=>"here", "one"=>1}.merge(bus_attrs).merge("bus_id" => 'app-given'))
48
48
  end
49
49
 
50
50
  it "should add metadata via callback" do
@@ -58,7 +58,7 @@ describe "Publishing an event" do
58
58
  event_name = "event_name"
59
59
 
60
60
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
61
- val.should == nil
61
+ expect(val).to eq(nil)
62
62
 
63
63
  QueueBus.publish(event_name, hash)
64
64
 
@@ -66,33 +66,33 @@ describe "Publishing an event" do
66
66
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
67
67
  hash = JSON.parse(val)
68
68
  att = JSON.parse(hash["args"].first)
69
- att["mine"].should == 4
70
- myval.should == 1
69
+ expect(att["mine"]).to eq(4)
70
+ expect(myval).to eq(1)
71
71
  end
72
72
 
73
73
  it "should set the timezone and locale if available" do
74
- defined?(I18n).should be_nil
75
- Time.respond_to?(:zone).should eq(false)
74
+ expect(defined?(I18n)).to be_nil
75
+ expect(Time.respond_to?(:zone)).to eq(false)
76
76
 
77
77
  stub_const("I18n", Class.new)
78
- I18n.stub(:locale).and_return("jp")
78
+ allow(I18n).to receive(:locale).and_return("jp")
79
79
 
80
- Time.stub(:zone).and_return(double('zone', :name => "EST"))
80
+ allow(Time).to receive(:zone).and_return(double('zone', :name => "EST"))
81
81
 
82
82
  hash = {:one => 1, "two" => "here", "bus_id" => "app-given" }
83
83
  event_name = "event_name"
84
84
 
85
85
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
86
- val.should == nil
86
+ expect(val).to eq(nil)
87
87
 
88
88
  QueueBus.publish(event_name, hash)
89
89
 
90
90
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
91
91
  hash = JSON.parse(val)
92
- hash["class"].should == "QueueBus::Worker"
92
+ expect(hash["class"]).to eq("QueueBus::Worker")
93
93
  att = JSON.parse(hash["args"].first)
94
- att["bus_locale"].should == "jp"
95
- att["bus_timezone"].should == "EST"
94
+ expect(att["bus_locale"]).to eq("jp")
95
+ expect(att["bus_timezone"]).to eq("EST")
96
96
  end
97
97
 
98
98
  end
data/spec/rider_spec.rb CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module QueueBus
4
4
  describe Rider do
5
5
  it "should call execute" do
6
- QueueBus.should_receive(:dispatcher_execute)
6
+ expect(QueueBus).to receive(:dispatcher_execute)
7
7
  Rider.perform("bus_rider_app_key" => "app", "bus_rider_sub_key" => "sub", "ok" => true, "bus_event_type" => "event_name")
8
8
  end
9
9
 
@@ -13,10 +13,10 @@ module QueueBus
13
13
  Runner1.run(attributes)
14
14
  end
15
15
  end
16
- Runner1.value.should == 0
16
+ expect(Runner1.value).to eq(0)
17
17
  Rider.perform("bus_locale" => "en", "bus_timezone" => "PST", "bus_rider_app_key" => "r1", "bus_rider_sub_key" => "event_name", "ok" => true, "bus_event_type" => "event_name")
18
18
  Rider.perform("bus_rider_app_key" => "other", "bus_rider_sub_key" => "event_name", "ok" => true, "bus_event_type" => "event_name")
19
- Runner1.value.should == 1
19
+ expect(Runner1.value).to eq(1)
20
20
  end
21
21
 
22
22
  it "should set the timezone and locale if present" do
@@ -26,12 +26,12 @@ module QueueBus
26
26
  end
27
27
  end
28
28
 
29
- defined?(I18n).should be_nil
30
- Time.respond_to?(:zone).should eq(false)
29
+ expect(defined?(I18n)).to be_nil
30
+ expect(Time.respond_to?(:zone)).to eq(false)
31
31
 
32
32
  stub_const("I18n", Class.new)
33
- I18n.should_receive(:locale=).with("en")
34
- Time.should_receive(:zone=).with("PST")
33
+ expect(I18n).to receive(:locale=).with("en")
34
+ expect(Time).to receive(:zone=).with("PST")
35
35
 
36
36
  Rider.perform("bus_locale" => "en", "bus_timezone" => "PST", "bus_rider_app_key" => "r1", "bus_rider_sub_key" => "event_name", "ok" => true, "bus_event_type" => "event_name")
37
37
  end
data/spec/spec_helper.rb CHANGED
@@ -48,10 +48,10 @@ end
48
48
 
49
49
  RSpec.configure do |config|
50
50
  config.mock_with :rspec do |c|
51
- c.syntax = :should
51
+ c.syntax = :expect
52
52
  end
53
53
  config.expect_with :rspec do |c|
54
- c.syntax = :should
54
+ c.syntax = :expect
55
55
  end
56
56
 
57
57
  config.before(:each) do
@@ -70,111 +70,111 @@ require 'spec_helper'
70
70
  end
71
71
 
72
72
  it "should have the application" do
73
- SubscriberTest1.app_key.should == "my_thing"
74
- SubModule::SubscriberTest3.app_key.should == "sub_module"
75
- SubModule::SubscriberTest4.app_key.should == "sub_module"
73
+ expect(SubscriberTest1.app_key).to eq("my_thing")
74
+ expect(SubModule::SubscriberTest3.app_key).to eq("sub_module")
75
+ expect(SubModule::SubscriberTest4.app_key).to eq("sub_module")
76
76
  end
77
77
 
78
78
  it "should be able to transform the attributes" do
79
79
  dispatcher = QueueBus.dispatcher_by_key("test2")
80
80
  all = dispatcher.subscriptions.all
81
- all.size.should == 1
81
+ expect(all.size).to eq(1)
82
82
 
83
83
  sub = all.first
84
- sub.queue_name.should == "test2_default"
85
- sub.class_name.should == "SubscriberTest2"
86
- sub.key.should == "SubscriberTest2.test2"
87
- sub.matcher.filters.should == {"value"=>"bus_special_value_present"}
84
+ expect(sub.queue_name).to eq("test2_default")
85
+ expect(sub.class_name).to eq("SubscriberTest2")
86
+ expect(sub.key).to eq("SubscriberTest2.test2")
87
+ expect(sub.matcher.filters).to eq({"value"=>"bus_special_value_present"})
88
88
 
89
89
  QueueBus::Driver.perform(attributes.merge("bus_event_type" => "something2", "value"=>"nice"))
90
90
 
91
91
  hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:test2_default") })
92
- hash["class"].should == "QueueBus::Worker"
93
- hash["args"].size.should == 1
94
- JSON.parse(hash["args"].first).should eq({"bus_class_proxy" => "SubscriberTest2", "bus_rider_app_key"=>"test2", "bus_rider_sub_key"=>"SubscriberTest2.test2", "bus_rider_queue" => "test2_default", "bus_rider_class_name"=>"SubscriberTest2",
92
+ expect(hash["class"]).to eq("QueueBus::Worker")
93
+ expect(hash["args"].size).to eq(1)
94
+ expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "SubscriberTest2", "bus_rider_app_key"=>"test2", "bus_rider_sub_key"=>"SubscriberTest2.test2", "bus_rider_queue" => "test2_default", "bus_rider_class_name"=>"SubscriberTest2",
95
95
  "bus_event_type" => "something2", "value"=>"nice", "x"=>"y"}.merge(bus_attrs))
96
96
 
97
- QueueBus::Runner1.value.should == 0
98
- QueueBus::Runner2.value.should == 0
97
+ expect(QueueBus::Runner1.value).to eq(0)
98
+ expect(QueueBus::Runner2.value).to eq(0)
99
99
  QueueBus::Util.constantize(hash["class"]).perform(*hash["args"])
100
- QueueBus::Runner1.value.should == 1
101
- QueueBus::Runner2.value.should == 0
100
+ expect(QueueBus::Runner1.value).to eq(1)
101
+ expect(QueueBus::Runner2.value).to eq(0)
102
102
 
103
- QueueBus::Runner1.attributes.should == {"transformed" => 4}
103
+ expect(QueueBus::Runner1.attributes).to eq({"transformed" => 4})
104
104
 
105
105
 
106
106
  QueueBus::Driver.perform(attributes.merge("bus_event_type" => "something2", "value"=>"12"))
107
107
 
108
108
  hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:test2_default") })
109
- hash["class"].should == "QueueBus::Worker"
110
- hash["args"].size.should == 1
111
- JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "SubscriberTest2", "bus_rider_app_key"=>"test2", "bus_rider_sub_key"=>"SubscriberTest2.test2", "bus_rider_queue" => "test2_default", "bus_rider_class_name"=>"SubscriberTest2",
112
- "bus_event_type" => "something2", "value"=>"12", "x"=>"y"}.merge(bus_attrs)
109
+ expect(hash["class"]).to eq("QueueBus::Worker")
110
+ expect(hash["args"].size).to eq(1)
111
+ expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "SubscriberTest2", "bus_rider_app_key"=>"test2", "bus_rider_sub_key"=>"SubscriberTest2.test2", "bus_rider_queue" => "test2_default", "bus_rider_class_name"=>"SubscriberTest2",
112
+ "bus_event_type" => "something2", "value"=>"12", "x"=>"y"}.merge(bus_attrs))
113
113
 
114
- QueueBus::Runner1.value.should == 1
115
- QueueBus::Runner2.value.should == 0
114
+ expect(QueueBus::Runner1.value).to eq(1)
115
+ expect(QueueBus::Runner2.value).to eq(0)
116
116
  QueueBus::Util.constantize(hash["class"]).perform(*hash["args"])
117
- QueueBus::Runner1.value.should == 2
118
- QueueBus::Runner2.value.should == 0
117
+ expect(QueueBus::Runner1.value).to eq(2)
118
+ expect(QueueBus::Runner2.value).to eq(0)
119
119
 
120
- QueueBus::Runner1.attributes.should == {"transformed" => 2}
120
+ expect(QueueBus::Runner1.attributes).to eq({"transformed" => 2})
121
121
  end
122
122
 
123
123
 
124
124
  it "should put in a different queue" do
125
125
  dispatcher = QueueBus.dispatcher_by_key("sub_module")
126
126
  all = dispatcher.subscriptions.all
127
- all.size.should == 4
127
+ expect(all.size).to eq(4)
128
128
 
129
129
  sub = all.select{ |s| s.key == "SubModule::SubscriberTest3.test3"}.first
130
- sub.queue_name.should == "sub_queue1"
131
- sub.class_name.should == "SubModule::SubscriberTest3"
132
- sub.key.should == "SubModule::SubscriberTest3.test3"
133
- sub.matcher.filters.should == {"bus_event_type"=>"the_event"}
130
+ expect(sub.queue_name).to eq("sub_queue1")
131
+ expect(sub.class_name).to eq("SubModule::SubscriberTest3")
132
+ expect(sub.key).to eq("SubModule::SubscriberTest3.test3")
133
+ expect(sub.matcher.filters).to eq({"bus_event_type"=>"the_event"})
134
134
 
135
135
  sub = all.select{ |s| s.key == "SubModule::SubscriberTest3.the_event"}.first
136
- sub.queue_name.should == "sub_queue2"
137
- sub.class_name.should == "SubModule::SubscriberTest3"
138
- sub.key.should == "SubModule::SubscriberTest3.the_event"
139
- sub.matcher.filters.should == {"bus_event_type"=>"the_event"}
136
+ expect(sub.queue_name).to eq("sub_queue2")
137
+ expect(sub.class_name).to eq("SubModule::SubscriberTest3")
138
+ expect(sub.key).to eq("SubModule::SubscriberTest3.the_event")
139
+ expect(sub.matcher.filters).to eq({"bus_event_type"=>"the_event"})
140
140
 
141
141
  sub = all.select{ |s| s.key == "SubModule::SubscriberTest3.other"}.first
142
- sub.queue_name.should == "sub_module_default"
143
- sub.class_name.should == "SubModule::SubscriberTest3"
144
- sub.key.should == "SubModule::SubscriberTest3.other"
145
- sub.matcher.filters.should == {"bus_event_type"=>"other_event"}
142
+ expect(sub.queue_name).to eq("sub_module_default")
143
+ expect(sub.class_name).to eq("SubModule::SubscriberTest3")
144
+ expect(sub.key).to eq("SubModule::SubscriberTest3.other")
145
+ expect(sub.matcher.filters).to eq({"bus_event_type"=>"other_event"})
146
146
 
147
147
  sub = all.select{ |s| s.key == "SubModule::SubscriberTest4.test4"}.first
148
- sub.queue_name.should == "sub_queue1"
149
- sub.class_name.should == "SubModule::SubscriberTest4"
150
- sub.key.should == "SubModule::SubscriberTest4.test4"
151
- sub.matcher.filters.should == {"bus_event_type"=>"test4"}
148
+ expect(sub.queue_name).to eq("sub_queue1")
149
+ expect(sub.class_name).to eq("SubModule::SubscriberTest4")
150
+ expect(sub.key).to eq("SubModule::SubscriberTest4.test4")
151
+ expect(sub.matcher.filters).to eq({"bus_event_type"=>"test4"})
152
152
 
153
153
  QueueBus::Driver.perform(attributes.merge("bus_event_type" => "the_event"))
154
154
 
155
155
  hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:sub_queue1") })
156
- hash["class"].should == "QueueBus::Worker"
157
- hash["args"].size.should == 1
158
- JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "SubModule::SubscriberTest3", "bus_rider_app_key"=>"sub_module", "bus_rider_sub_key"=>"SubModule::SubscriberTest3.test3", "bus_rider_queue" => "sub_queue1", "bus_rider_class_name"=>"SubModule::SubscriberTest3",
159
- "bus_event_type" => "the_event", "x" => "y"}.merge(bus_attrs)
156
+ expect(hash["class"]).to eq("QueueBus::Worker")
157
+ expect(hash["args"].size).to eq(1)
158
+ expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "SubModule::SubscriberTest3", "bus_rider_app_key"=>"sub_module", "bus_rider_sub_key"=>"SubModule::SubscriberTest3.test3", "bus_rider_queue" => "sub_queue1", "bus_rider_class_name"=>"SubModule::SubscriberTest3",
159
+ "bus_event_type" => "the_event", "x" => "y"}.merge(bus_attrs))
160
160
 
161
- QueueBus::Runner1.value.should == 0
162
- QueueBus::Runner2.value.should == 0
161
+ expect(QueueBus::Runner1.value).to eq(0)
162
+ expect(QueueBus::Runner2.value).to eq(0)
163
163
  QueueBus::Util.constantize(hash["class"]).perform(*hash["args"])
164
- QueueBus::Runner1.value.should == 1
165
- QueueBus::Runner2.value.should == 0
164
+ expect(QueueBus::Runner1.value).to eq(1)
165
+ expect(QueueBus::Runner2.value).to eq(0)
166
166
 
167
167
  hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:sub_queue2") })
168
- hash["class"].should == "QueueBus::Worker"
169
- hash["args"].size.should == 1
170
- JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "SubModule::SubscriberTest3", "bus_rider_app_key"=>"sub_module", "bus_rider_sub_key"=>"SubModule::SubscriberTest3.the_event", "bus_rider_queue" => "sub_queue2", "bus_rider_class_name"=>"SubModule::SubscriberTest3",
171
- "bus_event_type" => "the_event", "x" => "y"}.merge(bus_attrs)
168
+ expect(hash["class"]).to eq("QueueBus::Worker")
169
+ expect(hash["args"].size).to eq(1)
170
+ expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "SubModule::SubscriberTest3", "bus_rider_app_key"=>"sub_module", "bus_rider_sub_key"=>"SubModule::SubscriberTest3.the_event", "bus_rider_queue" => "sub_queue2", "bus_rider_class_name"=>"SubModule::SubscriberTest3",
171
+ "bus_event_type" => "the_event", "x" => "y"}.merge(bus_attrs))
172
172
 
173
- QueueBus::Runner1.value.should == 1
174
- QueueBus::Runner2.value.should == 0
173
+ expect(QueueBus::Runner1.value).to eq(1)
174
+ expect(QueueBus::Runner2.value).to eq(0)
175
175
  QueueBus::Util.constantize(hash["class"]).perform(*hash["args"])
176
- QueueBus::Runner1.value.should == 1
177
- QueueBus::Runner2.value.should == 1
176
+ expect(QueueBus::Runner1.value).to eq(1)
177
+ expect(QueueBus::Runner2.value).to eq(1)
178
178
  end
179
179
 
180
180
  it "should subscribe to default and attributes" do
@@ -182,19 +182,19 @@ require 'spec_helper'
182
182
  all = dispatcher.subscriptions.all
183
183
 
184
184
  sub = all.select{ |s| s.key == "SubscriberTest1.event_sub"}.first
185
- sub.queue_name.should == "myqueue"
186
- sub.class_name.should == "SubscriberTest1"
187
- sub.key.should == "SubscriberTest1.event_sub"
188
- sub.matcher.filters.should == {"bus_event_type"=>"event_sub"}
185
+ expect(sub.queue_name).to eq("myqueue")
186
+ expect(sub.class_name).to eq("SubscriberTest1")
187
+ expect(sub.key).to eq("SubscriberTest1.event_sub")
188
+ expect(sub.matcher.filters).to eq({"bus_event_type"=>"event_sub"})
189
189
 
190
190
  sub = all.select{ |s| s.key == "SubscriberTest1.thing_filter"}.first
191
- sub.queue_name.should == "myqueue"
192
- sub.class_name.should == "SubscriberTest1"
193
- sub.key.should == "SubscriberTest1.thing_filter"
194
- sub.matcher.filters.should == {"x"=>"y"}
191
+ expect(sub.queue_name).to eq("myqueue")
192
+ expect(sub.class_name).to eq("SubscriberTest1")
193
+ expect(sub.key).to eq("SubscriberTest1.thing_filter")
194
+ expect(sub.matcher.filters).to eq({"x"=>"y"})
195
195
 
196
196
  QueueBus::Driver.perform(attributes.merge("bus_event_type" => "event_sub"))
197
- QueueBus.redis { |redis| redis.smembers("queues") }.should =~ ["myqueue"]
197
+ expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["myqueue"])
198
198
 
199
199
  pop1 = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:myqueue") })
200
200
  pop2 = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:myqueue") })
@@ -207,63 +207,63 @@ require 'spec_helper'
207
207
  hash2 = pop1
208
208
  end
209
209
 
210
- hash1["class"].should == "QueueBus::Worker"
211
- JSON.parse(hash1["args"].first).should eq({"bus_class_proxy" => "SubscriberTest1", "bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.thing_filter", "bus_rider_queue" => "myqueue", "bus_rider_class_name"=>"SubscriberTest1",
210
+ expect(hash1["class"]).to eq("QueueBus::Worker")
211
+ expect(JSON.parse(hash1["args"].first)).to eq({"bus_class_proxy" => "SubscriberTest1", "bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.thing_filter", "bus_rider_queue" => "myqueue", "bus_rider_class_name"=>"SubscriberTest1",
212
212
  "bus_event_type" => "event_sub", "x" => "y"}.merge(bus_attrs))
213
213
 
214
- QueueBus::Runner1.value.should == 0
215
- QueueBus::Runner2.value.should == 0
214
+ expect(QueueBus::Runner1.value).to eq(0)
215
+ expect(QueueBus::Runner2.value).to eq(0)
216
216
  QueueBus::Util.constantize(hash1["class"]).perform(*hash1["args"])
217
- QueueBus::Runner1.value.should == 0
218
- QueueBus::Runner2.value.should == 1
217
+ expect(QueueBus::Runner1.value).to eq(0)
218
+ expect(QueueBus::Runner2.value).to eq(1)
219
219
 
220
- hash2["class"].should == "QueueBus::Worker"
221
- hash2["args"].size.should == 1
222
- JSON.parse(hash2["args"].first).should == {"bus_class_proxy" => "SubscriberTest1", "bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.event_sub", "bus_rider_queue" => "myqueue", "bus_rider_class_name"=>"SubscriberTest1",
223
- "bus_event_type" => "event_sub", "x" => "y"}.merge(bus_attrs)
220
+ expect(hash2["class"]).to eq("QueueBus::Worker")
221
+ expect(hash2["args"].size).to eq(1)
222
+ expect(JSON.parse(hash2["args"].first)).to eq({"bus_class_proxy" => "SubscriberTest1", "bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.event_sub", "bus_rider_queue" => "myqueue", "bus_rider_class_name"=>"SubscriberTest1",
223
+ "bus_event_type" => "event_sub", "x" => "y"}.merge(bus_attrs))
224
224
 
225
- QueueBus::Runner1.value.should == 0
226
- QueueBus::Runner2.value.should == 1
225
+ expect(QueueBus::Runner1.value).to eq(0)
226
+ expect(QueueBus::Runner2.value).to eq(1)
227
227
  QueueBus::Util.constantize(hash2["class"]).perform(*hash2["args"])
228
- QueueBus::Runner1.value.should == 1
229
- QueueBus::Runner2.value.should == 1
228
+ expect(QueueBus::Runner1.value).to eq(1)
229
+ expect(QueueBus::Runner2.value).to eq(1)
230
230
 
231
231
  QueueBus::Driver.perform(attributes.merge("bus_event_type" => "event_sub_other"))
232
- QueueBus.redis { |redis| redis.smembers("queues") }.should =~ ["myqueue"]
232
+ expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["myqueue"])
233
233
 
234
234
  hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:myqueue") })
235
- hash["class"].should == "QueueBus::Worker"
236
- hash["args"].size.should == 1
237
- JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "SubscriberTest1", "bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.thing_filter", "bus_rider_queue" => "myqueue", "bus_rider_class_name"=>"SubscriberTest1",
238
- "bus_event_type" => "event_sub_other", "x" => "y"}.merge(bus_attrs)
235
+ expect(hash["class"]).to eq("QueueBus::Worker")
236
+ expect(hash["args"].size).to eq(1)
237
+ expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "SubscriberTest1", "bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.thing_filter", "bus_rider_queue" => "myqueue", "bus_rider_class_name"=>"SubscriberTest1",
238
+ "bus_event_type" => "event_sub_other", "x" => "y"}.merge(bus_attrs))
239
239
 
240
- QueueBus::Runner1.value.should == 1
241
- QueueBus::Runner2.value.should == 1
240
+ expect(QueueBus::Runner1.value).to eq(1)
241
+ expect(QueueBus::Runner2.value).to eq(1)
242
242
  QueueBus::Util.constantize(hash["class"]).perform(*hash["args"])
243
- QueueBus::Runner1.value.should == 1
244
- QueueBus::Runner2.value.should == 2
243
+ expect(QueueBus::Runner1.value).to eq(1)
244
+ expect(QueueBus::Runner2.value).to eq(2)
245
245
 
246
246
  QueueBus::Driver.perform({"x"=>"z"}.merge("bus_event_type" => "event_sub_other"))
247
- QueueBus.redis { |redis| redis.smembers("queues") }.should =~ ["myqueue"]
247
+ expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["myqueue"])
248
248
 
249
- QueueBus.redis { |redis| redis.lpop("queue:myqueue") }.should be_nil
249
+ expect(QueueBus.redis { |redis| redis.lpop("queue:myqueue") }).to be_nil
250
250
  end
251
251
 
252
252
  describe ".perform" do
253
253
  let(:attributes) { {"bus_rider_sub_key"=>"SubscriberTest1.event_sub", "bus_locale" => "en", "bus_timezone" => "PST"} }
254
254
  it "should call the method based on key" do
255
- SubscriberTest1.any_instance.should_receive(:event_sub)
255
+ expect_any_instance_of(SubscriberTest1).to receive(:event_sub)
256
256
  SubscriberTest1.perform(attributes)
257
257
  end
258
258
  it "should set the timezone and locale if present" do
259
- defined?(I18n).should be_nil
260
- Time.respond_to?(:zone).should eq(false)
259
+ expect(defined?(I18n)).to be_nil
260
+ expect(Time.respond_to?(:zone)).to eq(false)
261
261
 
262
262
  stub_const("I18n", Class.new)
263
- I18n.should_receive(:locale=).with("en")
264
- Time.should_receive(:zone=).with("PST")
263
+ expect(I18n).to receive(:locale=).with("en")
264
+ expect(Time).to receive(:zone=).with("PST")
265
265
 
266
- SubscriberTest1.any_instance.should_receive(:event_sub)
266
+ expect_any_instance_of(SubscriberTest1).to receive(:event_sub)
267
267
  SubscriberTest1.perform(attributes)
268
268
  end
269
269
  end