queue-bus 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e1b4c0ca9bf660b79b88769d6ba7e4d2d89e28f5
4
- data.tar.gz: 2840967bb05b953171b300d28538d6b362332e6d
2
+ SHA256:
3
+ metadata.gz: f18ed6e21b956ce928e0c3ede7e1493eb7806413706e92e1f4c991667e9e06b8
4
+ data.tar.gz: 4043918b7705741e3719d6460b9823367b9e271e6344193c2b616aab063a4d9a
5
5
  SHA512:
6
- metadata.gz: 90dded1ee751e8d7773fbc183a8c8a0c430ec7dac927090fae6c775c05605c007b11e9a0595b0670f83becd6f5100b012d63ec77b34180d3ce9c802c995ca48e
7
- data.tar.gz: 9ddb1c632db8dcd4ca2d298fe50b219485cc408c264eef073d17b0f61fe447c4de04aad9cece3c01f3952f8cd5e931626a0f5aedbd3a8e7380111775095ac938
6
+ metadata.gz: 6894d383941edf09df6d245eaffc57ecd2ef3185bb3196d89a29c7714cc7b3f849639e285764ee57832158a566538bc2c1b8b6691af2d73ab5a3760d8893ef5e
7
+ data.tar.gz: 9b08d34ff3309f039640a1c154b5f33cfc186f69f18511a09201e4eeb5553ef8f5b8ad053405fc6f9bf3658d5750543d7fa92d431d88ba72af5c3ab8f0d50e45
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.6.0]
10
+
11
+ ### Added
12
+ - New middleware implementation that allows middleware to wrap the execution of work from the `QueueBus::Worker`
13
+ - Changelog!
14
+
15
+ ### Changed
16
+ - Specs are now using the `expect` syntax instead of `should`. This more closely aligns with the rspec recommendations.
data/lib/queue-bus.rb CHANGED
@@ -11,6 +11,7 @@ module QueueBus
11
11
  autoload :Heartbeat, 'queue_bus/heartbeat'
12
12
  autoload :Local, 'queue_bus/local'
13
13
  autoload :Matcher, 'queue_bus/matcher'
14
+ autoload :Middleware, 'queue_bus/middleware'
14
15
  autoload :Publishing, 'queue_bus/publishing'
15
16
  autoload :Publisher, 'queue_bus/publisher'
16
17
  autoload :Rider, 'queue_bus/rider'
@@ -39,7 +40,7 @@ module QueueBus
39
40
  :hostname=, :hostname,
40
41
  :adapter=, :adapter,
41
42
  :incoming_queue=, :incoming_queue,
42
- :redis
43
+ :redis, :worker_middleware_stack
43
44
 
44
45
  def_delegators :_dispatchers, :dispatch, :dispatchers, :dispatcher_by_key, :dispatcher_execute
45
46
 
@@ -55,6 +55,10 @@ module QueueBus
55
55
  @incoming_queue ||= "bus_incoming"
56
56
  end
57
57
 
58
+ def worker_middleware_stack
59
+ @worker_middleware_stack ||= QueueBus::Middleware::Stack.new
60
+ end
61
+
58
62
  def hostname
59
63
  @hostname ||= `hostname 2>&1`.strip.sub(/.local/,'')
60
64
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QueueBus
4
+ module Middleware
5
+ # A base class for implementing a middleware. Inheriting from this will
6
+ # provide a constructor and a basic call method. Override the call method
7
+ # to implement your own logic. Calling the instance variable `@app` will
8
+ # drive the middleware stack.
9
+ class Abstract
10
+ def initialize(app)
11
+ @app = app
12
+ end
13
+
14
+ def call(_args)
15
+ @app.call
16
+ end
17
+ end
18
+
19
+ # A stack of middleware. You can modify the stack using the provided
20
+ # helper methods.
21
+ class Stack
22
+ def initialize
23
+ @middlewares = []
24
+ end
25
+
26
+ def use(middleware)
27
+ @middlewares << middleware
28
+ end
29
+
30
+ def run(args, &inner)
31
+ Runner.new(args: args, stack: @middlewares.dup, inner: inner).call
32
+ end
33
+ end
34
+
35
+ # Runs the middleware stack by passing it self to each class.
36
+ class Runner
37
+ def initialize(args:, stack:, inner:)
38
+ @stack = stack
39
+ @inner = inner
40
+ @args = args
41
+ end
42
+
43
+ def call
44
+ middleware = @stack.shift
45
+
46
+ if middleware
47
+ middleware.new(self).call(@args)
48
+ else
49
+ @inner.call
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module QueueBus
2
- VERSION = "0.5.9"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -12,7 +12,9 @@ module QueueBus
12
12
  return
13
13
  end
14
14
 
15
- klass.perform(attributes)
15
+ QueueBus.worker_middleware_stack.run(attributes) do
16
+ klass.perform(attributes)
17
+ end
16
18
  end
17
19
 
18
20
  # all our workers include this one
@@ -4,7 +4,7 @@ describe "Publishing an event in the future" do
4
4
 
5
5
  before(:each) do
6
6
  Timecop.freeze(now)
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
@@ -25,27 +25,27 @@ describe "Publishing an event in the future" do
25
25
  QueueBus.publish_at(future, event_name, hash)
26
26
 
27
27
  schedule = QueueBus.redis { |redis| redis.zrange("delayed_queue_schedule", 0, 1) }
28
- schedule.should == [future.to_i.to_s]
28
+ expect(schedule).to eq([future.to_i.to_s])
29
29
 
30
30
  val = QueueBus.redis { |redis| redis.lpop("delayed:#{future.to_i}") }
31
31
  hash = JSON.parse(val)
32
32
 
33
- hash["class"].should == "QueueBus::Worker"
34
- hash["args"].size.should == 1
35
- 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)
36
- hash["queue"].should == "bus_incoming"
33
+ expect(hash["class"]).to eq("QueueBus::Worker")
34
+ expect(hash["args"].size).to eq(1)
35
+ 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))
36
+ expect(hash["queue"]).to eq("bus_incoming")
37
37
 
38
38
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
39
- val.should == nil # nothing really added
39
+ expect(val).to eq(nil) # nothing really added
40
40
 
41
41
  Timecop.freeze(worktime)
42
42
  QueueBus::Publisher.perform(JSON.parse(hash["args"].first))
43
43
 
44
44
  val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
45
45
  hash = JSON.parse(val)
46
- hash["class"].should == "QueueBus::Worker"
47
- hash["args"].size.should == 1
48
- 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)
46
+ expect(hash["class"]).to eq("QueueBus::Worker")
47
+ expect(hash["args"].size).to eq(1)
48
+ 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))
49
49
  end
50
50
 
51
51
  end
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
34
+ }.to raise_error(RuntimeError, "Invalid application name")
35
35
 
36
- lambda {
36
+ expect {
37
37
  Application.new(nil)
38
- }.should raise_error
38
+ }.to raise_error(RuntimeError, "Invalid application name")
39
39
 
40
- lambda {
40
+ expect {
41
41
  Application.new("/")
42
- }.should raise_error
42
+ }.to raise_error(RuntimeError, "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
57
+ }.to raise_error(RuntimeError, "Adapter already set to QueueBus::Adapters::Data")
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
72
+ }.to raise_error(RuntimeError, "Adapter already set to QueueBus::Adapters::Data")
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