sidekiq-bus 0.5.10 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7489c0d0c8039c603f60784f1da9229dc7b738ef
4
- data.tar.gz: 411beaacbb95dbff057c75b489938858f92cd3c1
3
+ metadata.gz: 63c03ac9abef7e30948f4e1cc83d499251853846
4
+ data.tar.gz: ac25e298ce8dab9160026a2bdd8c5eaba099198b
5
5
  SHA512:
6
- metadata.gz: aa5c04a124802c488ee1427727353fbf3257d534e45dcd027afd6964fd07d42fe88f558dc5d9ff46b4e0ed308f09d15bab8444bb45f78befc3e4c89b10775124
7
- data.tar.gz: 01516f2ffb2e18cf7a9f704000debb019f6f20fc16796df6c3ac0b368c44ee774094ea91bbcba6f7085b4ff5e2bed9773eb6c7b45075766b2f412398245a0abe
6
+ metadata.gz: 8fa90c9f87a6e27c8a9a29c0d5823460874fb37c99812addaca062788aed32b9cb769f9997006d9c671f4adfbc9e4400e8b0a9d80810b22c79d797eca4f58c85
7
+ data.tar.gz: 39cd967a17827ec6c8c7f0b0a8a767db802b33e32fe6bbfe2508e67f52a1a1e3471e97c17ceb0d0d46b25e398f2d56c2c54a1dadb4e7cf83ce17e4c1792f42cb
data/README.mdown CHANGED
@@ -11,7 +11,6 @@ To install, include the 'sidekiq-bus' gem and add the following to your Rakefile
11
11
  require "sidekiq_bus/tasks"
