wisper-testing-compat 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 42d457a75de89cf0184bf042299d5dbdc3a73e1fe31919c336973505b5ae5fb0
4
+ data.tar.gz: 74acefb5b9454a740ef4c38f530a6b9ba04a7199c5bd5b840cd98e74e965a34c
5
+ SHA512:
6
+ metadata.gz: ee42cf2afd6c46ccb36e7d69de81d290189720d25d328e290fe5c0b002cc91dfa8f73c34132cd907ad81c542eea6980fd3ffced5f50d28213f299d10c78add34
7
+ data.tar.gz: c2c988c2a014c21e4ec263f736696bf339cb539a3ac38d219a8bb782b5d464f13f772b7fbeb02c8f780b27ea6f85545d8e8e0e5c03456b78900f4013c81e3e0f
@@ -0,0 +1,27 @@
1
+ name: Test
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+
9
+ env:
10
+ RAILS_ENV: test
11
+
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ['3.0', '3.1', '3.2']
15
+
16
+ steps:
17
+ - name: Checkout
18
+ uses: actions/checkout@v3
19
+
20
+ - name: Setup Ruby
21
+ uses: ruby/setup-ruby@master
22
+ with:
23
+ bundler-cache: true
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+
26
+ - name: Run tests
27
+ run: bundle exec rspec spec
data/.gitignore ADDED
@@ -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
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.1
data/.travis.yml ADDED
@@ -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,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "rake"
6
+ gem "rspec"
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -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
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -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
data/bin/setup ADDED
@@ -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,9 @@
1
+ module Wisper
2
+ class Testing
3
+ class FakeBroadcaster
4
+ def broadcast(_listener, _publisher, _event, *_args, **_kwargs)
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 = "2.0.0"
4
+ end
5
+ end
@@ -0,0 +1,152 @@
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
+
18
+ store_global_broadcasters
19
+ Wisper::GlobalListeners.registrations.each do |registration|
20
+ registration.instance_variable_set("@broadcaster", FakeBroadcaster.new)
21
+ end
22
+
23
+ is_enabled
24
+ self
25
+ end
26
+
27
+
28
+ # Sets all broadcasters to FakeBroadcaster which does not broadcast any
29
+ # events to the subscriber, for the duration of the block
30
+ #
31
+ # @return self
32
+ #
33
+ def self.fake
34
+ fake!
35
+ yield
36
+ restore!
37
+ self
38
+ end
39
+
40
+ # Sets all broadcasters to InlineBroadcaster which broadcasts event
41
+ # to the subscriber synchronously.
42
+ #
43
+ # @return self
44
+ #
45
+ def self.inline!
46
+ store_original_broadcasters
47
+ Wisper.configuration.broadcasters.keys.each do |key, broadcaster|
48
+ Wisper.configuration.broadcasters[key] = InlineBroadcaster.new
49
+ end
50
+
51
+ store_global_broadcasters
52
+ Wisper::GlobalListeners.registrations.each do |registration|
53
+ registration.instance_variable_set("@broadcaster", InlineBroadcaster.new)
54
+ end
55
+
56
+ is_enabled
57
+ self
58
+ end
59
+
60
+ # Sets all broadcasters to InlineBroadcaster which broadcasts event
61
+ # to the subscriber synchronously.
62
+ #
63
+ # @return self
64
+ #
65
+ def self.inline
66
+ inline!
67
+ yield
68
+ restore!
69
+ self
70
+ end
71
+
72
+ # Restores the original broadcasters configuration
73
+ #
74
+ # @return self
75
+ #
76
+ def self.restore!
77
+ if enabled?
78
+ Wisper.configuration.broadcasters.clear
79
+ original_broadcasters.each do |key, broadcaster|
80
+ Wisper.configuration.broadcasters[key] = broadcaster
81
+ end
82
+
83
+ Wisper::GlobalListeners.registrations.each do |registration|
84
+ registration.instance_variable_set("@broadcaster", global_broadcaster_for(registration))
85
+ end
86
+
87
+ is_not_enabled
88
+ end
89
+ self
90
+ end
91
+
92
+ # Returns true when either fake! or inline! having been invoked and restore!
93
+ # has not subsequently been invoked.
94
+ #
95
+ # @return Boolean
96
+ #
97
+ def self.enabled?
98
+ !!@enabled
99
+ end
100
+
101
+ # Forget the original broadcaster configuration.
102
+ #
103
+ # This is only used in the specs of Wisper::Testing to get clean state.
104
+ #
105
+ # @api private
106
+ #
107
+ def self._forget
108
+ return unless original_broadcasters?
109
+ @enabled = false
110
+ @original_broadcasters = nil
111
+ end
112
+
113
+ private
114
+
115
+ def self.is_enabled
116
+ @enabled = true
117
+ end
118
+
119
+ def self.is_not_enabled
120
+ @enabled = false
121
+ end
122
+
123
+ def self.original_broadcasters
124
+ @original_broadcasters
125
+ end
126
+
127
+ def self.global_broadcasters
128
+ @global_broadcasters
129
+ end
130
+
131
+ def self.global_broadcaster_for(registration)
132
+ global_broadcasters[[registration.listener, registration.on]]
133
+ end
134
+
135
+ def self.store_original_broadcasters
136
+ @original_broadcasters = Wisper.configuration.broadcasters.to_h.dup
137
+ end
138
+
139
+ def self.store_global_broadcasters
140
+ @global_broadcasters = Wisper::GlobalListeners.registrations.map do |registration|
141
+ key = [registration.listener, registration.on]
142
+ val = registration.broadcaster
143
+
144
+ [key, val]
145
+ end.to_h
146
+ end
147
+
148
+ def self.original_broadcasters?
149
+ !!original_broadcasters
150
+ end
151
+ end
152
+ 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-compat"
8
+ spec.version = Wisper::Testing::VERSION
9
+ spec.authors = ["Kris Leech", "Jamie Schembri"]
10
+ spec.email = ["kris.leech@gmail.com", "jamie.schembri@nedap.com"]
11
+
12
+ spec.summary = "Helpers for testing Wisper-Compat publisher/subscribers."
13
+ spec.homepage = "https://github.com/nedap/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-compat'
22
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisper-testing-compat
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kris Leech
8
+ - Jamie Schembri
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2023-02-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: wisper-compat
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description:
29
+ email:
30
+ - kris.leech@gmail.com
31
+ - jamie.schembri@nedap.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".github/workflows/ci.yml"
37
+ - ".gitignore"
38
+ - ".rspec"
39
+ - ".ruby-version"
40
+ - ".travis.yml"
41
+ - CODE_OF_CONDUCT.md
42
+ - Gemfile
43
+ - LICENSE.txt
44
+ - README.md
45
+ - Rakefile
46
+ - bin/console
47
+ - bin/setup
48
+ - lib/wisper/testing.rb
49
+ - lib/wisper/testing/fake_broadcaster.rb
50
+ - lib/wisper/testing/inline_broadcaster.rb
51
+ - lib/wisper/testing/version.rb
52
+ - wisper-testing.gemspec
53
+ homepage: https://github.com/nedap/wisper-testing
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.4.6
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Helpers for testing Wisper-Compat publisher/subscribers.
76
+ test_files: []