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.
@@ -10,28 +10,28 @@ module QueueBus
10
10
 
11
11
  it "should return from attributes" do
12
12
  list = SubscriptionList.from_redis(mult)
13
- list.size.should == 2
13
+ expect(list.size).to eq(2)
14
14
  one = list.key("event_one")
15
15
  two = list.key("event_two")
16
16
 
17
- one.key.should == "event_one"
18
- one.key.should == "event_one"
19
- one.queue_name.should == "default"
20
- one.class_name.should == "MyClass"
21
- one.matcher.filters.should == {"bus_event_type" => "event_one"}
17
+ expect(one.key).to eq("event_one")
18
+ expect(one.key).to eq("event_one")
19
+ expect(one.queue_name).to eq("default")
20
+ expect(one.class_name).to eq("MyClass")
21
+ expect(one.matcher.filters).to eq({"bus_event_type" => "event_one"})
22
22
 
23
- two.key.should == "event_two"
24
- two.key.should == "event_two"
25
- two.queue_name.should == "else"
26
- two.class_name.should == "MyClass"
27
- two.matcher.filters.should == {"bus_event_type" => "event_two"}
23
+ expect(two.key).to eq("event_two")
24
+ expect(two.key).to eq("event_two")
25
+ expect(two.queue_name).to eq("else")
26
+ expect(two.class_name).to eq("MyClass")
27
+ expect(two.matcher.filters).to eq({"bus_event_type" => "event_two"})
28
28
  end
29
29
 
30
30
  it "raises an error if a subscription key already exists" do
31
31
  mult["event_two"]["key"] = "event_one"
32
32
 
33
- lambda { SubscriptionList.from_redis(mult) }
34
- .should raise_error(RuntimeError)
33
+ expect { SubscriptionList.from_redis(mult) }
34
+ .to raise_error(RuntimeError)
35
35
  end
36
36
  end
37
37
 
@@ -42,9 +42,9 @@ module QueueBus
42
42
  list.add(Subscription.new("else_ok", "key2", "MyClass", {"bus_event_type" => "event_two"}))
43
43
 
44
44
  hash = list.to_redis
