bunny-publisher 0.1.1 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c083b8200bdbe3d30cb2672065e3529c1e1dc78f82514f8d694f83419df279b
4
- data.tar.gz: 38c13c753e4bceeb6f26d344ab050769a874201fb262b47104005bfed3b22466
3
+ metadata.gz: 81976f1ec6350ac4bd2ec4182f0b0c42dcb99705b014228f896f5183bf3e02af
4
+ data.tar.gz: 15cc8eef3348d2eff8367aa3f8167a1762e9a94fa56506168f47618ee857e7ed
5
5
  SHA512:
6
- metadata.gz: 1db69e62d8f38eb35b3a625233af35304ddbeb5ce9af02c3fb162e559813267f3b465dd48e54547a57d1ec9e988d57483e1c03a878b883dab699b14f0588dd43
7
- data.tar.gz: 462fc949e57fcc820e1486a86e4a216229c2bbe2a15792563e1dc45435f97e179cc1d6663f9fbd92a5c74417179631bf87ebadb2e5b674732e39df7d23342681
6
+ metadata.gz: d67b3c8e5a609b61450452a8f87aaa281ee458d10f3c5d551e45b8ab5bdf9fb07e75df06525f7df803b88129a5412229a26f485f4f602d71cf309cc737619806
7
+ data.tar.gz: 4cdf52e2d3f6a8f99156b0e7359b6a3bf54841ae80ea3cf461c3ab8f1e105a0cc66d0d7e6cc3a0d25812b607dfddb8222b330508c49821866528cc5f589948e3
@@ -1,3 +1,7 @@
1
+ ## Changes Between 0.1.1 and 0.1.2
2
+
3
+ Added [test mode](https://github.com/veeqo/bunny-publisher#test-mode)
4
+
1
5
  ## Changes Between 0.1.0 and 0.1.1
2
6
 
3
7
  Minor improvements of unrouted message processing at program exit.
data/README.md CHANGED
@@ -111,6 +111,32 @@ end
111
111
 
112
112
  Not implemented yet
113
113
 
114
+ ## Test mode
115
+
116
+ BunnyPublisher also has a test mode which replaces exchange and prevents real connection to RabbitMQ
117
+
118
+ ```ruby
119
+ BunnyPublisher.configure do |c|
120
+ c.test = true # or Rails.env.test?
121
+
122
+ # ...
123
+ end
124
+ ```
125
+
126
+ Now publisher has `#messages`, `#flush!` methods:
127
+
128
+ ```ruby
129
+ describe SomeServiceThatPublishesToRabbitMQ, '#call' do
130
+ subject { described_class.new(some: 'attributes').call }
131
+
132
+ before { BunnyPublisher.flush! }
133
+
134
+ it 'publishes a message' do
135
+ expect { subject }.to change(BunnyPublisher.messages).by(1)
136
+ end
137
+ end
138
+ ```
139
+
114
140
  ## Contributing
115
141
 
116
142
  Bug reports and pull requests are welcome on GitHub at https://github.com/veeqo/bunny-publisher.
@@ -6,6 +6,7 @@ require 'bunny_publisher/callbacks'
6
6
  require 'bunny_publisher/errors'
7
7
  require 'bunny_publisher/base'
8
8
  require 'bunny_publisher/mandatory'
9
+ require 'bunny_publisher/test'
9
10
 
10
11
  module BunnyPublisher
11
12
  class << self
@@ -20,13 +21,28 @@ module BunnyPublisher
20
21
  def configure
21
22
  require 'ostruct'
22
23
 
23
- config = OpenStruct.new({})
24
+ config = OpenStruct.new(mandatory: false, test: false)
24
25
 
25
26
  yield(config)
26
27
 
27
- klass = Class.new(Base).tap { |k| k.include(::BunnyPublisher::Mandatory) if config.delete_field(:mandatory) }
28
+ klass = Class.new(Base) do
29
+ include ::BunnyPublisher::Mandatory if config.delete_field(:mandatory)
30
+ include ::BunnyPublisher::Test if config.delete_field(:test)
31
+ end
28
32
 
29
33
  @publisher = klass.new(config.to_h)
30
34
  end
35
+
36
+ def method_missing(method_name, *args)
37
+ if publisher.respond_to?(method_name)
38
+ publisher.send(method_name, *args)
39
+ else
40
+ super
41
+ end
42
+ end
43
+
44
+ def respond_to_missing?(method_name, include_private = false)
45
+ publisher.respond_to?(method_name) || super
46
+ end
31
47
  end
32
48
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BunnyPublisher
4
+ # Test module prevents real connections to be made and replaces exchange with array-based TestExchange
5
+ module Test
6
+ class TestExchange < Array
7
+ def publish(message, options = {})
8
+ self << [message, options]
9
+ true
10
+ end
11
+
12
+ # in case if used with Mandatory module included
13
+ def on_return(&block); end
14
+ end
15
+
16
+ def exchange
17
+ @exchange ||= TestExchange.new
18
+ end
19
+
20
+ alias messages exchange
21
+
22
+ def flush!
23
+ exchange.clear
24
+ end
25
+
26
+ alias close flush!
27
+ alias stop flush!
28
+
29
+ private
30
+
31
+ def ensure_connection!; end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BunnyPublisher
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunny-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Sharshenov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-21 00:00:00.000000000 Z
11
+ date: 2020-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -117,6 +117,7 @@ files:
117
117
  - lib/bunny_publisher/callbacks.rb
118
118
  - lib/bunny_publisher/errors.rb
119
119
  - lib/bunny_publisher/mandatory.rb
120
+ - lib/bunny_publisher/test.rb
120
121
  - lib/bunny_publisher/version.rb
121
122
  homepage: https://github.com/veeqo/bunny-publisher
122
123
  licenses: