wisper-testing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4668832b4665bea0f8e3fee3daa2b29026b86689
4
+ data.tar.gz: 2f2c12b2acea21ac13676543ebd1c92b78799a22
5
+ SHA512:
6
+ metadata.gz: b43632d980a24170b43bdf2c0865cfc2960f2c3237d3b619ea73485430b907a8d4272f0723df8512a011ce67ea045064f822a7ea5ea45ce91c9297546e735134
7
+ data.tar.gz: ecb631fdc01454792b6c242576c910be3ef83bd79450f4dc454dbcc5851b5bf1cffc5fec5e8e872be575c9e8258750cbba6721ca0a98e6e68043039f8ef81ed5
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.4
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - '2.4.0'
5
+ before_install: gem install bundler
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "bundler", "~> 1.10"
6
+ gem "rake", "~> 10.0"
7
+ gem "rspec"
8
+ gem 'pry-byebug'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Kris Leech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Wisper::Testing
2
+
3
+ [![Build Status](https://travis-ci.org/krisleech/wisper-testing.svg?branch=master)](https://travis-ci.org/krisleech/wisper-testing)
4
+
5
+ Helpers for testing Wisper publisher/subscribers.
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ gem 'wisper-testing'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Using `fake!` and `fake` prevents any events from being broadcast.
16
+
17
+ Instead each event is recorded and can be inspected.
18
+
19
+ ```ruby
20
+ Wisper::Testing.fake!
21
+
22
+ Wisper::Testing.fake do
23
+ # ...
24
+ end
25
+
26
+ Wisper::Testing.events # => [...]
27
+ ```
28
+
29
+ ### Inline
30
+
31
+ Using `inline!` and `inline` ensures all events are broadcast using the default
32
+ broadcaster, meaning any subscribers which are subscribed with `async: true`
33
+ will not be called asynchronously, but synchronously.
34
+
35
+ ```ruby
36
+ Wisper::Testing.inline!
37
+
38
+ Wisper::Testing.inline do
39
+ # ...
40
+ end
41
+ ```
42
+
43
+ ### Restore
44
+
45
+ Using `restore!` will turn off `fake!` and `inline!` and restore the original
46
+ configuration.
47
+
48
+ It is not nessesary to call this if you are using the block variations
49
+ `fake` and `inline`.
50
+
51
+ ```ruby
52
+ Wisper::Testing.restore!
53
+ ```
54
+
55
+ ### Enabled
56
+
57
+ ```ruby
58
+ Wisper::Testing.enabled? # => true/false
59
+ ```
60
+
61
+ ## Development
62
+
63
+ ```
64
+ ls **/*.rb | entr -c bundle exec rspec
65
+ ```
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/krisleech/wisper-testing.
70
+
71
+ This project is intended to be a safe, welcoming space for collaboration, and
72
+ contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org)
73
+ code of conduct.
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
78
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wisper/testing"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,117 @@
1
+ require "wisper/testing/version"
2
+ require "wisper/testing/fake_broadcaster"
3
+ require "wisper/testing/inline_broadcaster"
4
+
5
+ module Wisper
6
+ class Testing
7
+ # Sets all broadcasters to FakeBroadcaster which does not broadcast any
8
+ # events to the subscriber.
9
+ #
10
+ # @return self
11
+ #
12
+ def self.fake!
13
+ store_original_broadcasters
14
+ Wisper.configuration.broadcasters.keys.each do |key, broadcaster|
15
+ Wisper.configuration.broadcasters[key] = FakeBroadcaster.new
16
+ end
17
+ is_enabled
18
+ self
19
+ end
20
+
21
+ # Sets all broadcasters to FakeBroadcaster which does not broadcast any
22
+ # events to the subscriber, for the duration of the block
23
+ #
24
+ # @return self
25
+ #
26
+ def self.fake
27
+ fake!
28
+ yield
29
+ restore!
30
+ self
31
+ end
32
+
33
+ # Sets all broadcasters to InlineBroadcaster which broadcasts event
34
+ # to the subscriber synchronously.
35
+ #
36
+ # @return self
37
+ #
38
+ def self.inline!
39
+ store_original_broadcasters
40
+ Wisper.configuration.broadcasters.keys.each do |key, broadcaster|
41
+ Wisper.configuration.broadcasters[key] = InlineBroadcaster.new
42
+ end
43
+ is_enabled
44
+ self
45
+ end
46
+
47
+ # Sets all broadcasters to InlineBroadcaster which broadcasts event
48
+ # to the subscriber synchronously.
49
+ #
50
+ # @return self
51
+ #
52
+ def self.inline
53
+ inline!
54
+ yield
55
+ restore!
56
+ self
57
+ end
58
+
59
+ # Restores the original broadcasters configuration
60
+ #
61
+ # @return self
62
+ #
63
+ def self.restore!
64
+ if enabled?
65
+ Wisper.configuration.broadcasters.clear
66
+ original_broadcasters.each do |key, broadcaster|
67
+ Wisper.configuration.broadcasters[key] = broadcaster
68
+ end
69
+ is_not_enabled
70
+ end
71
+ self
72
+ end
73
+
74
+ # Returns true when either fake! or inline! having been invoked and restore!
75
+ # has not subsequently been invoked.
76
+ #
77
+ # @return Boolean
78
+ #
79
+ def self.enabled?
80
+ !!@enabled
81
+ end
82
+
83
+ # Forget the original broadcaster configuration.
84
+ #
85
+ # This is only used in the specs of Wisper::Testing to get clean state.
86
+ #
87
+ # @api private
88
+ #
89
+ def self._forget
90
+ return unless original_broadcasters?
91
+ @enabled = false
92
+ @original_broadcasters = nil
93
+ end
94
+
95
+ private
96
+
97
+ def self.is_enabled
98
+ @enabled = true
99
+ end
100
+
101
+ def self.is_not_enabled
102
+ @enabled = false
103
+ end
104
+
105
+ def self.original_broadcasters
106
+ @original_broadcasters
107
+ end
108
+
109
+ def self.store_original_broadcasters
110
+ @original_broadcasters = Wisper.configuration.broadcasters.to_h.dup
111
+ end
112
+
113
+ def self.original_broadcasters?
114
+ !!original_broadcasters
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,9 @@
1
+ module Wisper
2
+ class Testing
3
+ class FakeBroadcaster
4
+ def broadcast(listener, publisher, event, args)
5
+ # no-op
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module Wisper
2
+ class Testing
3
+ class InlineBroadcaster < Wisper::Broadcasters::SendBroadcaster
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Wisper
2
+ class Testing
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wisper/testing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wisper-testing"
8
+ spec.version = Wisper::Testing::VERSION
9
+ spec.authors = ["Kris Leech"]
10
+ spec.email = ["kris.leech@gmail.com"]
11
+
12
+ spec.summary = "Helpers for testing Wisper publisher/subscribers."
13
+ spec.homepage = "https://github.com/krisleech/wisper-testing"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'wisper', '~>2.0'
22
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisper-testing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kris Leech
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wisper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description:
28
+ email:
29
+ - kris.leech@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".ruby-version"
37
+ - ".travis.yml"
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - lib/wisper/testing.rb
46
+ - lib/wisper/testing/fake_broadcaster.rb
47
+ - lib/wisper/testing/inline_broadcaster.rb
48
+ - lib/wisper/testing/version.rb
49
+ - wisper-testing.gemspec
50
+ homepage: https://github.com/krisleech/wisper-testing
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.6.8
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Helpers for testing Wisper publisher/subscribers.
74
+ test_files: []