fluffle 0.2.1 → 0.2.2

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
2
  SHA1:
3
- metadata.gz: 255eee82ad3d15d6a7b9623e2abc52327c0b029c
4
- data.tar.gz: 9d0496f43f6f63e85b8de2d861d516959ec92cb5
3
+ metadata.gz: 5873bf894f32f349386f18661620aabd487dabb9
4
+ data.tar.gz: 6f832fa861f56d4186a7e260bbed46b0233c7428
5
5
  SHA512:
6
- metadata.gz: 5dad9fde293a176c4b3f9cfe1c8dcc3cee2359f683db422d3e8a1f0273be9d84e57b5c24b1bd044a8f7416db58fa9d96551c87d4c1c19ee1e75ad31df9165e8c
7
- data.tar.gz: 1d5e676a4db1978eda8e987c56d045ae137cd06345917ad10a0678db108d1b18d8240f9c2361ed47b00f4d512690443e3910fa99450e412198bd460b86e8cce7
6
+ metadata.gz: 59bedfeb61ff2766100e3515dbcd75f4f240cb58febb9ceb904e9a696d305e52e894fb6aef61124a852554c09ef0fee202735cb06a85e5548b2c4888ec661446
7
+ data.tar.gz: 6a9bfdbc4940b1ff64a2536c9c65ed61fd36dde610a0a4cf1b9390a4bf7709f31a626179028df42ce0f3cd82f6111bf2ea7a368067cca6988df313f84a69168e
data/examples/testing.rb CHANGED
@@ -3,6 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  require 'fluffle'
5
5
  require 'fluffle/testing'
6
+ Fluffle::Testing.setup!
6
7
 
7
8
  server = Fluffle::Server.new url: 'amqp://localhost'
8
9
 
@@ -72,7 +72,7 @@ module Fluffle
72
72
  response = publish_and_wait payload, queue: queue,
73
73
  timeout: timeout
74
74
 
75
- if response['result']
75
+ if response.key? 'result'
76
76
  response['result']
77
77
  else
78
78
  error = response['error'] || {}
@@ -2,19 +2,35 @@ require 'concurrent'
2
2
 
3
3
  module Fluffle
4
4
  module Testing
5
- def self.setup!
6
- # Inject our own custom `Connectable` implementation
7
- [Fluffle::Client, Fluffle::Server].each do |mod|
8
- mod.include Connectable
9
- end
5
+ class << self
6
+ def setup!(use_fake_thread_pool: true)
7
+ # Inject our own custom `Connectable` implementation
8
+ [Fluffle::Client, Fluffle::Server].each do |mod|
9
+ mod.include Connectable
10
+ end
10
11
 
11
- Fluffle::Server.class_eval do
12
- # Overwriting this so that we don't actually block waiting for signal
13
- def wait_for_signal
14
- # pass
12
+ Fluffle::Server.class_eval do
13
+ # Overwriting this so that we don't actually block waiting for signal
14
+ def wait_for_signal
15
+ # pass
16
+ end
17
+ end
18
+
19
+ if use_fake_thread_pool
20
+ Fluffle::Server.class_eval do
21
+ # Wrap the `initialize` implementation to switch out the handler pool
22
+ # to a local unthreaded one
23
+ alias_method :original_initialize, :initialize
24
+
25
+ def initialize(*args)
26
+ original_initialize *args
27
+
28
+ @handler_pool = ThreadPool.new
29
+ end
30
+ end
15
31
  end
16
32
  end
17
- end
33
+ end # class << self
18
34
 
19
35
  # Patch in a new `#connect` method that injects the loopback
20
36
  module Connectable
@@ -29,6 +45,14 @@ module Fluffle
29
45
  end
30
46
  end
31
47
 
48
+ # Fake thread pool that executes `#post`'ed blocks immediately in the
49
+ # current thread
50
+ class ThreadPool
51
+ def post(&block)
52
+ block.call
53
+ end
54
+ end
55
+
32
56
  # Fake RabbitMQ server presented through a subset of the `Bunny`
33
57
  # library's interface
34
58
  class Loopback
@@ -130,5 +154,3 @@ module Fluffle
130
154
  end # class LoopbackServer
131
155
  end # module Testing
132
156
  end # module Fluffle
133
-
134
- Fluffle::Testing.setup!
@@ -1,3 +1,3 @@
1
1
  module Fluffle
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -71,6 +71,16 @@ describe Fluffle::Client do
71
71
  expect(subject.call(method)).to eq(result)
72
72
  end
73
73
 
74
+ it 'accepts null as a result' do
75
+ respond = prepare_response 'result' => nil
76
+
77
+ allow(@exchange_spy).to receive(:publish) do |payload, _opts|
78
+ respond.call Oj.load(payload)['id']
79
+ end
80
+
81
+ expect(subject.call('something')).to eq(nil)
82
+ end
83
+
74
84
  it 'raises on error from server' do
75
85
  code = 1337
76
86
  message = 'Uh-oh!'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluffle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dirk Gadsden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2016-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny