larrytheliquid-moqueue 0.1.2

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,102 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe MockExchange do
4
+
5
+ before(:each) do
6
+ reset_broker
7
+ @queue, @exchange = mock_queue_and_exchange
8
+ end
9
+
10
+ it "should manually attach queues" do
11
+ ensure_deferred_block_called(:times => 2)
12
+ exchange = mock_exchange
13
+ one_queue, another_queue = mock_queue("one"), mock_queue("two")
14
+ exchange.attach_queue(one_queue)
15
+ exchange.attach_queue(another_queue)
16
+ one_queue.subscribe do |msg|
17
+ deferred_block_called && msg.should == "mmm, smoothies"
18
+ end
19
+ another_queue.subscribe do |msg|
20
+ deferred_block_called && msg.should == "mmm, smoothies"
21
+ end
22
+ exchange.publish("mmm, smoothies")
23
+ end
24
+
25
+ it "should accept options for the publish method" do
26
+ lambda {@exchange.publish("whateva eva", :key=>"foo.bar")}.should_not raise_error(ArgumentError)
27
+ end
28
+
29
+ it "should emulate topic exchanges" do
30
+ #pending "support for storing and retrieving topic exchanges in MockBroker"
31
+ topic_exchange = MockExchange.new(:topic => "lolcats")
32
+ topic_exchange.topic.should == "lolcats"
33
+ end
34
+
35
+ it "should register new topic exchanges with the mock broker" do
36
+ MockBroker.instance.expects(:register_topic_exchange)
37
+ MockExchange.new(:topic => "lolz")
38
+ end
39
+
40
+ it "should return a previously created topic exchange when asked to create a new one with the same topic" do
41
+ exchange = MockExchange.new(:topic => "fails")
42
+ MockExchange.new(:topic => "fails").should equal exchange
43
+ end
44
+
45
+ it "should determine if routing keys match" do
46
+ exchange = MockExchange.new(:topic => "lolz")
47
+ key = MockExchange::BindingKey
48
+ key.new("cats").matches?("cats").should be_true
49
+ key.new("cats").matches?("cats").should be_true
50
+ key.new("cats").matches?("dogs").should be_false
51
+ key.new("cats.*").matches?("cats.fridge").should be_true
52
+ key.new("cats.evil").matches?("cats.fridge").should be_false
53
+ key.new("cats.*").matches?("cats.fridge.in_urs").should be_false
54
+ key.new("cats.#").matches?("cats.fridge.in_urs").should be_true
55
+ end
56
+
57
+ it "should forward messages to a queue only if the keys match when emulating a topic exchange" do
58
+ ensure_deferred_block_called
59
+ exchange = MockExchange.new(:topic => "lolz")
60
+ queue = MockQueue.new("lolz-lover")
61
+ queue.bind(exchange, :key=>"cats.*").subscribe do |msg|
62
+ msg.should == "ohai"
63
+ deferred_block_called
64
+ end
65
+ exchange.publish("ohai", :key => "cats.attack")
66
+ end
67
+
68
+ it "should add the routing key to the headers' properties when publishing as a topic exchange" do
69
+ ensure_deferred_block_called
70
+ exchange = MockExchange.new(:topic => "mehDogs")
71
+ queue = MockQueue.new("dogzLover").bind(exchange, :key=>"boxers.*")
72
+ queue.subscribe do |headers, msg|
73
+ deferred_block_called
74
+ headers.routing_key.should == "boxers.awesome"
75
+ msg.should == "Roxie"
76
+ end
77
+ exchange.publish("Roxie", :key=>"boxers.awesome")
78
+ end
79
+
80
+ it "should raise an error when publishing to a topic exchange without specifying a key" do
81
+ exchange = MockExchange.new(:topic=>"failz")
82
+ fail_msg = "you must provide a key when publishing to a topic exchange"
83
+ lambda {exchange.publish("failtacular")}.should raise_error(ArgumentError, fail_msg)
84
+ end
85
+
86
+ it "should allow the fanout exchange name to be queried" do
87
+ exchange = MockExchange.new(:fanout => "hiMyNameIs")
88
+ exchange.fanout.should == "hiMyNameIs"
89
+ end
90
+
91
+ it "should register new fanout exchanges with the MockBroker" do
92
+ MockBroker.instance.expects(:register_fanout_exchange)
93
+ MockExchange.new(:fanout => "nanite friendly")
94
+ end
95
+
96
+ it "should return the exact same fanout exchange if creating one with an identical name" do
97
+ the_first_fanout = MockExchange.new(:fanout => "pseudo singleton")
98
+ the_second_one = MockExchange.new(:fanout => "pseudo singleton")
99
+ the_first_fanout.should equal the_second_one
100
+ end
101
+
102
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe MockHeaders do
4
+
5
+ it "should respond to the same methods as real AMQP::Protocol::Header" do
6
+ headers = Moqueue::MockHeaders.new
7
+ headers.should respond_to(:size)
8
+ headers.should respond_to(:weight)
9
+ headers.should respond_to(:properties)
10
+ headers.should respond_to(:to_frame)
11
+ end
12
+
13
+ it "should add properties given to constructor" do
14
+ headers = MockHeaders.new({:routing_key=>"lolz.cats.inKitchen"})
15
+ end
16
+
17
+ it "should lookup unknown methods as keys in the hash" do
18
+ headers = MockHeaders.new(:wtf_ftw_lolz_yo => "did I really write that?")
19
+ headers.wtf_ftw_lolz_yo.should == "did I really write that?"
20
+ end
21
+
22
+ end
@@ -0,0 +1,141 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe MockQueue do
4
+
5
+ before(:each) do
6
+ reset_broker
7
+ @queue, @exchange = mock_queue_and_exchange
8
+ end
9
+
10
+ it "should accept options for :ack=>(true|false) :nowait=>(true|false)" do
11
+ lambda {@queue.subscribe(:ack=>true) { |message| p message}}.should_not raise_error(ArgumentError)
12
+ end
13
+
14
+ it "should pass mock headers to block when subscribe is given a block w/ 2 arity" do
15
+ ensure_deferred_block_called
16
+ @queue.subscribe do |headers, msg|
17
+ headers.should be_kind_of(Moqueue::MockHeaders)
18
+ msg.should == "the message"
19
+ deferred_block_called
20
+ end
21
+ @exchange.publish("the message")
22
+ end
23
+
24
+ it "should create mock headers if pop is given a block w/ 2 arity" do
25
+ pending
26
+ end
27
+
28
+ it "should process pending messages after a handler block is defined" do
29
+ ensure_deferred_block_called
30
+ @exchange.publish("found!")
31
+ @queue.subscribe { |msg| deferred_block_called && msg.should == "found!" }
32
+ end
33
+
34
+ it "should not process pending messages twice" do
35
+ ensure_deferred_block_called(:times=>2)
36
+ @exchange.publish("take out the garbage")
37
+ @queue.subscribe do |msg|
38
+ deferred_block_called
39
+ msg.should match(/take out (.*) garbage/)
40
+ end
41
+ @exchange.publish("take out more garbage")
42
+ end
43
+
44
+ it "should not ack messages when given or defaulting to :ack=>false" do
45
+ ensure_deferred_block_called
46
+ @queue.subscribe { |msg| deferred_block_called && msg.should == "hew-row" }
47
+ @exchange.publish("hew-row")
48
+ @exchange.received_ack_for_message?("hew-row").should_not be_true
49
+ end
50
+
51
+ it "should not ack messages when given :ack => true, but headers don't receive #ack" do
52
+ ensure_deferred_block_called
53
+ @queue.subscribe(:ack=>true) do |headers, msg|
54
+ deferred_block_called
55
+ msg.should == "10-4"
56
+ end
57
+ @exchange.publish("10-4")
58
+ @exchange.received_ack_for_message?("10-4").should be_false
59
+ end
60
+
61
+ it "should ack messages when subscribe is given :ack=>true and headers are acked" do
62
+ @queue.subscribe(:ack=>true) do |headers, msg|
63
+ msg.should == "10-4"
64
+ headers.ack
65
+ end
66
+ @exchange.publish("10-4")
67
+ @exchange.received_ack_for_message?("10-4").should be_true
68
+ end
69
+
70
+ it "should provide ability to check for acks when direct exchange is used" do
71
+ queue = MockQueue.new("direct-ack-check")
72
+ queue.subscribe(:ack => true) do |headers, msg|
73
+ msg.should == "ack me"
74
+ headers.ack
75
+ end
76
+ queue.publish("ack me")
77
+ queue.received_ack_for_message?("ack me").should be_true
78
+ end
79
+
80
+ it "should store received messages in the queues" do
81
+ @queue.subscribe { |msg| msg.should == "save me!" }
82
+ @exchange.publish("save me!")
83
+ @queue.received_message?("save me!").should be_true
84
+ end
85
+
86
+ it "should #unsubscribe" do
87
+ pending ("should really remove the association with exchange")
88
+ @queue.should respond_to(:unsubscribe)
89
+ end
90
+
91
+ it "should raise an error on double subscribe" do
92
+ @queue.subscribe { |msg| "once" }
93
+ second_subscribe = lambda { @queue.subscribe {|msg| "twice"} }
94
+ second_subscribe.should raise_error DoubleSubscribeError
95
+ end
96
+
97
+ it "should emulate direct exchange publishing" do
98
+ ensure_deferred_block_called
99
+ @queue.subscribe { |msg|deferred_block_called && msg.should == "Dyrekt" }
100
+ @queue.publish("Dyrekt")
101
+ end
102
+
103
+ it "should take an optional name argument" do
104
+ lambda { MockQueue.new("say-my-name") }.should_not raise_error
105
+ end
106
+
107
+ it "should register itself with the mock broker if given a name" do
108
+ MockBroker.instance.expects(:register_queue)
109
+ queue = MockQueue.new("with-a-name")
110
+ end
111
+
112
+ it "should return the previously created queue when trying to create a queue with the same name" do
113
+ queue = MockQueue.new("firsties")
114
+ MockQueue.new("firsties").should equal(queue)
115
+ end
116
+
117
+ it "should support binding to a topic exchange" do
118
+ queue = MockQueue.new("lolz lover")
119
+ topic_exchange = MockExchange.new(:topic => "lolcats")
120
+ topic_exchange.expects(:attach_queue).with(queue, :key=>"lolcats.fridges")
121
+ queue.bind(topic_exchange, :key => "lolcats.fridges") #http://lolcatz.net/784/im-in-ur-fridge-eatin-ur-foodz/
122
+ end
123
+
124
+ it "should make the callback (#subscribe block) available for direct use" do
125
+ queue = MockQueue.new("inspect my guts, plz")
126
+ queue.subscribe { |msg| msg + "yo" }
127
+ queue.run_callback("hey-").should == "hey-yo"
128
+ end
129
+
130
+ it "should bind to a fanout exchange" do
131
+ queue = MockQueue.new("fanouts are cool, too")
132
+ lambda {queue.bind(MockExchange.new)}.should_not raise_error
133
+ end
134
+
135
+ it "should provide a null subscribe that does nothing but allows messages to be received" do
136
+ queue = MockQueue.new("nilly").null_subscribe
137
+ queue.publish("I'm feelin this")
138
+ queue.received_message?("I'm feelin this").should be_true
139
+ end
140
+
141
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Moqueue do
4
+
5
+ it "should have mocha-like #expects_message('message content') expectations" do
6
+ pending("after refactoring: I'm ugly on the inside. like Hollywood")
7
+ end
8
+
9
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe ObjectMethods do
4
+
5
+ before(:each) do
6
+ reset_broker
7
+ @queue, @exchange = mock_queue_and_exchange
8
+ end
9
+
10
+ it "should reset the MockBroker" do
11
+ MockBroker.instance.expects(:reset!)
12
+ reset_broker
13
+ end
14
+
15
+ it "should name the queue ``anonymous-RANDOM_GARBAGE'' if not given a name" do
16
+ @queue.name.should match /anonymous\-[0-9a-f]{0,8}/
17
+ end
18
+
19
+ it "should name the queue with the name given" do
20
+ q, exchange = mock_queue_and_exchange("wassup")
21
+ q.name.should == "wassup"
22
+ q2 = mock_queue("watup")
23
+ q2.name.should == "watup"
24
+ end
25
+
26
+ it "should create a matched mock queue and mock exchange" do
27
+ ensure_deferred_block_called
28
+ @queue.subscribe do |message|
29
+ deferred_block_called
30
+ message.should == "FTW"
31
+ end
32
+ @exchange.publish("FTW")
33
+ end
34
+
35
+ it "should allow for overloading AMQP and MQ" do
36
+ overload_amqp
37
+ defined?(AMQP).should be_true
38
+ defined?(MQ).should be_true
39
+ end
40
+
41
+ it "should provide a convenience method for creating mock queues" do
42
+ mock_queue("Sugary").should be_kind_of(Moqueue::MockQueue)
43
+ end
44
+
45
+ it "should provide a convenience method for creating mock exchanges" do
46
+ mock_exchange(:topic => "sweetSugar").should be_kind_of(Moqueue::MockExchange)
47
+ end
48
+
49
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "AMQP and MQ", "when overloaded by moqueue/overloads" do
4
+
5
+ before(:all) do
6
+ overload_amqp
7
+ end
8
+
9
+ it "should make AMQP.start take options and a block without connecting to AMQP broker" do
10
+ ensure_deferred_block_called
11
+ AMQP.start(:host => "localhost") do
12
+ deferred_block_called
13
+ EM.stop
14
+ end
15
+ end
16
+
17
+ it "should run EM in AMQP.start" do
18
+ EM.expects(:run)
19
+ AMQP.start { EM.stop }
20
+ end
21
+
22
+ it "should provide a MQ.queue class method" do
23
+ MQ.queue('FTW').should be_a(Moqueue::MockQueue)
24
+ end
25
+
26
+ it "should emulate the behavior of MQ.closing?" do
27
+ ensure_deferred_block_called
28
+ AMQP.stop do
29
+ deferred_block_called
30
+ AMQP.should be_closing
31
+ end
32
+ end
33
+
34
+ it "should create topic exchanges" do
35
+ MQ.new.topic("lolzFTW").should == MockExchange.new(:topic => "lolzFTW")
36
+ end
37
+
38
+ it "should provide a MQ.fanout class method" do
39
+ MQ.fanout("fanout", :durable=>true).should be_a Moqueue::MockExchange
40
+ end
41
+
42
+ it "should create a named fanout queue via MQ.fanout" do
43
+ fanout = MQ.fanout("SayMyNameSayMyName", :durable=>true)
44
+ fanout.should be_a Moqueue::MockExchange
45
+ fanout.fanout.should == "SayMyNameSayMyName"
46
+ end
47
+
48
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: larrytheliquid-moqueue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Daniel DeLeo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Mocktacular Companion to AMQP Library. Happy TATFTing!
17
+ email: dan@kallistec.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - lib
26
+ - moqueue.gemspec
27
+ - Rakefile
28
+ - README.rdoc
29
+ - spec
30
+ - VERSION.yml
31
+ - lib/moqueue
32
+ - lib/moqueue/fibers18.rb
33
+ - lib/moqueue/matchers.rb
34
+ - lib/moqueue/mock_broker.rb
35
+ - lib/moqueue/mock_exchange.rb
36
+ - lib/moqueue/mock_headers.rb
37
+ - lib/moqueue/mock_queue.rb
38
+ - lib/moqueue/object_methods.rb
39
+ - lib/moqueue/overloads.rb
40
+ - lib/moqueue.rb
41
+ - spec/examples
42
+ - spec/examples/ack_spec.rb
43
+ - spec/examples/basic_usage_spec.rb
44
+ - spec/examples/example_helper.rb
45
+ - spec/examples/logger_spec.rb
46
+ - spec/examples/ping_pong_spec.rb
47
+ - spec/examples/stocks_spec.rb
48
+ - spec/spec.opts
49
+ - spec/spec_helper.rb
50
+ - spec/unit
51
+ - spec/unit/matchers_spec.rb
52
+ - spec/unit/mock_broker_spec.rb
53
+ - spec/unit/mock_exchange_spec.rb
54
+ - spec/unit/mock_headers_spec.rb
55
+ - spec/unit/mock_queue_spec.rb
56
+ - spec/unit/moqueue_spec.rb
57
+ - spec/unit/object_methods_spec.rb
58
+ - spec/unit/overloads_spec.rb
59
+ has_rdoc: false
60
+ homepage: http://github.com/danielsdeleo/moqueue
61
+ licenses:
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --inline-source
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Mocktacular Companion to AMQP Library. Happy TATFTing!
87
+ test_files: []
88
+