45
- hash.should == { "key1" => {"queue_name" => "default", "key" => "key1", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_one"}},
45
+ expect(hash).to eq({ "key1" => {"queue_name" => "default", "key" => "key1", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_one"}},
46
46
  "key2" => {"queue_name" => "else_ok", "key" => "key2", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_two"}}
47
- }
47
+ })
48
48
 
49
49
  end
50
50
  end
@@ -3,27 +3,27 @@ require 'spec_helper'
3
3
  module QueueBus
4
4
  describe Subscription do
5
5
  it "should normalize the queue name" do
6
- Subscription.new("test", "my_event", "MyClass", {}, nil).queue_name.should == "test"
7
- Subscription.new("tes t", "my_event", "MyClass", {}, nil).queue_name.should == "tes_t"
8
- Subscription.new("t%s", "my_event", "MyClass", {}, nil).queue_name.should == "t_s"
6
+ expect(Subscription.new("test", "my_event", "MyClass", {}, nil).queue_name).to eq("test")
7
+ expect(Subscription.new("tes t", "my_event", "MyClass", {}, nil).queue_name).to eq("tes_t")
8
+ expect(Subscription.new("t%s", "my_event", "MyClass", {}, nil).queue_name).to eq("t_s")
9
9
  end
10
10
 
11
11
  describe ".register" do
12
12
  it "should take in args from dispatcher" do
13
13
  executor = Proc.new { |attributes| }
14
14
  sub = Subscription.register("queue_name", "mykey", "MyClass", {"bus_event_type" => "my_event"}, executor)
15
- sub.send(:executor).should == executor
16
- sub.matcher.filters.should == {"bus_event_type" => "my_event"}
17
- sub.queue_name.should == "queue_name"
18
- sub.key.should == "mykey"
19
- sub.class_name.should == "MyClass"
15
+ expect(sub.send(:executor)).to eq(executor)
16
+ expect(sub.matcher.filters).to eq({"bus_event_type" => "my_event"})
17
+ expect(sub.queue_name).to eq("queue_name")
18
+ expect(sub.key).to eq("mykey")
19
+ expect(sub.class_name).to eq("MyClass")
20
20
  end
21
21
  end
22
22
 
23
23
  describe "#execute!" do
24
24
  it "should call the executor with the attributes" do
25
25
  exec = Object.new
26
- exec.should_receive(:call)
26
+ expect(exec).to receive(:call)
27
27
 
28
28
  sub = Subscription.new("x", "y", "ClassName", {}, exec)
29
29
  sub.execute!({"ok" => true})
@@ -33,19 +33,19 @@ module QueueBus
33
33
  describe "#to_redis" do
34
34
  it "should return what to store for this subscription" do
35
35
  sub = Subscription.new("queue_one", "xyz", "ClassName", {"bus_event_type" => "my_event"}, nil)
36
- sub.to_redis.should == {"queue_name" => "queue_one", "key" => "xyz", "class" => "ClassName", "matcher" => {"bus_event_type" => "my_event"}}
36
+ expect(sub.to_redis).to eq({"queue_name" => "queue_one", "key" => "xyz", "class" => "ClassName", "matcher" => {"bus_event_type" => "my_event"}})
37
37
  end
38
38
  end
39
39
 
40
40
  describe "#matches?" do
41
41
  it "should do pattern stuff" do
42
- Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one"}).matches?("bus_event_type" => "one").should == true
43
- Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one"}).matches?("bus_event_type" => "onex").should == false
44
- Subscription.new("x", "id", "ClassName", {"bus_event_type" => "^one.*$"}).matches?("bus_event_type" => "onex").should == true
45
- Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.*"}).matches?("bus_event_type" => "onex").should == true
46
- Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.?"}).matches?("bus_event_type" => "onex").should == true
47
- Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.?"}).matches?("bus_event_type" => "one").should == true
48
- Subscription.new("x", "id", "ClassName", {"bus_event_type" => "\\"}).matches?("bus_event_type" => "one").should == false
42
+ expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one"}).matches?("bus_event_type" => "one")).to eq(true)
43
+ expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one"}).matches?("bus_event_type" => "onex")).to eq(false)
44
+ expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "^one.*$"}).matches?("bus_event_type" => "onex")).to eq(true)
45
+ expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.*"}).matches?("bus_event_type" => "onex")).to eq(true)
46
+ expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.?"}).matches?("bus_event_type" => "onex")).to eq(true)
47
+ expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.?"}).matches?("bus_event_type" => "one")).to eq(true)
48
+ expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "\\"}).matches?("bus_event_type" => "one")).to eq(false)
49
49
  end
50
50
  end
51
51
 
data/spec/worker_spec.rb CHANGED
@@ -1,32 +1,37 @@
1
1
  require 'spec_helper'
2
+ require 'json'
2
3
 
3
- module QueueBus
4
- describe Worker do
5
- it "should proxy to given class" do
6
- hash = {"bus_class_proxy" => "QueueBus::Driver", "ok" => true}
7
- QueueBus::Driver.should_receive(:perform).with(hash)
8
- QueueBus::Worker.perform(JSON.generate(hash))
9
- end
4
+ describe QueueBus::Worker do
5
+ it "proxies to given class" do
6
+ hash = {"bus_class_proxy" => "QueueBus::Driver", "ok" => true}
7
+ expect(QueueBus::Driver).to receive(:perform).with(hash)
8
+ QueueBus::Worker.perform(JSON.generate(hash))
9
+ end
10
+
11
+ it "uses an instance" do
12
+ hash = {"bus_class_proxy" => "QueueBus::Rider", "ok" => true}
13
+ expect(QueueBus::Rider).to receive(:perform).with(hash)
14
+ QueueBus::Worker.new.perform(JSON.generate(hash))
15
+ end
10
16
 