12
12
  ```
13
13
 
14
-
15
14
  ### Example
16
15
 
17
16
  Application A can publish an event
@@ -108,6 +107,29 @@ end
108
107
 
109
108
  Note: This subscribes when this class is loaded, so it needs to be in your load or otherwise referenced/required during app initialization to work properly.
110
109
 
110
+ ### sidekiq.rb
111
+
112
+ To make sure that your sidekiq server is consuming on the proper queues, add code like
113
+ this to your `config/sidekiq.rb` file:
114
+
115
+ ```ruby
116
+ # config/sidekiq.rb
117
+
118
+ # Load the environment here
119
+ require './boot.rb'
120
+
121
+ if Sidekiq.server?
122
+ # Load the queues into sidekiq:
123
+ weights = {
124
+ 'app_events' => 10,
125
+ 'app_heartbeat' => 3,
126
+ 'app_refresh' => 1
127
+ }
128
+ Sidekiq.options[:queues] =
129
+ SidekiqBus.generate_weighted_queues(overrides: weights, default: 2)
130
+ end
131
+ ```
132
+
111
133
  ### Commands
112
134
 
113
135
  Each app needs to tell Redis about its subscriptions:
data/lib/sidekiq-bus.rb CHANGED
@@ -1,6 +1,46 @@
1
- require "queue-bus"
2
- require "sidekiq_bus/adapter"
3
- require "sidekiq_bus/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'queue-bus'
4
+ require 'sidekiq_bus/adapter'
5
+ require 'sidekiq_bus/version'
4
6
  require 'sidekiq_bus/middleware/retry'
5
7
 
6
8
  QueueBus.adapter = QueueBus::Adapters::Sidekiq.new
9
+
10
+ module SidekiqBus
11
+ # This method will analyze the current queues and generate an array that
12
+ # can operate as the sidekiq queues configuration. It should be based on how
13
+ # The sidekiq CLI builds weighted queues.
14
+ #
15
+ # @param overrides [Hash<String, Integer>] A mapping of queue names and
16
+ # weights that must be included
17
+ # @param default [Integer] The default weight to apply to any given queue
18
+ # @returns [Array<String>] The set of queue names weighted to sidekiq
19
+ def self.generate_weighted_queues(overrides: {}, default: 1)
20
+ # Gathers all queues and overrides as strictly strings
21
+ queues = Set.new(QueueBus::TaskManager.new(false).queue_names.map(&:to_s))
22
+ overrides = overrides.each_with_object({}) { |(q, w), h| h[q.to_s] = w }
23
+ overrides.default = default
24
+
25
+ # Also pitches-in for driving the bus.
26
+ queues << 'bus_incoming'
27
+
28
+ # Make sure every queue from the overrides is included
29
+ queues += overrides.keys
30
+
31
+ entry = Struct.new(:queue, :weight)
32
+
33
+ # Map all queue names to their weights and returns them as entries
34
+ entries = queues.map { |q| entry.new(q, [1, overrides[q]].max) }
35
+
36
+ # Sorts by weight to provide a visual indication of queue order in sidekiq
37
+ # UI. Otherwise they can appear in various orders. They will be sorted
38
+ # from greatest to least weight. The negative sign on the weight is key to
39
+ # making this work.
40
+ entries = entries.sort_by { |e| [-e.weight, e.queue] }
41
+
42
+ # Creates an array of N length with the same queue name (N=weight) then
43
+ # flattened into a single array
44
+ entries.flat_map { |e| Array.new(e.weight, e.queue) }
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module SidekiqBus
2
- VERSION = "0.5.10"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -19,26 +19,26 @@ describe "Sidekiq Integration" do
19
19
 
20
20
  it "should publish and receive" do
21
21
  Sidekiq::Testing.fake!
22
- QueueBus::Runner1.value.should == 0
22
+ expect(QueueBus::Runner1.value).to eq(0)
23
23
 
24
24
  QueueBus.publish("event_name", "ok" => true)
25
- QueueBus::Runner1.value.should == 0
25
+ expect(QueueBus::Runner1.value).to eq(0)
26
26
 
27
27
  QueueBus::Worker.perform_one
28
28
 
29
- QueueBus::Runner1.value.should == 0
29
+ expect(QueueBus::Runner1.value).to eq(0)
30
30
 
31
31
  QueueBus::Worker.perform_one
32
32
 
33
- QueueBus::Runner1.value.should == 1
33
+ expect(QueueBus::Runner1.value).to eq(1)
34
34
  end
35
35
 
36
36
  it "should publish and receive" do
37
37
  Sidekiq::Testing.inline!
38
- QueueBus::Runner1.value.should == 0
38
+ expect(QueueBus::Runner1.value).to eq(0)
39
39
 
40
40
  QueueBus.publish("event_name", "ok" => true)
41
- QueueBus::Runner1.value.should == 1
41
+ expect(QueueBus::Runner1.value).to eq(1)
42
42
  end
43
43
 
44
44
  end
@@ -46,7 +46,7 @@ describe "Sidekiq Integration" do
46
46
  describe "Delayed Publishing" do
47
47
  before(:each) do
48
48
  Timecop.freeze(now)
49
- QueueBus.stub(:generate_uuid).and_return("idfhlkj")
49
+ allow(QueueBus).to receive(:generate_uuid).and_return("idfhlkj")
50
50
  end
51
51
  after(:each) do
52
52
  Timecop.return
@@ -69,10 +69,10 @@ describe "Sidekiq Integration" do
69
69
 
70
70
  hash = JSON.parse(val)
71
71
 
72
- hash["class"].should == "QueueBus::Worker"
73
- hash["args"].size.should == 1
74
- JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_attrs)
75
- hash["queue"].should == "bus_incoming"
72
+ expect(hash["class"]).to eq("QueueBus::Worker")
73
+ expect(hash["args"].size).to eq(1)
74
+ expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_attrs))
75
+ expect(hash["queue"]).to eq("bus_incoming")
76
76
  end
77
77
 
78
78
  it "should move it to the real queue when processing" do
@@ -80,12 +80,12 @@ describe "Sidekiq Integration" do
80
80
  event_name = "event_name"
81
81
 
82
82
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
83
- val.should == nil
83
+ expect(val).to eq(nil)
84
84
 
85
85
  QueueBus.publish_at(future, event_name, hash)
86
86
 
87
87
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
88
- val.should == nil # nothing really added
88
+ expect(val).to eq(nil) # nothing really added
89
89
 
90
90
  if Sidekiq::VERSION < '4'
91
91
  Sidekiq::Scheduled::Poller.new.poll
@@ -94,7 +94,7 @@ describe "Sidekiq Integration" do
94
94
  end
95
95
 
96
96
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
97
- val.should == nil # nothing added yet
97
+ expect(val).to eq(nil) # nothing added yet
98
98
 
99
99
  # process scheduler in future
100
100
  Timecop.freeze(worktime) do
@@ -106,17 +106,17 @@ describe "Sidekiq Integration" do
106
106
 
107
107
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
108
108
  hash = JSON.parse(val)
109
- hash["class"].should == "QueueBus::Worker"
110
- hash["args"].size.should == 1
111
- JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_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" => "QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_attrs))
112
112
 
113
113
  QueueBus::Publisher.perform(JSON.parse(hash["args"].first))
114
114
 
115
115
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
116
116
  hash = JSON.parse(val)
117
- hash["class"].should == "QueueBus::Worker"
118
- hash["args"].size.should == 1
119
- JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "QueueBus::Driver", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(bus_attrs)
117
+ expect(hash["class"]).to eq("QueueBus::Worker")
118
+ expect(hash["args"].size).to eq(1)
119
+ expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "QueueBus::Driver", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(bus_attrs))
120
120
  end
121
121
  end
122
122
 
data/spec/adapter_spec.rb CHANGED
@@ -3,12 +3,12 @@ require 'spec_helper'
3
3
  describe "adapter is set" do
4
4
  it "should call it's enabled! method on init" do
5
5
  QueueBus.send(:reset)
6
- adapter_under_test_class.any_instance.should_receive(:enabled!)
6
+ expect_any_instance_of(adapter_under_test_class).to receive(:enabled!)
7
7
  instance = adapter_under_test_class.new
8
8
  QueueBus.send(:reset)
9
9
  end
10
10
 
11
11
  it "should be defaulting to Data from spec_helper" do
12
- QueueBus.adapter.is_a?(adapter_under_test_class).should == true
12
+ expect(QueueBus.adapter.is_a?(adapter_under_test_class)).to eq(true)
13
13
  end
14
14
  end
@@ -4,42 +4,42 @@ module QueueBus
4
4
  describe Application do
5
5
  describe ".all" do
6
6
  it "should return empty array when none" do
7
- Application.all.should == []
7
+ expect(Application.all).to eq([])
8
8
  end
9
9
  it "should return registered applications when there are some" do
10
10
  Application.new("One").subscribe(test_list(test_sub("fdksjh")))
11
11
  Application.new("Two").subscribe(test_list(test_sub("fdklhf")))
12
12
  Application.new("Three").subscribe(test_list(test_sub("fkld")))
13
13
 
14
- Application.all.collect(&:app_key).should =~ ["one", "two", "three"]
14
+ expect(Application.all.collect(&:app_key)).to match_array(["one", "two", "three"])
15
15
 
16
16
  Application.new("two").unsubscribe
17
- Application.all.collect(&:app_key).should =~ ["one", "three"]
17
+ expect(Application.all.collect(&:app_key)).to match_array(["one", "three"])
18
18
  end
19
19
  end
20
20
 
21
21
  describe ".new" do
22
22
  it "should have a key" do
23
- Application.new("something").app_key.should == "something"
23
+ expect(Application.new("something").app_key).to eq("something")
24
24
 
25
- Application.new("some thing").app_key.should == "some_thing"
26
- Application.new("some-thing").app_key.should == "some_thing"
27
- Application.new("some_thing").app_key.should == "some_thing"
28
- Application.new("Some Thing").app_key.should == "some_thing"
25
+ expect(Application.new("some thing").app_key).to eq("some_thing")
26
+ expect(Application.new("some-thing").app_key).to eq("some_thing")
27
+ expect(Application.new("some_thing").app_key).to eq("some_thing")
28
+ expect(Application.new("Some Thing").app_key).to eq("some_thing")
29
29
  end
30
30
 
31
31
  it "should raise an error if not valid" do
32
- lambda {
32
+ expect {
33
33
  Application.new("")
34
- }.should raise_error("Invalid application name")
34
+ }.to raise_error("Invalid application name")
35
35
 
36
- lambda {
36
+ expect {
37
37
  Application.new(nil)
38
- }.should raise_error("Invalid application name")
38
+ }.to raise_error("Invalid application name")
39
39
 
40
- lambda {
40
+ expect {
41
41
  Application.new("/")
42
- }.should raise_error("Invalid application name")
42
+ }.to raise_error("Invalid application name")
43
43
  end
44
44
  end
45
45
 
@@ -50,7 +50,7 @@ module QueueBus
50
50
  QueueBus.redis { |redis| redis.hset("bus_app:myapp", "old_one", "oldqueue_name") }
51
51
  app = Application.new("myapp")
52
52
  val = app.send(:read_redis_hash)
53
- val.should == {"new_one" => {"queue_name" => "x", "bus_event_type" => "event_name"}, "old_one" => "oldqueue_name"}
53
+ expect(val).to eq({"new_one" => {"queue_name" => "x", "bus_event_type" => "event_name"}, "old_one" => "oldqueue_name"})
54
54
  end
55
55
  end
56
56
 
@@ -59,45 +59,45 @@ module QueueBus
59
59
  let(:sub2) { test_sub("event_two", "default") }
60
60
  let(:sub3) { test_sub("event_three", "other") }
61
61
  it "should add array to redis" do
62
- QueueBus.redis { |redis| redis.get("bus_app:myapp") }.should be_nil
62
+ expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
63
63
  Application.new("myapp").subscribe(test_list(sub1, sub2))
64
64
 
65
- QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }.should == {"event_two"=>"{\"queue_name\":\"default\",\"key\":\"event_two\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_two\"}}",
66
- "event_one"=>"{\"queue_name\":\"default\",\"key\":\"event_one\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_one\"}}"}
67
- QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }.should =~ ["event_one", "event_two"]
68
- QueueBus.redis { |redis| redis.smembers("bus_apps") }.should =~ ["myapp"]
65
+ expect(QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }).to eq({"event_two"=>"{\"queue_name\":\"default\",\"key\":\"event_two\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_two\"}}",
66
+ "event_one"=>"{\"queue_name\":\"default\",\"key\":\"event_one\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_one\"}}"})
67
+ expect(QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }).to match_array(["event_one", "event_two"])
68
+ expect(QueueBus.redis { |redis| redis.smembers("bus_apps") }).to match_array(["myapp"])
69
69
  end
70
70
  it "should add string to redis" do
71
- QueueBus.redis { |redis| redis.get("bus_app:myapp") }.should be_nil
71
+ expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
72
72
  Application.new("myapp").subscribe(test_list(sub1))
73
73
 
74
- QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }.should == {"event_one"=>"{\"queue_name\":\"default\",\"key\":\"event_one\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_one\"}}"}
75
- QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }.should =~ ["event_one"]
76
- QueueBus.redis { |redis| redis.smembers("bus_apps") }.should =~ ["myapp"]
74
+ expect(QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }).to eq({"event_one"=>"{\"queue_name\":\"default\",\"key\":\"event_one\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_one\"}}"})
75
+ expect(QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }).to match_array(["event_one"])
76
+ expect(QueueBus.redis { |redis| redis.smembers("bus_apps") }).to match_array(["myapp"])
77
77
  end
78
78
  it "should multiple queues to redis" do
79
- QueueBus.redis { |redis| redis.get("bus_app:myapp") }.should be_nil
79
+ expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
80
80
  Application.new("myapp").subscribe(test_list(sub1, sub2, sub3))
81
- QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }.should == {"event_two"=>"{\"queue_name\":\"default\",\"key\":\"event_two\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_two\"}}", "event_one"=>"{\"queue_name\":\"default\",\"key\":\"event_one\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_one\"}}",
82
- "event_three"=>"{\"queue_name\":\"other\",\"key\":\"event_three\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_three\"}}"}
83
- QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }.should =~ ["event_three", "event_two", "event_one"]
84
- QueueBus.redis { |redis| redis.smembers("bus_apps") }.should =~ ["myapp"]
81
+ expect(QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }).to eq({"event_two"=>"{\"queue_name\":\"default\",\"key\":\"event_two\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_two\"}}", "event_one"=>"{\"queue_name\":\"default\",\"key\":\"event_one\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_one\"}}",
82
+ "event_three"=>"{\"queue_name\":\"other\",\"key\":\"event_three\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_three\"}}"})
83
+ expect(QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }).to match_array(["event_three", "event_two", "event_one"])
84
+ expect(QueueBus.redis { |redis| redis.smembers("bus_apps") }).to match_array(["myapp"])
85
85
  end
86
86
 
87
87
  it "should do nothing if nil or empty" do
88
88
 
89
- QueueBus.redis { |redis| redis.get("bus_app:myapp") }.should be_nil
89
+ expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
90
90
 
91
91
  Application.new("myapp").subscribe(nil)
92
- QueueBus.redis { |redis| redis.get("bus_app:myapp") }.should be_nil
92
+ expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
93
93
 
94
94
  Application.new("myapp").subscribe([])
95
- QueueBus.redis { |redis| redis.get("bus_app:myapp") }.should be_nil
95
+ expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
96
96
  end
97
97
 
98
98
  it "should call unsubscribe" do
99
99
  app = Application.new("myapp")
100
- app.should_receive(:unsubscribe)
100
+ expect(app).to receive(:unsubscribe)
101
101
  app.subscribe([])
102
102
  end
103
103
  end
@@ -110,42 +110,42 @@ module QueueBus
110
110
 
111
111
  Application.new("myapp").unsubscribe
112
112
 
113
- QueueBus.redis { |redis| redis.smembers("bus_apps") }.should == ["other"]
114
- QueueBus.redis { |redis| redis.get("bus_app:myapp") }.should be_nil
113
+ expect(QueueBus.redis { |redis| redis.smembers("bus_apps") }).to eq(["other"])
114
+ expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
115
115
  end
116
116
  end
117
117
 
118
118
  describe "#subscription_matches" do
119
119
  it "should return if it is there" do
120
- Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should == []
120
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
121
121
 
122
122
  subs = test_list(test_sub("one_x"), test_sub("one_y"), test_sub("one"), test_sub("two"))
123
123
  Application.new("myapp").subscribe(subs)
124
- Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should == []
124
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
125
125
 
126
- Application.new("myapp").subscription_matches("bus_event_type"=>"two").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["myapp", "two", "default", "::QueueBus::Rider"]]
127
- Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["myapp", "one", "default", "::QueueBus::Rider"]]
126
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"two").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "two", "default", "::QueueBus::Rider"]])
127
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "one", "default", "::QueueBus::Rider"]])
128
128
  end
129
129
 
130
130
  it "should handle * wildcards" do
131
131
  subs = test_list(test_sub("one.+"), test_sub("one"), test_sub("one_.*"), test_sub("two"))
132
132
  Application.new("myapp").subscribe(subs)
133
- Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should == []
133
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
134
134
 
135
- Application.new("myapp").subscription_matches("bus_event_type"=>"onex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["myapp", "one.+", "default", "::QueueBus::Rider"]]
136
- Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["myapp", "one", "default", "::QueueBus::Rider"]]
137
- Application.new("myapp").subscription_matches("bus_event_type"=>"one_x").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["myapp", "one.+","default", "::QueueBus::Rider"], ["myapp", "one_.*", "default", "::QueueBus::Rider"]]
135
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"onex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "one.+", "default", "::QueueBus::Rider"]])
136
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "one", "default", "::QueueBus::Rider"]])
137
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"one_x").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "one.+","default", "::QueueBus::Rider"], ["myapp", "one_.*", "default", "::QueueBus::Rider"]])
138
138
  end
139
139
 
140
140
  it "should handle actual regular expressions" do
141
141
  subs = test_list(test_sub(/one.+/), test_sub("one"), test_sub(/one_.*/), test_sub("two"))
142
142
  Application.new("myapp").subscribe(subs)
143
- Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should == []
143
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
144
144
 
145
- Application.new("myapp").subscription_matches("bus_event_type"=>"onex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["myapp", "(?-mix:one.+)", "default", "::QueueBus::Rider"]]
146
- Application.new("myapp").subscription_matches("bus_event_type"=>"donex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["myapp", "(?-mix:one.+)", "default", "::QueueBus::Rider"]]
147
- Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["myapp", "one" ,"default", "::QueueBus::Rider"]]
148
- Application.new("myapp").subscription_matches("bus_event_type"=>"one_x").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["myapp", "(?-mix:one.+)", "default", "::QueueBus::Rider"], ["myapp", "(?-mix:one_.*)", "default", "::QueueBus::Rider"]]
145
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"onex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "(?-mix:one.+)", "default", "::QueueBus::Rider"]])
146
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"donex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "(?-mix:one.+)", "default", "::QueueBus::Rider"]])
147
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "one" ,"default", "::QueueBus::Rider"]])
148
+ expect(Application.new("myapp").subscription_matches("bus_event_type"=>"one_x").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "(?-mix:one.+)", "default", "::QueueBus::Rider"], ["myapp", "(?-mix:one_.*)", "default", "::QueueBus::Rider"]])
149
149
  end
150
150
  end
151
151
  end
data/spec/config_spec.rb CHANGED
@@ -10,51 +10,51 @@ end
10
10
 
11
11
  describe "QueueBus config" do
12
12
  it "should set the default app key" do
13
- QueueBus.default_app_key.should == nil
13
+ expect(QueueBus.default_app_key).to eq(nil)
14
14
 
15
15
  QueueBus.default_app_key = "my_app"
16
- QueueBus.default_app_key.should == "my_app"
16
+ expect(QueueBus.default_app_key).to eq("my_app")
17
17
 
18
18
  QueueBus.default_app_key = "something here"
19
- QueueBus.default_app_key.should == "something_here"
19
+ expect(QueueBus.default_app_key).to eq("something_here")
20
20
  end
21
21
 
22
22
  it "should set the default queue" do
23
- QueueBus.default_queue.should == nil
23
+ expect(QueueBus.default_queue).to eq(nil)
24
24
 
25
25
  QueueBus.default_queue = "my_queue"
26
- QueueBus.default_queue.should == "my_queue"
26
+ expect(QueueBus.default_queue).to eq("my_queue")
27
27
  end
28
28
 
29
29
  it "should set the local mode" do
30
- QueueBus.local_mode.should == nil
30
+ expect(QueueBus.local_mode).to eq(nil)
31
31
  QueueBus.local_mode = :standalone
32
- QueueBus.local_mode.should == :standalone
32
+ expect(QueueBus.local_mode).to eq(:standalone)
33
33
  end
34
34
 
35
35
  it "should set the hostname" do
36
- QueueBus.hostname.should_not == nil
36
+ expect(QueueBus.hostname).not_to eq(nil)
37
37
  QueueBus.hostname = "whatever"
38
- QueueBus.hostname.should == "whatever"
38
+ expect(QueueBus.hostname).to eq("whatever")
39
39
  end
40
40
 
41
41
  it "should set before_publish callback" do
42
42
  QueueBus.before_publish = lambda {|attributes| 42 }
43
- QueueBus.before_publish_callback({}).should == 42
43
+ expect(QueueBus.before_publish_callback({})).to eq(42)
44
44
  end
45
45
 
46
46
 
47
47
  it "should use the default Redis connection" do
48
- QueueBus.redis { |redis| redis }.should_not eq(nil)
48
+ expect(QueueBus.redis { |redis| redis }).not_to eq(nil)
49
49
  end
50
50
 
51
51
  it "should default to given adapter" do
52
- QueueBus.adapter.is_a?(adapter_under_test_class).should == true
52
+ expect(QueueBus.adapter.is_a?(adapter_under_test_class)).to eq(true)
53
53
 
54
54
  # and should raise if already set
55
- lambda {
55
+ expect {
56
56
  QueueBus.adapter = :data
57
- }.should raise_error("Adapter already set to QueueBus::Adapters::Sidekiq")
57
+ }.to raise_error("Adapter already set to QueueBus::Adapters::Sidekiq")
58
58
  end
59
59
 
60
60
  context "with a fresh load" do
@@ -64,18 +64,18 @@ describe "QueueBus config" do
64
64
 
65
65
  it "should be able to be set to resque" do
66
66
  QueueBus.adapter = adapter_under_test_symbol
67
- QueueBus.adapter.is_a?(adapter_under_test_class).should == true
67
+ expect(QueueBus.adapter.is_a?(adapter_under_test_class)).to eq(true)
68
68
 
69
69
  # and should raise if already set
70
- lambda {
70
+ expect {
71
71
  QueueBus.adapter = :data
72
- }.should raise_error("Adapter already set to QueueBus::Adapters::Sidekiq")
72
+ }.to raise_error("Adapter already set to QueueBus::Adapters::Sidekiq")
73
73
  end
74
74
 
75
75
  it "should be able to be set to something else" do
76
76
 
77
77
  QueueBus.adapter = :test_one
78
- QueueBus.adapter.is_a?(QueueBus::Adapters::TestOne).should == true
78
+ expect(QueueBus.adapter.is_a?(QueueBus::Adapters::TestOne)).to eq(true)
79
79
  end
80
80
  end
81
81