lapine 0.1.0 → 0.1.1

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: c903d73c15a42efe4c3714fa857ac2445e323710
4
- data.tar.gz: 8586dd9c5d4d2dc8cc1aa54a4e3c4111b06d8485
3
+ metadata.gz: db131a0aa239e502ac31258568eb2180c3699c95
4
+ data.tar.gz: c2c3302d3ced52aa11d78d477241be7af4183cf7
5
5
  SHA512:
6
- metadata.gz: 88a0490e40a3107ac07c38cf1e39842af4a31a6886036f24e1c0fbfd1d42641aed7cc4352420fb99522c48ded69930a6ca44c549d57b2ac188e687643a164053
7
- data.tar.gz: 97bd4d3961e10c83f3bfad031da65061cdb0f3823e52c7c2dcadb19b88bb626788ff20d2069ba2e2377c4a6dd2fef6d3040a0e1324602c0cafbc6e36284c734a
6
+ metadata.gz: 9a29396753fe50307e752fd5a06cd1f02ddf64b011ca65869be06b770d47e68492c88cd8bec89019a6d2a70fe3bc658e2047f6f6895f0ea0ea8f84d8acfde102
7
+ data.tar.gz: 67122efa1ccb92aa40b0e5237e5218e05c55d30aa1f26e0f9350a62d0d7c8912172a1af1d7537b4b78c593b23e7f5e257864a8d0c6975b691167b0e53149b627
data/README.md CHANGED
@@ -78,6 +78,45 @@ are arbitrary.
78
78
  complex or assumed very specific configurations different from what
79
79
  we want.
80
80
 
81
+
82
+ ## Testing
83
+
84
+ Lapine comes with helpers to stub out calls to RabbitMQ. This allows you
85
+ to write tests using Lapine, without having to actually run RabbitMQ in
86
+ your test suite.
87
+
88
+ ```ruby
89
+ require 'lapine/test/rspec_helper'
90
+
91
+ RSpec.configure do |config|
92
+ config.include Lapine::Test::RSpecHelper, fake_rabbit: true
93
+
94
+ config.before :each, :fake_rabbit do |example|
95
+ Lapine::Test::RSpecHelper.setup(example)
96
+ end
97
+
98
+ config.after :each, :fake_rabbit do
99
+ Lapine::Test::RSpecHelper.teardown
100
+ end
101
+ end
102
+ ```
103
+
104
+ An example test would look something like this:
105
+
106
+ ```ruby
107
+ RSpec.describe MyPublisher, fake_rabbit: true do
108
+ let(:exchange) { Lapine.find_exchange('my.topic') }
109
+ let(:queue) { exchange.channel.queue.bind(exchange) }
110
+
111
+ describe 'publishing' do
112
+ it 'adds a message to a queue' do
113
+ MyPublisher.new.publish('my.things')
114
+ expect(queue.message_count).to eq(1)
115
+ end
116
+ end
117
+ end
118
+ ```
119
+
81
120
  ## Contributing
82
121
 
83
122
  1. Fork it ( https://github.com/[my-github-username]/lapine/fork )
@@ -25,7 +25,7 @@ module Lapine
25
25
  end
26
26
 
27
27
  def close!
28
- @conn.close
28
+ conn.close if conn.connected?
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,83 @@
1
+ module Lapine
2
+ module Test
3
+ class FakeChannel
4
+ attr_reader :queues
5
+
6
+ def initialize
7
+ @queues = {}
8
+ end
9
+
10
+ def queue(name = nil, opts = {})
11
+ @queues[name] ||= FakeQueue.new
12
+ end
13
+ end
14
+
15
+ class FakeExchange
16
+ attr_reader :histories
17
+
18
+ def initialize
19
+ @histories = []
20
+ end
21
+
22
+ def channel
23
+ @channel ||= FakeChannel.new
24
+ end
25
+
26
+ def bind(history)
27
+ histories << history
28
+ end
29
+
30
+ def publish(body, routing_key = nil)
31
+ histories.each do |h|
32
+ h.publish(body, routing_key)
33
+ end
34
+ end
35
+ end
36
+
37
+ class FakeQueue
38
+ attr_reader :history
39
+
40
+ def bind(exchange)
41
+ @history = MessageHistory.new
42
+ exchange.bind history
43
+ self
44
+ end
45
+
46
+ def message_count
47
+ history.message_count
48
+ end
49
+ end
50
+
51
+ class MessageHistory
52
+ attr_reader :messages
53
+
54
+ def initialize
55
+ @messages = []
56
+ end
57
+
58
+ def publish(body, routing_key)
59
+ messages << [body, routing_key]
60
+ end
61
+
62
+ def message_count
63
+ messages.size
64
+ end
65
+ end
66
+
67
+ class Exchange
68
+ attr_reader :name
69
+
70
+ def initialize(name, properties)
71
+ @name = name
72
+ end
73
+
74
+ def exchange
75
+ @exchange ||= FakeExchange.new
76
+ end
77
+
78
+ def close!
79
+ true
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,19 @@
1
+ require 'lapine/test/exchange'
2
+
3
+ module Lapine
4
+ module Test
5
+ module RSpecHelper
6
+ def self.setup(example)
7
+ example.allow(Lapine::Exchange).to(
8
+ example.receive(:new) { |name, properties|
9
+ Lapine::Test::Exchange.new(name, properties)
10
+ }
11
+ )
12
+ end
13
+
14
+ def self.teardown
15
+ Lapine.close_connections!
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Lapine
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lapine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Saxby
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-25 00:00:00.000000000 Z
12
+ date: 2014-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bunny
@@ -114,6 +114,8 @@ files:
114
114
  - lib/lapine/configuration.rb
115
115
  - lib/lapine/exchange.rb
116
116
  - lib/lapine/publisher.rb
117
+ - lib/lapine/test/exchange.rb
118
+ - lib/lapine/test/rspec_helper.rb
117
119
  - lib/lapine/version.rb
118
120
  - spec/lib/lapine/publisher_spec.rb
119
121
  - spec/lib/lapine_spec.rb
@@ -138,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
140
  version: '0'
139
141
  requirements: []
140
142
  rubyforge_project:
141
- rubygems_version: 2.2.2
143
+ rubygems_version: 2.4.4
142
144
  signing_key:
143
145
  specification_version: 4
144
146
  summary: Talk to rabbits