fastly_nsq 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +1 -1
  5. data/Gemfile +0 -2
  6. data/README.md +56 -14
  7. data/Rakefile +4 -9
  8. data/examples/Rakefile +36 -0
  9. data/fastly_nsq.gemspec +1 -2
  10. data/lib/fastly_nsq/message_queue/consumer.rb +5 -1
  11. data/lib/fastly_nsq/message_queue/listener.rb +27 -4
  12. data/lib/fastly_nsq/message_queue/producer.rb +5 -1
  13. data/lib/fastly_nsq/rake_task.rb +40 -0
  14. data/lib/fastly_nsq/sample_message_processor.rb +16 -12
  15. data/lib/fastly_nsq/version.rb +1 -1
  16. data/{test/lib/fastly_nsq/fake_message_queue_test.rb → spec/lib/fastly_nsq/fake_message_queue_spec.rb} +12 -12
  17. data/{test/lib/fastly_nsq/fastly_nsq_test.rb → spec/lib/fastly_nsq/fastly_nsq_spec.rb} +3 -3
  18. data/spec/lib/fastly_nsq/message_queue/consumer_spec.rb +93 -0
  19. data/spec/lib/fastly_nsq/message_queue/listener_spec.rb +78 -0
  20. data/spec/lib/fastly_nsq/message_queue/producer_spec.rb +84 -0
  21. data/{test/lib/fastly_nsq/message_queue/strategy.rb → spec/lib/fastly_nsq/message_queue/strategy_spec.rb} +5 -7
  22. data/{test/lib/fastly_nsq/sample_message_processor_test.rb → spec/lib/fastly_nsq/sample_message_processor_spec.rb} +8 -22
  23. data/spec/spec_helper.rb +44 -0
  24. data/spec/support/env_helpers.rb +19 -0
  25. data/test/lib/fastly_nsq/rake_task_test.rb +68 -0
  26. metadata +17 -33
  27. data/test/lib/fastly_nsq/message_queue/consumer_test.rb +0 -59
  28. data/test/lib/fastly_nsq/message_queue/listener_test.rb +0 -45
  29. data/test/lib/fastly_nsq/message_queue/producer_test.rb +0 -54
  30. data/test/test_helper.rb +0 -49
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastly_nsq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy O'Neil
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-11 00:00:00.000000000 Z
12
+ date: 2016-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0.4'
56
- - !ruby/object:Gem::Dependency
57
- name: minitest
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '5.8'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '5.8'
70
56
  - !ruby/object:Gem::Dependency
71
57
  name: pry-byebug
72
58
  requirement: !ruby/object:Gem::Requirement
@@ -110,7 +96,7 @@ dependencies:
110
96
  - !ruby/object:Gem::Version
111
97
  version: '4.2'
112
98
  - !ruby/object:Gem::Dependency
113
- name: rspec-mocks
99
+ name: rspec
114
100
  requirement: !ruby/object:Gem::Requirement
115
101
  requirements:
116
102
  - - "~>"
@@ -166,6 +152,7 @@ files:
166
152
  - ".document"
167
153
  - ".gitignore"
168
154
  - ".rdoc_options"
155
+ - ".ruby-version"
169
156
  - ".travis.yml"
170
157
  - ChangeLog.md
171
158
  - Gemfile
@@ -174,6 +161,7 @@ files:
174
161
  - Rakefile
175
162
  - env_configuration_for_local_gem_tests.yml
176
163
  - examples/.sample.env
164
+ - examples/Rakefile
177
165
  - fastly_nsq.gemspec
178
166
  - lib/fastly_nsq.rb
179
167
  - lib/fastly_nsq/fake_message_queue.rb
@@ -182,16 +170,19 @@ files:
182
170
  - lib/fastly_nsq/message_queue/listener.rb
183
171
  - lib/fastly_nsq/message_queue/producer.rb
184
172
  - lib/fastly_nsq/message_queue/strategy.rb
173
+ - lib/fastly_nsq/rake_task.rb
185
174
  - lib/fastly_nsq/sample_message_processor.rb
186
175
  - lib/fastly_nsq/version.rb
