wisper_subscription 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 912d8f12cd963ba1e732752590ca8c86022fae28
4
+ data.tar.gz: 71b57abd56add0f8163f9757d17589893844fdcd
5
+ SHA512:
6
+ metadata.gz: 5dc155254a0c2aebc81902f451be952d8d3cd2b4c4b54a3218be998dcd4bc6c1d5861fa36cd8669f8dee5556ebc979abdf329cf809f62ce43855362889e95580
7
+ data.tar.gz: 36759f7dad409e02d1d1713bf8f293603a60f11e1e01373885e92f02242802edcac2d6b115c215b39f6374ff6dbe1350c87ca991a4e4839627ce8e14700f3bc8
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wisper_subscription.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jeff Dickey
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # WisperSubscription
2
+
3
+ [![Join the chat at https://gitter.im/jdickey/wisper_subscription](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jdickey/wisper_subscription?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/wisper_subscription.svg)](http://badge.fury.io/rb/wisper_subscription)
6
+ [![Code Climate](https://codeclimate.com/github/jdickey/wisper_subscription.png)](https://codeclimate.com/github/jdickey/wisper_subscription)
7
+ [ ![Codeship Status for jdickey/wisper_subscription](https://codeship.com/projects/2e3dfaa0-8950-0132-3d83-4e5a44c3ddcb/status?branch=master)](https://codeship.com/projects/59675)
8
+ [![security](https://hakiri.io/github/jdickey/wisper_subscription/master.svg)](https://hakiri.io/github/jdickey/wisper_subscription/master)
9
+ [![Dependency Status](https://gemnasium.com/jdickey/wisper_subscription.svg)](https://gemnasium.com/jdickey/wisper_subscription)
10
+
11
+ This Gem contains a class, `WisperSubscription`, which encapsulates an extremly
12
+ simple container to record call parameters for messages, and query methods for
13
+ whether a defined message was sent. This is a refinement of a class
14
+ [originally developed](https://github.com/jdickey/new_poc/blob/c255cbd/spec/support/broadcast_success_tester.rb)
15
+ to record results of very specific [Wisper](https://github.com/krisleech/wisper)
16
+ broadcast messages to support testing of broadcasters of such messages. While
17
+ [restructuring that app](https://github.com/jdickey/new_poc/issues/54), the
18
+ existing `BroadcastSuccessTester` was identified as a dependency of the testing
19
+ for [*multiple*](https://github.com/jdickey/new_poc/issues/173) to-be-decoupled
20
+ classes. Including that test-support class in so many redundant places would have
21
+ been an engraved invitation to sync-related bugs (and egregious waste), and so
22
+ this `WisperSubscription` class/Gem was created.
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'wisper_subscription'
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install wisper_subscription
39
+
40
+ ## Usage
41
+
42
+ Remember that this was originally developed to support testing Wisper message
43
+ broadcast from an object. So you might have an RSpec file (Minitest would be
44
+ similar) that had excerpts [similar to](https://github.com/jdickey/new_poc/blob/c255cbd/spec/actions/index_users_spec.rb):
45
+
46
+ ```ruby
47
+ describe SomeWisperPublishingClass do
48
+ let(:subscriber) { WisperSubscription.new }
49
+ let(:command_params) do
50
+ # ...
51
+ end
52
+ let(:command) { described_class.new command_params }
53
+
54
+ before :each do
55
+ # some setup
56
+ subscriber.define_message :success
57
+ subscriber.define_Message :failure
58
+ command.subscribe subscriber
59
+ command.do_something_that_broadcasts_a_success
60
+ end
61
+
62
+ it 'was successful' do
63
+ payload = subscriber.payload_for(:success).to_a.first
64
+ expect(payload).to be_a WhatYouExpectOnSuccess # as opposed to nil
65
+ end
66
+
67
+ # ...
68
+ end
69
+ ```
70
+
71
+ You get the idea. If not, open an issue or ask on our Gitter channel.
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it ( https://github.com/jdickey/wisper_subscription/fork )
76
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 1. Ensure that your changes are completely covered by *passing* specs, and comply with the [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) as enforced by [RuboCop](https://github.com/bbatsov/rubocop). To verify this, run `bundle exec rake`, noting and repairing any lapses in coverage or style violations;
78
+ 1. Commit your changes (`git commit -a`). Please *do not* use a single-line commit message (`git commit -am "some message"`). A good commit message notes what was changed and why in sufficient detail that a relative newcomer to the code can understand your reasoning and your code;
79
+ 1. Push to the branch (`git push origin my-new-feature`)
80
+ 1. Create a new Pull Request. Describe at some length the rationale for your new feature; your implementation strategy at a higher level than each individual commit message; anything future maintainers should be aware of; and so on. *If this is a modification to existing code, reference the open issue being addressed*.
81
+ 1. Don't be discouraged if the PR generates a discussion that leads to further refinement of your PR through additional commits. These should *generally* be discussed in comments on the PR itself; discussion in the Gitter room (see below) may also be useful;
82
+ 1. If you've comments, questions, or just want to talk through your ideas, come hang out in the project's [room on Gitter](https://gitter.im/jdickey/wisper_subscription). Ask away!
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+
6
+ RuboCop::RakeTask.new(:rubocop) do |task|
7
+ task.patterns = [
8
+ 'lib/**/*.rb',
9
+ 'spec/spec_helper.rb',
10
+ 'spec/**/*_spec.rb'
11
+ ]
12
+ task.formatters = ['simple', 'd']
13
+ task.fail_on_error = true
14
+ # task.options << '--rails'
15
+ end
16
+
17
+ RSpec::Core::RakeTask.new :spec
18
+
19
+ task(:default).clear
20
+ task default: [:spec, :rubocop]
@@ -0,0 +1,5 @@
1
+
2
+ # Collects and reports on messages sent to an instance.
3
+ class WisperSubscription
4
+ VERSION = '0.1.1'
5
+ end
@@ -0,0 +1,60 @@
1
+
2
+ require 'wisper_subscription/version'
3
+
4
+ # Collects and reports on messages sent to an instance.
5
+ class WisperSubscription
6
+ def initialize
7
+ @internals = {}
8
+ @empty_payload = []
9
+ @query_pattern = /^.*\?$/
10
+ end
11
+
12
+ def define_message(message)
13
+ @message = message
14
+ add_internals_entry
15
+ add_query_method
16
+ add_responder_method
17
+ self
18
+ end
19
+
20
+ def payload_for(message)
21
+ return empty_payload unless @internals.key? message
22
+ @internals[message]
23
+ end
24
+
25
+ def method_missing(method_sym, *arguments, &block)
26
+ return false if method_sym.to_s =~ query_pattern
27
+ super
28
+ end
29
+
30
+ def respond_to?(symbol, include_all = false)
31
+ return true if symbol.to_s =~ query_pattern
32
+ super
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :empty_payload, :query_pattern
38
+
39
+ def add_internals_entry
40
+ @internals[@message.to_sym] = []
41
+ self
42
+ end
43
+
44
+ def add_query_method
45
+ message = @message
46
+ define_singleton_method "#{@message}?".to_sym do
47
+ !@internals[message].to_a.empty?
48
+ end
49
+ self
50
+ end
51
+
52
+ def add_responder_method
53
+ message = @message
54
+ define_singleton_method @message.to_sym do |*params|
55
+ @internals[message].push params
56
+ self
57
+ end
58
+ self
59
+ end
60
+ end
@@ -0,0 +1,10 @@
1
+
2
+ require 'simplecov'
3
+ SimpleCov.start do # 'rails'
4
+ add_filter '/spec/'
5
+ add_filter '/vendor/'
6
+ end
7
+
8
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
9
+
10
+ require 'wisper_subscription'
@@ -0,0 +1,132 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe WisperSubscription do
5
+ let(:obj) { described_class.new }
6
+ let(:message) { :foo }
7
+ let(:other_message) { :bar }
8
+
9
+ it 'has a version number' do
10
+ expect(WisperSubscription::VERSION).not_to be nil
11
+ end
12
+
13
+ describe '#initialize' do
14
+ it 'can be called without parameters' do
15
+ expect { described_class.new }.not_to raise_error
16
+ end
17
+ end # describe '#initialize'
18
+
19
+ describe '#define_message' do
20
+ it 'can be called with a symbol as the single paremter' do
21
+ expect { obj.define_message message }.not_to raise_error
22
+ end
23
+
24
+ it 'requires a single parameter (only)' do
25
+ expect(obj.method(:define_message).arity).to eq 1
26
+ end
27
+
28
+ it 'adds a new entry to the internal store' do
29
+ expect(obj.instance_variable_get(:@internals)).to be_empty
30
+ obj.define_message message
31
+ internals = obj.instance_variable_get :@internals
32
+ expect(internals.keys.length).to eq 1
33
+ end
34
+
35
+ describe 'adds a new' do
36
+ before :each do
37
+ obj.define_message message
38
+ @internals = obj.instance_variable_get :@internals
39
+ end
40
+
41
+ describe 'entry to the internal store that is' do
42
+ it 'Array-like' do
43
+ # Reminder: Array#to_ary is the IMPLICIT convert-to-Array method
44
+ expect(@internals[message]).to respond_to :to_ary
45
+ end
46
+
47
+ it 'initially empty' do
48
+ expect(@internals[message]).to be_empty
49
+ end
50
+
51
+ it 'keyed to the parameter-specified message' do
52
+ expect(@internals.keys).to include message
53
+ end
54
+ end # describe 'entry to the internal store that is'
55
+
56
+ it 'public query method to the class instance' do
57
+ query = "#{message}?".to_sym
58
+ expect { obj.method query }.not_to raise_error
59
+ method = obj.method query
60
+ expect(method.arity).to eq 0
61
+ end
62
+
63
+ it 'message-responder method to the class instance' do
64
+ expect { obj.method message }.not_to raise_error
65
+ method = obj.method message
66
+ expect(method.arity).to eq(-1)
67
+ end
68
+ end # describe 'adds a new'
69
+ end # describe '#define_message'
70
+
71
+ describe '#payload_for' do
72
+ it 'takes a single parameter' do
73
+ method = obj.method :payload_for
74
+ expect(method.arity).to eq 1
75
+ end
76
+
77
+ describe 'returns a no-payloads-received indicator when' do
78
+ let(:none_received) { [] }
79
+
80
+ after :each do
81
+ expect(obj.payload_for message).to eq none_received
82
+ end
83
+
84
+ it 'no messages have been defined' do
85
+ end
86
+
87
+ it 'other messages have been defined but this message has not been' do
88
+ obj.define_message other_message
89
+ end
90
+
91
+ it 'the specified message has been defined but not received' do
92
+ obj.define_message message
93
+ end
94
+ end # describe 'returns a no-payloads-received indicator when'
95
+
96
+ describe 'returns the payload(s) received for the specified message when' do
97
+ it 'payloads for that message have been stored' do
98
+ obj.define_message message
99
+ expected = 'testing'
100
+ obj.instance_variable_get(:@internals)[message].push expected
101
+ expect(obj.payload_for message).to eq Array.new([expected])
102
+ end
103
+ end # describe 'returns the payload(s) received for the ... message when'
104
+ end # describe '#payload_for'
105
+
106
+ describe '#respond_to?' do
107
+ it 'returns true for any query method' do
108
+ expect(obj).to respond_to :is_that_right?
109
+ expect(obj).to respond_to :you_dont_say?
110
+ expect(obj).to respond_to :all_tone_here?
111
+ end
112
+
113
+ it 'returns false for any other undefined method' do
114
+ expect(obj).not_to respond_to :taunts
115
+ expect(obj).not_to respond_to :threats
116
+ expect(obj).not_to respond_to :anything
117
+ end
118
+ end # describe '#respond_to?'
119
+
120
+ describe '.method_missing' do
121
+ it 'causes an unknown query method to return false' do
122
+ expect(obj).not_to be_success
123
+ expect(obj).not_to be_real
124
+ expect(obj).not_to be_anything_in_particular
125
+ end
126
+
127
+ it 'raises a NoMethodError for any other undefined method' do
128
+ message = Regexp.new 'undefined method `bogus\' for'
129
+ expect { obj.bogus }.to raise_error NoMethodError, message
130
+ end
131
+ end # describe '.method_missing'
132
+ end
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wisper_subscription/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wisper_subscription"
8
+ spec.version = WisperSubscription::VERSION
9
+ spec.authors = ["Jeff Dickey"]
10
+ spec.email = ["jdickey@seven-sigma.com"]
11
+ spec.summary = %q{Records and reports messages sent using Wisper conventions.}
12
+ spec.homepage = "https://github.com/jdickey/wisper_subscription"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec"
23
+
24
+ spec.add_development_dependency 'rubocop', '>= 0.28.0'
25
+ spec.add_development_dependency 'simplecov', '>= 0.9.1'
26
+ # spec.add_development_dependency 'awesome_print'
27
+ # spec.add_development_dependency 'pry-byebug'
28
+ # spec.add_development_dependency 'pry-doc'
29
+
30
+ spec.description = %q{May be used to subscribe to Wisper broadcasts, or other
31
+ similar mechanisms. Define what messages you want an instance to respond to and,
32
+ when those messages are received, any parameters or "payload" associated with
33
+ each single message is saved for later querying and retrieval. See the README for
34
+ more information.}
35
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisper_subscription
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Dickey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.28.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.28.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.1
83
+ description: |-
84
+ May be used to subscribe to Wisper broadcasts, or other
85
+ similar mechanisms. Define what messages you want an instance to respond to and,
86
+ when those messages are received, any parameters or "payload" associated with
87
+ each single message is saved for later querying and retrieval. See the README for
88
+ more information.
89
+ email:
90
+ - jdickey@seven-sigma.com
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - ".gitignore"
96
+ - ".rspec"
97
+ - ".travis.yml"
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - lib/wisper_subscription.rb
103
+ - lib/wisper_subscription/version.rb
104
+ - spec/spec_helper.rb
105
+ - spec/wisper_subscription_spec.rb
106
+ - wisper_subscription.gemspec
107
+ homepage: https://github.com/jdickey/wisper_subscription
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Records and reports messages sent using Wisper conventions.
131
+ test_files:
132
+ - spec/spec_helper.rb
133
+ - spec/wisper_subscription_spec.rb