signal 1.0.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +4 -0
- data/.github/FUNDING.yml +4 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +38 -0
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ruby-tests.yml +53 -0
- data/.rubocop.yml +12 -0
- data/Gemfile +3 -1
- data/README.md +87 -43
- data/Rakefile +15 -1
- data/examples/activerecord_model.rb +14 -12
- data/examples/arguments.rb +4 -2
- data/examples/block_context.rb +8 -5
- data/examples/blocks.rb +6 -4
- data/examples/call.rb +23 -0
- data/examples/chain.rb +20 -18
- data/examples/listener.rb +6 -4
- data/lib/signal/extensions/active_record.rb +8 -6
- data/lib/signal/extensions/call.rb +5 -3
- data/lib/signal/listener.rb +4 -1
- data/lib/signal/mock.rb +51 -0
- data/lib/signal/version.rb +3 -1
- data/lib/signal.rb +11 -7
- data/signal.gemspec +39 -17
- metadata +99 -37
- data/.rspec +0 -1
- data/.travis.yml +0 -11
- data/CHANGELOG.md +0 -5
- data/spec/signal/activerecord_spec.rb +0 -132
- data/spec/signal/call_spec.rb +0 -18
- data/spec/signal/issues/2_spec.rb +0 -13
- data/spec/signal/listener_spec.rb +0 -8
- data/spec/signal/signal_spec.rb +0 -123
- data/spec/spec_helper.rb +0 -25
- data/spec/support/callable.rb +0 -10
- data/spec/support/emitter.rb +0 -9
- data/spec/support/observable.rb +0 -3
- data/spec/support/observable_with_call.rb +0 -13
- data/spec/support/user.rb +0 -4
data/spec/signal/signal_spec.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Signal do
|
4
|
-
let(:observable) { Observable.new }
|
5
|
-
let(:callable) { Callable.new }
|
6
|
-
|
7
|
-
context 'add listener' do
|
8
|
-
it 'runs listener' do
|
9
|
-
callable.respond_to(:on_ready)
|
10
|
-
observable.add_listener(callable)
|
11
|
-
expect(callable).to receive(:called).with(no_args)
|
12
|
-
|
13
|
-
observable.emit(:ready)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'returns itself' do
|
17
|
-
expect(observable.add_listener(callable)).to eq(observable)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'using blocks' do
|
22
|
-
it 'triggers event' do
|
23
|
-
observable.on(:ready, &callable)
|
24
|
-
expect(callable).to receive(:called).with(no_args)
|
25
|
-
|
26
|
-
observable.emit(:ready)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'triggers event with arguments' do
|
30
|
-
observable.on(:ready, &callable)
|
31
|
-
expect(callable).to receive(:called).with(1, 2, 3)
|
32
|
-
|
33
|
-
observable.emit(:ready, 1, 2, 3)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'triggers before event' do
|
37
|
-
observable.before(:ready, &callable)
|
38
|
-
expect(callable).to receive(:called).with(no_args)
|
39
|
-
|
40
|
-
observable.emit(:ready)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'triggers before event with arguments' do
|
44
|
-
observable.before(:ready, &callable)
|
45
|
-
expect(callable).to receive(:called).with(1, 2, 3)
|
46
|
-
|
47
|
-
observable.emit(:ready, 1, 2, 3)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'triggers after event' do
|
51
|
-
observable.after(:ready, &callable)
|
52
|
-
expect(callable).to receive(:called).with(no_args)
|
53
|
-
|
54
|
-
observable.emit(:ready)
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'triggers after event with arguments' do
|
58
|
-
observable.after(:ready, &callable)
|
59
|
-
expect(callable).to receive(:called).with(1, 2, 3)
|
60
|
-
|
61
|
-
observable.emit(:ready, 1, 2, 3)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'chains events' do
|
65
|
-
before_callable = Callable.new
|
66
|
-
on_callable = Callable.new
|
67
|
-
after_callable = Callable.new
|
68
|
-
|
69
|
-
observable
|
70
|
-
.before(:ready, &before_callable)
|
71
|
-
.on(:ready, &on_callable)
|
72
|
-
.after(:ready, &after_callable)
|
73
|
-
|
74
|
-
expect(before_callable).to receive(:called).with(no_args).ordered
|
75
|
-
expect(on_callable).to receive(:called).with(no_args).ordered
|
76
|
-
expect(after_callable).to receive(:called).with(no_args).ordered
|
77
|
-
|
78
|
-
observable.emit(:ready)
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'keeps context' do
|
82
|
-
context = nil
|
83
|
-
callable = -> { context = self }
|
84
|
-
observable.on(:ready, &callable)
|
85
|
-
observable.emit(:ready)
|
86
|
-
|
87
|
-
expect(context).to eql(self)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context 'using listeners' do
|
92
|
-
it 'triggers event for listener' do
|
93
|
-
callable.respond_to(:on_ready)
|
94
|
-
observable.listeners << callable
|
95
|
-
expect(callable).to receive(:called).with(no_args)
|
96
|
-
|
97
|
-
observable.emit(:ready)
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'triggers event for listener with arguments' do
|
101
|
-
callable.respond_to(:on_ready)
|
102
|
-
observable.listeners << callable
|
103
|
-
expect(callable).to receive(:called).with(1, 2, 3)
|
104
|
-
|
105
|
-
observable.emit(:ready, 1, 2, 3)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'mixed listeners' do
|
110
|
-
it 'calls all listeners' do
|
111
|
-
callable.respond_to(:on_ready)
|
112
|
-
another_callable = Callable.new
|
113
|
-
|
114
|
-
expect(callable).to receive(:called).ordered
|
115
|
-
expect(another_callable).to receive(:called).ordered
|
116
|
-
|
117
|
-
observable
|
118
|
-
.add_listener(callable)
|
119
|
-
.on(:ready, &another_callable)
|
120
|
-
.emit(:ready)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'codeclimate-test-reporter'
|
2
|
-
CodeClimate::TestReporter.start
|
3
|
-
|
4
|
-
require 'bundler/setup'
|
5
|
-
require 'active_record'
|
6
|
-
|
7
|
-
I18n.enforce_available_locales = false
|
8
|
-
|
9
|
-
require 'signal'
|
10
|
-
require 'support/observable'
|
11
|
-
require 'support/observable_with_call'
|
12
|
-
require 'support/callable'
|
13
|
-
require 'support/user'
|
14
|
-
require 'support/emitter'
|
15
|
-
|
16
|
-
ActiveRecord::Base.establish_connection({
|
17
|
-
:adapter => 'sqlite3',
|
18
|
-
:database => ':memory:'
|
19
|
-
})
|
20
|
-
|
21
|
-
ActiveRecord::Schema.define(:version => 0) do
|
22
|
-
create_table :users do |t|
|
23
|
-
t.string :username
|
24
|
-
end
|
25
|
-
end
|
data/spec/support/callable.rb
DELETED
data/spec/support/emitter.rb
DELETED
data/spec/support/observable.rb
DELETED
data/spec/support/user.rb
DELETED