187
- - test/lib/fastly_nsq/fake_message_queue_test.rb
188
- - test/lib/fastly_nsq/fastly_nsq_test.rb
189
- - test/lib/fastly_nsq/message_queue/consumer_test.rb
190
- - test/lib/fastly_nsq/message_queue/listener_test.rb
191
- - test/lib/fastly_nsq/message_queue/producer_test.rb
192
- - test/lib/fastly_nsq/message_queue/strategy.rb
193
- - test/lib/fastly_nsq/sample_message_processor_test.rb
194
- - test/test_helper.rb
176
+ - spec/lib/fastly_nsq/fake_message_queue_spec.rb
177
+ - spec/lib/fastly_nsq/fastly_nsq_spec.rb
178
+ - spec/lib/fastly_nsq/message_queue/consumer_spec.rb
179
+ - spec/lib/fastly_nsq/message_queue/listener_spec.rb
180
+ - spec/lib/fastly_nsq/message_queue/producer_spec.rb
181
+ - spec/lib/fastly_nsq/message_queue/strategy_spec.rb
182
+ - spec/lib/fastly_nsq/sample_message_processor_spec.rb
183
+ - spec/spec_helper.rb
184
+ - spec/support/env_helpers.rb
185
+ - test/lib/fastly_nsq/rake_task_test.rb
195
186
  homepage: https://github.com/fastly/fastly-nsq
196
187
  licenses:
197
188
  - MIT
@@ -217,11 +208,4 @@ signing_key:
217
208
  specification_version: 4
218
209
  summary: Fastly NSQ Adapter
219
210
  test_files:
220
- - test/lib/fastly_nsq/fake_message_queue_test.rb
221
- - test/lib/fastly_nsq/fastly_nsq_test.rb
222
- - test/lib/fastly_nsq/message_queue/consumer_test.rb
223
- - test/lib/fastly_nsq/message_queue/listener_test.rb
224
- - test/lib/fastly_nsq/message_queue/producer_test.rb
225
- - test/lib/fastly_nsq/message_queue/strategy.rb
226
- - test/lib/fastly_nsq/sample_message_processor_test.rb
227
- - test/test_helper.rb
211
+ - test/lib/fastly_nsq/rake_task_test.rb
@@ -1,59 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe MessageQueue::Consumer do
4
- describe '#connection' do
5
- describe 'when using the real queue' do
6
- it 'returns an instance of the queue consumer' do
7
- MessageQueue::FALSY_VALUES.each do |no|
8
- allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(no)
9
- allow(Nsq::Consumer).to receive(:new)
10
- topic = 'death_star'
11
- channel = 'star_killer_base'
12
-
13
- MessageQueue::Consumer.new(topic: topic, channel: channel).connection
14
-
15
- expect(Nsq::Consumer).to have_received(:new).
16
- with(
17
- nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
18
- topic: topic,
19
- channel: channel,
20
- ).at_least(:once)
21
- end
22
- end
23
- end
24
- end
25
-
26
- describe 'when using the fake queue' do
27
- it 'returns an instance of the queue consumer' do
28
- MessageQueue::TRUTHY_VALUES.each do |yes|
29
- allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(yes)
30
- allow(FakeMessageQueue::Consumer).to receive(:new)
31
- topic = 'death_star'
32
- channel = 'star_killer_base'
33
-
34
- MessageQueue::Consumer.new(topic: topic, channel: channel).connection
35
-
36
- expect(FakeMessageQueue::Consumer).to have_received(:new).
37
- with(
38
- nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
39
- topic: topic,
40
- channel: channel,
41
- ).at_least(:once)
42
- end
43
- end
44
- end
45
-
46
- describe 'when the ENV is set incorrectly' do
47
- it 'raises with a helpful error' do
48
- allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return('taco')
49
- topic = 'death_star'
50
- channel = 'star_killer_base'
51
-
52
- consumer = MessageQueue::Consumer.new(topic: topic, channel: channel)
53
-
54
- assert_raises(InvalidParameterError) do
55
- consumer.connection
56
- end
57
- end
58
- end
59
- end
@@ -1,45 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe MessageQueue::Listener do
4
- describe '#process_next_message' do
5
- it 'pass the topic and channel to the consumer' do
6
- allow(SampleMessageProcessor).to receive_message_chain(:new, :go)
7
- allow(MessageQueue::Consumer).to receive_message_chain(
8
- :new,
9
- :connection,
10
- :pop,
11
- )
12
- topic = 'minitest'
13
- channel = 'northstar'
14
-
15
- MessageQueue::Listener.new(topic: topic, channel: channel).
16
- process_next_message
17
-
18
- expect(MessageQueue::Consumer).to have_received(:new).
19
- with(topic: topic, channel: channel)
20
- end
21
-
22
- it 'processes the message' do
23
- process_message = double(go: nil)
24
- allow(MessageProcessor).to receive(:new).and_return(process_message)
25
- message = double
26
- allow(MessageQueue::Consumer).to receive_message_chain(
27
- :new,
28
- :connection,
29
- pop: message
30
- )
31
- topic = 'minitest'
32
- channel = 'northstar'
33
-
34
- MessageQueue::Listener.new(topic: topic, channel: channel).
35
- process_next_message
36
-
37
- expect(MessageProcessor).to have_received(:new).with(message)
38
- expect(process_message).to have_received(:go)
39
- end
40
- end
41
-
42
- describe '#go' do
43
- # Infinite loops are untestable
44
- end
45
- end
@@ -1,54 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe MessageQueue::Producer do
4
- describe '#connection' do
5
- describe 'when using the real queue' do
6
- it 'returns an instance of the queue producer' do
7
- MessageQueue::FALSY_VALUES.each do |no|
8
- allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(no)
9
- allow(Nsq::Producer).to receive(:new)
10
- topic = 'death_star'
11
-
12
- MessageQueue::Producer.new(topic: topic).connection
13
-
14
- expect(Nsq::Producer).to have_received(:new).
15
- with(
16
- nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
17
- topic: topic,
18
- ).at_least(:once)
19
- end
20
- end
21
- end
22
- end
23
-
24
- describe 'when using the fake queue' do
25
- it 'returns an instance of the queue producer' do
26
- MessageQueue::TRUTHY_VALUES.each do |yes|
27
- allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(yes)
28
- allow(FakeMessageQueue::Producer).to receive(:new)
29
- topic = 'death_star'
30
-
31
- MessageQueue::Producer.new(topic: topic).connection
32
-
33
- expect(FakeMessageQueue::Producer).to have_received(:new).
34
- with(
35
- nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
36
- topic: topic,
37
- ).at_least(:once)
38
- end
39
- end
40
- end
41
-
42
- describe 'when the ENV is set incorrectly' do
43
- it 'raises with a helpful error' do
44
- allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return('taco')
45
- topic = 'death_star'
46
-
47
- producer = MessageQueue::Producer.new(topic: topic)
48
-
49
- assert_raises(InvalidParameterError) do
50
- producer.connection
51
- end
52
- end
53
- end
54
- end
@@ -1,49 +0,0 @@
1
- require 'rubygems'
2
-
3
- begin
4
- require 'bundler/setup'
5
- rescue LoadError => error
6
- abort error.message
7
- end
8
-
9
- require 'fastly_nsq'
10
-
11
- require 'minitest/autorun'
12
- require 'awesome_print'
13
- require 'pry-byebug'
14
- require_relative '../lib/fastly_nsq/sample_message_processor'
15
-
16
- MessageProcessor = SampleMessageProcessor
17
-
18
- MiniTest::Spec.before do
19
- load_sample_environment_variables
20
- end
21
-
22
- def load_sample_environment_variables
23
- env_file = File.open('env_configuration_for_local_gem_tests.yml')
24
-
25
- YAML.load(env_file).each do |key, value|
26
- ENV[key.to_s] = value
27
- end
28
- end
29
-
30
- require 'rspec/mocks'
31
- module MinitestRSpecMocksIntegration
32
- include ::RSpec::Mocks::ExampleMethods
33
-
34
- def before_setup
35
- ::RSpec::Mocks.setup
36
- super
37
- end
38
-
39
- def after_teardown
40
- super
41
- ::RSpec::Mocks.verify
42
- ensure
43
- ::RSpec::Mocks.teardown
44
- end
45
- end
46
-
47
- class MiniTest::Spec
48
- include MinitestRSpecMocksIntegration
49
- end