11
- it "should use instance" do
12
- hash = {"bus_class_proxy" => "QueueBus::Rider", "ok" => true}
13
- QueueBus::Rider.should_receive(:perform).with(hash)
14
- QueueBus::Worker.new.perform(JSON.generate(hash))
15
- end
17
+ it "does not freak out if class not there anymore" do
18
+ hash = {"bus_class_proxy" => "QueueBus::BadClass", "ok" => true}
19
+ expect {
20
+ QueueBus::Worker.perform(JSON.generate(hash))
21
+ }.not_to raise_error
22
+ end
16
23
 
17
- it "should not freak out if class not there anymore" do
18
- hash = {"bus_class_proxy" => "QueueBus::BadClass", "ok" => true}
19
- lambda {
20
- QueueBus::Worker.perform(JSON.generate(hash))
21
- }.should_not raise_error
22
- end
24
+ it "raises error if proxy raises error" do
25
+ hash = {"bus_class_proxy" => "QueueBus::Rider", "ok" => true}
26
+ expect(QueueBus::Rider).to receive(:perform).with(hash).and_raise("rider crash")
27
+ expect {
28
+ QueueBus::Worker.perform(JSON.generate(hash))
29
+ }.to raise_error(RuntimeError, 'rider crash')
30
+ end
23
31
 
24
- it "should raise error if proxy raises error" do
25
- hash = {"bus_class_proxy" => "QueueBus::Rider", "ok" => true}
26
- QueueBus::Rider.should_receive(:perform).with(hash).and_raise("rider crash")
27
- lambda {
28
- QueueBus::Worker.perform(JSON.generate(hash))
29
- }.should raise_error
30
- end
32
+ it "runs the middleware stack" do
33
+ hash = {"bus_class_proxy" => "QueueBus::Driver", "ok" => true}
34
+ expect(QueueBus.worker_middleware_stack).to receive(:run).with(hash).and_yield
35
+ QueueBus::Worker.perform(JSON.generate(hash))
31
36
  end
32
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queue-bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Leonard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-17 00:00:00.000000000 Z
11
+ date: 2019-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -92,6 +92,7 @@ files:
92
92
  - ".rbenv-version"
93
93
  - ".rspec"
94
94
  - ".rvmrc"
95
+ - CHANGELOG.md
95
96
  - Gemfile
96
97
  - MIT-LICENSE
97
98
  - README.mdown
@@ -107,6 +108,7 @@ files:
107
108
  - lib/queue_bus/heartbeat.rb
108
109
  - lib/queue_bus/local.rb
109
110
  - lib/queue_bus/matcher.rb
111
+ - lib/queue_bus/middleware.rb
110
112
  - lib/queue_bus/publisher.rb
111
113
  - lib/queue_bus/publishing.rb
112
114
  - lib/queue_bus/rider.rb
@@ -129,6 +131,7 @@ files:
129
131
  - spec/heartbeat_spec.rb
130
132
  - spec/integration_spec.rb
131
133
  - spec/matcher_spec.rb
134
+ - spec/middleware_spec.rb
132
135
  - spec/publish_spec.rb
133
136
  - spec/publisher_spec.rb
134
137
  - spec/rider_spec.rb
@@ -156,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
159
  version: '0'
157
160
  requirements: []
158
161
  rubyforge_project: queue-bus
159
- rubygems_version: 2.5.2
162
+ rubygems_version: 2.7.6
160
163
  signing_key:
161
164
  specification_version: 4
162
165
  summary: A simple event bus on top of background queues
@@ -171,6 +174,7 @@ test_files:
171
174
  - spec/heartbeat_spec.rb
172
175
  - spec/integration_spec.rb
173
176
  - spec/matcher_spec.rb
177
+ - spec/middleware_spec.rb
174
178
  - spec/publish_spec.rb
175
179
  - spec/publisher_spec.rb
176
180
  - spec/rider_spec.rb