sidekiq-bus 0.5.10 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe SidekiqBus do
6
+ describe '.generate_weighted_queues' do
7
+ subject { SidekiqBus.generate_weighted_queues(args) }
8
+
9
+ let(:args) { {} }
10
+
11
+ before do
12
+ QueueBus.dispatch('app') do
13
+ subscribe 'some_event' do |_|
14
+ end
15
+ end
16
+ end
17
+
18
+ it 'includes bus incoming' do
19
+ expect(subject.count('bus_incoming')).to eq 1
20
+ end
21
+
22
+ it 'includes subscribed queues' do
23
+ expect(subject.count('app_default')).to eq 1
24
+ end
25
+
26
+ it 'sorts alphabetical' do
27
+ expect(subject).to eq %w[app_default bus_incoming]
28
+ end
29
+
30
+ context 'with overrides' do
31
+ let(:args) do
32
+ super().merge(overrides: { 'queue_a' => 3, 'app_default' => 5 })
33
+ end
34
+
35
+ it 'includes weight-copies of the queue names' do
36
+ expect(subject.count('queue_a')).to eq 3
37
+ end
38
+
39
+ it 'applies the override to an existing queue' do
40
+ expect(subject.count('app_default')).to eq 5
41
+ end
42
+
43
+ it 'sorts by weight' do
44
+ expect(subject)
45
+ .to eq %w[app_default app_default app_default app_default app_default
46
+ queue_a queue_a queue_a
47
+ bus_incoming]
48
+ end
49
+
50
+ context 'that are symbols' do
51
+ let(:args) do
52
+ super().merge(overrides: { queue_a: 3, app_default: 5 })
53
+ end
54
+
55
+ it 'includes weight-copies of the queue names' do
56
+ expect(subject.count('queue_a')).to eq 3
57
+ end
58
+
59
+ it 'applies the override to an existing queue' do
60
+ expect(subject.count('app_default')).to eq 5
61
+ end
62
+
63
+ it 'sorts by weight' do
64
+ expect(subject)
65
+ .to eq %w[app_default app_default app_default app_default app_default
66
+ queue_a queue_a queue_a
67
+ bus_incoming]
68
+ end
69
+ end
70
+
71
+ context 'with multiple of same weight' do
72
+ let(:args) do
73
+ super().merge(overrides: { 'queue_a' => 2, 'app_default' => 2 })
74
+ end
75
+
76
+ it 'sorts alphabetical' do
77
+ expect(subject)
78
+ .to eq %w[app_default app_default queue_a queue_a bus_incoming]
79
+ end
80
+ end
81
+
82
+ context 'when negative' do
83
+ let(:args) do
84
+ super().merge(overrides: { 'queue_a' => -1, 'app_default' => -1 })
85
+ end
86
+
87
+ it 'includes 1 of each' do
88
+ expect(subject.count('queue_a')).to eq 1
89
+ expect(subject.count('app_default')).to eq 1
90
+ end
91
+ end
92
+
93
+ context 'and a default' do
94
+ let(:args) { super().merge(default: 4) }
95
+
96
+ it 'includes bus incoming' do
97
+ expect(subject.count('bus_incoming')).to eq 4
98
+ end
99
+
100
+ it 'includes weight-copies of the queue names' do
101
+ expect(subject.count('queue_a')).to eq 3
102
+ end
103
+
104
+ it 'applies the override to an existing queue' do
105
+ expect(subject.count('app_default')).to eq 5
106
+ end
107
+ end
108
+ end
109
+
110
+ context 'with a default' do
111
+ let(:args) { super().merge(default: 5) }
112
+
113
+ it 'applies it to bus incoming' do
114
+ expect(subject.count('bus_incoming')).to eq 5
115
+ end
116
+
117
+ it 'applies it to an existing queue' do
118
+ expect(subject.count('app_default')).to eq 5
119
+ end
120
+ end
121
+ end
122
+ end
data/spec/spec_helper.rb CHANGED
@@ -59,10 +59,10 @@ RSpec.configure do |config|
59
59
  config.alias_example_to :fit, focus: true
60
60
 
61
61
  config.mock_with :rspec do |c|
62
- c.syntax = :should
62
+ c.syntax = :expect
63
63
  end
64
64
  config.expect_with :rspec do |c|
65
- c.syntax = :should
65
+ c.syntax = :expect
66
66
  end
67
67
 
68
68
  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