nebulous_stomp 1.1.5

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,146 @@
1
+ require 'spec_helper'
2
+ require 'nebulous/param'
3
+
4
+ include Nebulous
5
+
6
+
7
+ describe Param do
8
+
9
+ before { Param.reset }
10
+ after(:all) { Param.reset }
11
+
12
+
13
+ describe "Param.set" do
14
+
15
+ it "resets the param string" do
16
+ Param.set
17
+ expect( Param.get_all).to eq(Param::ParamDefaults)
18
+ end
19
+
20
+ it "rejects any weird parameters passed to it" do
21
+ expect { Param.set({:notARealParameter => 1}) }.to \
22
+ raise_exception NebulousError
23
+
24
+ end
25
+
26
+ it "adds legitimate parameters to the param hash" do
27
+ Param.set( redisConnectHash: {boo: 1} )
28
+
29
+ expect( Param.get_all[:redisConnectHash] ).to eq( {boo: 1} )
30
+ end
31
+
32
+ end # of Param::set
33
+ ##
34
+
35
+
36
+ describe "Param.add_target" do
37
+
38
+ let(:hash1) { {receiveQueue: '/queue/foo', sendQueue: '/queue/bar'} }
39
+
40
+ it "rejects unkown values in the param string for the target" do
41
+ expect { Param.add_target(:foo, {:notAValidThing => 14}) }.to \
42
+ raise_exception NebulousError
43
+
44
+ end
45
+
46
+ it "expects both a send queue and a receive queue" do
47
+ h = {receiveQueue: '/queue/foo'}
48
+ expect{ Param.add_target(:foo, h) }.to raise_exception(NebulousError)
49
+
50
+ h = {sendQueue: '/queue/foo'}
51
+ expect{ Param.add_target(:foo, h) }.to raise_exception(NebulousError)
52
+ end
53
+
54
+ it 'works even when set has not been called' do
55
+ Param.reset
56
+ expect{ Param.add_target(:foo, hash1) }.not_to raise_exception
57
+ end
58
+
59
+ it "adds legitimate parameters to the target hash" do
60
+ Param.add_target(:foo, hash1)
61
+ expect( Param.get_all[:targets][:foo] ).to include(hash1)
62
+ end
63
+
64
+ end # of Param:add_target
65
+ ##
66
+
67
+
68
+ describe "Param.get" do
69
+
70
+ let(:hash1) { { stompConnectHash: {one: 1, two: 2},
71
+ redisConnectHash: {three: 4, five: 6},
72
+ messageTimeout: 7,
73
+ cacheTimeout: 888 } }
74
+
75
+ it "returns the given hash value" do
76
+ Param.set(hash1)
77
+ expect( Param.get(:redisConnectHash) ).to eq(hash1[:redisConnectHash])
78
+ expect( Param.get(:messageTimeout) ).to eq(7)
79
+ end
80
+
81
+ it 'does not freak out if set() was never called' do
82
+ expect{ Param.get(:foo) }.not_to raise_exception
83
+ end
84
+
85
+ end # of param::get
86
+ ##
87
+
88
+
89
+ describe "Param.get_target" do
90
+
91
+ before do
92
+ @targ = {receiveQueue: 'foo', sendQueue: 'bar'}
93
+ Param.add_target(:one, @targ)
94
+ end
95
+
96
+ it "throws an exception if you ask for a target it doesn't have" do
97
+ expect{ Param.get_target(:two) }.to raise_exception(NebulousError)
98
+ end
99
+
100
+ it "returns the target hash corresponding to the name" do
101
+ expect( Param.get_target(:one) ).to include(@targ)
102
+ end
103
+
104
+ it 'does not freak out if set() was never called' do
105
+ Param.reset
106
+ expect{ Param.get_target(:one) }.not_to raise_exception
107
+ end
108
+
109
+ end # of get_target
110
+ ##
111
+
112
+
113
+ describe "Param.get_logger" do
114
+
115
+ it "returns the logger instance" do
116
+ l = Logger.new(STDOUT)
117
+ Param.set_logger(l)
118
+
119
+ expect( Param.get_logger ).to eq l
120
+ end
121
+
122
+ it 'does not freak out if set_logger() was never called' do
123
+ Param.reset
124
+ expect{ Param.get_logger }.not_to raise_exception
125
+ end
126
+
127
+ end
128
+ ##
129
+
130
+
131
+ describe "Param.set_logger" do
132
+
133
+ it "requires an instance of Logger, or nil" do
134
+ expect{ Nebulous.set_logger(:foo) }.to raise_exception NebulousError
135
+
136
+ expect{ Nebulous.set_logger(nil) }.not_to raise_exception
137
+ expect{ Nebulous.set_logger( Logger.new(STDOUT) ) }.not_to raise_exception
138
+ end
139
+
140
+ end
141
+ ##
142
+
143
+
144
+ end
145
+
146
+
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ require 'pry'
4
+
5
+ require 'nebulous/redis_handler_null'
6
+
7
+ include Nebulous
8
+
9
+
10
+ describe RedisHandlerNull do
11
+
12
+ let(:redis_hash) do
13
+ { "connect" => {"host" => '127.0.0.1', "port" => 6379, "db" => 0} }
14
+ end
15
+
16
+ let(:handler) { RedisHandlerNull.new(redis_hash) }
17
+
18
+
19
+ describe '#connect' do
20
+
21
+ it 'returns self' do
22
+ expect( handler.connect ).to eq handler
23
+ end
24
+
25
+ end
26
+ ##
27
+
28
+
29
+ describe '#insert_fake' do
30
+
31
+ it 'sets the key/value to return' do
32
+ handler.insert_fake('one', 'two')
33
+ expect( handler.fake_pair ).to eq({"one" => "two"})
34
+ end
35
+
36
+ end
37
+ ##
38
+
39
+
40
+ describe '#connected?' do
41
+
42
+ it 'returns false if we didnt call run insert_fake' do
43
+ expect( handler.connected? ).to be_falsey
44
+ end
45
+
46
+ it 'returns true if we did call insert_fake' do
47
+ handler.insert_fake('one', 'two')
48
+ expect( handler.connected? ).to be_truthy
49
+ end
50
+
51
+ end
52
+ ##
53
+
54
+
55
+ describe '#set#' do
56
+
57
+ it 'supports a key, value, option parameter like the real thing' do
58
+ expect{ handler.set('foo', 'bar', {baz: 1}) }.not_to raise_exception
59
+ end
60
+
61
+ it 'acts like insert_fake' do
62
+ handler.set('alice', 'tom')
63
+ expect( handler.fake_pair ).to eq({'alice' => 'tom'})
64
+ end
65
+
66
+ end
67
+ ##
68
+
69
+
70
+ describe '#get#' do
71
+
72
+ it 'retreives the fake message regardless' do
73
+ handler.insert_fake('grr', 'arg')
74
+ expect( handler.get('woo') ).to eq 'arg'
75
+ end
76
+
77
+ it "returns nil if the fake message is not set" do
78
+ expect( handler.get('foo') ).to be_nil
79
+ end
80
+
81
+ end
82
+ ##
83
+
84
+
85
+ describe '#del#' do
86
+
87
+ it 'resets the fake message' do
88
+ handler.insert_fake('grr', 'arg')
89
+ handler.del('woo')
90
+ expect( handler.fake_pair ).to eq({})
91
+ end
92
+
93
+ end
94
+ ##
95
+
96
+ end
97
+
@@ -0,0 +1,141 @@
1
+ require 'spec_helper'
2
+
3
+ require 'pry'
4
+
5
+ require 'nebulous/redis_handler'
6
+
7
+ include Nebulous
8
+
9
+
10
+ describe RedisHandler do
11
+
12
+ let(:redis_hash) do
13
+ { "connect" => {"host" => '127.0.0.1', "port" => 6379, "db" => 0} }
14
+ end
15
+
16
+ let(:rclient) { double('Redis Client').as_null_object }
17
+
18
+ let(:redis) do
19
+ # Again, mocking all this is fragile, but I don't know of another way to
20
+ # test the class except assuming that Redis is up, which is worse. And at
21
+ # least we are only doing this in the test for this special handler class.
22
+ r = double(Redis).as_null_object
23
+ allow(r).to receive(:client).and_return(rclient)
24
+
25
+ r
26
+ end
27
+
28
+ let(:handler) { RedisHandler.new(redis_hash, redis) }
29
+
30
+
31
+ describe '#connect' do
32
+
33
+ it '...connects...' do
34
+ expect(rclient).to receive(:connect)
35
+ handler.connect
36
+
37
+ expect(handler.redis).not_to be_nil
38
+ end
39
+
40
+ it 'raises ConnectionError if not then connected' do
41
+ expect(redis).to receive(:connected?).and_return(false)
42
+
43
+ expect{ handler.connect }.to raise_exception ConnectionError
44
+ end
45
+
46
+ end
47
+ ##
48
+
49
+
50
+ describe '#quit' do
51
+
52
+ it 'calls redis.quit when appropriate' do
53
+ expect(redis).to receive(:quit)
54
+ handler.connect
55
+ handler.quit
56
+
57
+ expect(handler.redis).to be_nil
58
+ end
59
+
60
+ it 'returns gracefully if we are not connected' do
61
+ expect(redis).not_to receive(:quit)
62
+ handler.quit
63
+ end
64
+
65
+ end
66
+ ##
67
+
68
+
69
+ describe '#connected?' do
70
+
71
+ it 'returns false if we didnt call connect' do
72
+ expect( handler.connected? ).to be_falsey
73
+ end
74
+
75
+ it 'passes to redis.client.connected? if we have a redis instance' do
76
+ expect(redis).to receive(:connected?)
77
+
78
+ handler.connect
79
+ handler.connected?
80
+ end
81
+
82
+ end
83
+ ##
84
+
85
+
86
+ describe '#redis_on?' do
87
+
88
+ it 'is true if we were passed any connection hash at all' do
89
+ expect( RedisHandler.new(nil).redis_on? ).to be_falsy
90
+ expect( RedisHandler.new({}).redis_on? ).to be_falsy
91
+
92
+ expect( handler.redis_on? ).to be_truthy
93
+ end
94
+
95
+ end
96
+ ##
97
+
98
+
99
+ context 'when forwarding other methods to Redis' do
100
+
101
+ it 'handles only set, get, and del' do
102
+ expect(redis).to receive(:set)
103
+ expect(redis).to receive(:get)
104
+ expect(redis).to receive(:del)
105
+
106
+ handler.connect
107
+ handler.set("foo", {bar:1})
108
+ handler.get("foo")
109
+ handler.del("foo")
110
+
111
+ # I "happen to know" that we are using method_missing to implement the
112
+ # above. It's an implementation detail, but let's throw a test in for
113
+ # that, anyway:
114
+ expect{ handler.blewit }.to raise_exception NoMethodError
115
+ end
116
+
117
+ it 'raises ConnectionError if connect has not been called' do
118
+ expect{ handler.set("foo", {bar:1}) }.
119
+ to raise_exception Nebulous::ConnectionError
120
+
121
+ expect{ handler.get("foo") }.to raise_exception Nebulous::ConnectionError
122
+ expect{ handler.del("foo") }.to raise_exception Nebulous::ConnectionError
123
+ end
124
+
125
+ it 'raises ConnectionError if not connected' do
126
+ allow(redis).to receive(:connected?).and_return(true,false,false,false)
127
+ handler.connect
128
+
129
+ expect{ handler.set("foo", {bar:1}) }.
130
+ to raise_exception Nebulous::ConnectionError
131
+
132
+ expect{ handler.get("foo") }.to raise_exception Nebulous::ConnectionError
133
+ expect{ handler.del("foo") }.to raise_exception Nebulous::ConnectionError
134
+ end
135
+
136
+
137
+ end
138
+ ##
139
+
140
+ end
141
+
@@ -0,0 +1,100 @@
1
+ require 'pry'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ if config.files_to_run.one?
46
+ config.default_formatter = 'doc'
47
+ end
48
+
49
+ config.filter_run :focus
50
+ config.run_all_when_everything_filtered = true
51
+
52
+ # The settings below are suggested to provide a good initial experience
53
+ # with RSpec, but feel free to customize to your heart's content.
54
+ =begin
55
+ # These two settings work together to allow you to limit a spec run
56
+ # to individual examples or groups you care about by tagging them with
57
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
58
+ # get run.
59
+ config.filter_run :focus
60
+ config.run_all_when_everything_filtered = true
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
65
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = 'doc'
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
@@ -0,0 +1,19 @@
1
+ #$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ #require 'nebulous'
3
+
4
+ RSpec.configure do |config|
5
+
6
+ config.expect_with :rspec do |expectations|
7
+ expectations.include_chain_causes_in_custom_matcher_descriptions = true
8
+ end
9
+
10
+ config.mock_with :rspec do |mocks|
11
+ mocks.verify_partial_doubles = true
12
+ end
13
+
14
+ if config.files_to_run.one?
15
+ config.default_formatter = 'doc'
16
+ end
17
+
18
+ end
19
+ ~
@@ -0,0 +1,173 @@
1
+ require 'spec_helper'
2
+
3
+ require 'time'
4
+
5
+ require 'nebulous/stomp_handler_null'
6
+
7
+ include Nebulous
8
+
9
+
10
+ describe StompHandlerNull do
11
+
12
+ let(:handler) do
13
+ StompHandlerNull.new
14
+ end
15
+
16
+ let(:msg1) do
17
+ stomp_message('application/text', 'verb:Foo', client.calc_reply_id)
18
+ end
19
+
20
+ let(:msg2) do
21
+ stomp_message('application/text', 'verb:Bar', client.calc_reply_id)
22
+ end
23
+
24
+
25
+ describe 'StompHandlerNull.body_to_hash' do
26
+
27
+ it "returns a hash" do
28
+ expect{ StompHandlerNull.body_to_hash({}, 'baz') }.not_to raise_exception
29
+ expect( StompHandlerNull.body_to_hash({}, 'baz') ).to be_a_kind_of Hash
30
+ end
31
+
32
+ end
33
+ ##
34
+
35
+
36
+ describe "#initialize" do
37
+
38
+ it "takes an initialization hash" do
39
+ expect{ StompHandlerNull.new(foo: 'bar') }.not_to raise_exception
40
+ end
41
+
42
+ end
43
+ ##
44
+
45
+
46
+ describe '#insert_fake' do
47
+
48
+ it 'sets the message to send' do
49
+ handler.insert_fake( Message.from_parts('', '','foo', 'bar', 'baz') )
50
+ expect( handler.fake_mess ).to be_a_kind_of Nebulous::Message
51
+ expect( handler.fake_mess.verb ).to eq 'foo'
52
+ end
53
+
54
+ end
55
+ ##
56
+
57
+
58
+ describe '#connected?' do
59
+
60
+ it 'returns false if fake_message was not called' do
61
+ expect( handler.connected? ).to be_falsey
62
+ end
63
+
64
+ it 'returns true if fake_message was called' do
65
+ handler.insert_fake( Message.from_parts('','', 'one', 'two', 'three') )
66
+ expect( handler.connected? ).to be_truthy
67
+ end
68
+
69
+ end
70
+ ##
71
+
72
+
73
+ describe "#stomp_connect" do
74
+
75
+ it "returns self" do
76
+ expect(handler.stomp_connect).to eq handler
77
+ end
78
+
79
+ end
80
+ ##
81
+
82
+
83
+ describe "#calc_reply_id" do
84
+
85
+ it "returns a 'unique' string" do
86
+ handler.stomp_connect
87
+ expect( handler.calc_reply_id ).to respond_to :upcase
88
+ expect( handler.calc_reply_id.size ).to be > 12
89
+ end
90
+ end
91
+ ##
92
+
93
+
94
+ describe "send_message" do
95
+ let(:mess) { Nebulous::Message.from_parts(nil, nil, 'foo', nil, nil) }
96
+
97
+ it "accepts a queue name and a Message" do
98
+ expect{ handler.send_message('foo', mess) }.not_to raise_exception
99
+ end
100
+
101
+ it "returns the message" do
102
+ expect( handler.send_message('foo', mess) ).to eq mess
103
+ end
104
+
105
+ end
106
+ ##
107
+
108
+
109
+ describe "#listen" do
110
+
111
+ def run_listen(secs)
112
+ got = nil
113
+
114
+ handler.listen('/queue/foo') do |m|
115
+ got = m
116
+ end
117
+ sleep secs
118
+
119
+ got
120
+ end
121
+
122
+
123
+ it "yields a Message" do
124
+ handler.insert_fake( Message.from_parts('', '', 'foo', 'bar', 'baz') )
125
+ gotMessage = run_listen(1)
126
+
127
+ expect(gotMessage).not_to be_nil
128
+ expect(gotMessage).to be_a_kind_of Nebulous::Message
129
+ end
130
+
131
+ end
132
+ ##
133
+
134
+
135
+ describe "listen_with_timeout" do
136
+
137
+ def run_listen_with_timeout(secs)
138
+ got = nil
139
+ handler.listen_with_timeout('/queue/foo', secs) do |m|
140
+ got = m
141
+ end
142
+
143
+ got
144
+ end
145
+
146
+ context "when there is a message" do
147
+
148
+ it "yields a Message" do
149
+ handler.insert_fake( Message.from_parts('', '', 'foo', 'bar', 'baz') )
150
+ gotMessage = run_listen_with_timeout(1)
151
+
152
+ expect( gotMessage ).not_to be_nil
153
+ expect( gotMessage ).to be_a_kind_of Nebulous::Message
154
+ end
155
+
156
+ end
157
+
158
+ context "when there is no message" do
159
+
160
+ it 'raises NebulousTimeout' do
161
+ expect{handler.listen_with_timeout('foo', 2)}.
162
+ to raise_exception Nebulous::NebulousTimeout
163
+
164
+ end
165
+
166
+ end
167
+
168
+ end
169
+ ##
170
+
171
+
172
+ end
173
+