audible 0.2.0 → 0.4.0
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 +15 -0
- data/.document +5 -5
- data/.travis.yml +12 -12
- data/Gemfile +6 -6
- data/Gemfile.lock +64 -62
- data/LICENSE.txt +20 -20
- data/README.md +9 -9
- data/Rakefile +33 -41
- data/VERSION +1 -1
- data/audible.gemspec +69 -67
- data/lib/audible.rb +3 -3
- data/lib/audible/audible.rb +50 -42
- data/lib/audible/pidfile.rb +16 -16
- data/spec/spec_helper.rb +7 -7
- data/spec/system.tests/drb/bin/server +44 -44
- data/spec/system.tests/drb/drb_observers_spec.rb +65 -65
- data/spec/system.tests/drb/support/drb_server.rb +26 -26
- data/spec/{and_how_it_differs_from_observable_spec.rb → unit.tests/and_how_it_differs_from_observable_spec.rb} +101 -101
- data/spec/{examples → unit.tests/examples}/a_notifying_shell_spec.rb +28 -28
- data/spec/{examples → unit.tests/examples}/logging_as_notifications_spec.rb +51 -51
- data/spec/unit.tests/it_notifies_despite_errors_spec.rb +30 -0
- data/spec/{listening_spec.rb → unit.tests/listening_spec.rb} +53 -53
- data/spec/{relaying_notifications → unit.tests/relaying_notifications}/about_the_notifications_spec.rb +69 -69
- data/spec/{relaying_notifications → unit.tests/relaying_notifications}/can_relay_notifications_spec.rb +43 -43
- metadata +12 -22
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
class Shell
|
|
4
|
-
require "audible"; extend Audible
|
|
5
|
-
|
|
6
|
-
class << self
|
|
7
|
-
def exec(what)
|
|
8
|
-
require "open3"
|
|
9
|
-
Open3.popen2(what, :err => [:child, :out]) do |i,o,t|
|
|
10
|
-
o.each_line {|line| notify :progress, line}
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe "An audible shell" do
|
|
17
|
-
it "notifies for each line of output" do
|
|
18
|
-
result = StringIO.new
|
|
19
|
-
|
|
20
|
-
Shell.on :progress do |e, args|
|
|
21
|
-
result.puts args.first
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
Shell.exec "ls -a"
|
|
25
|
-
|
|
26
|
-
result.length.must be > 0
|
|
27
|
-
end
|
|
28
|
-
end
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
class Shell
|
|
4
|
+
require "audible"; extend Audible
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def exec(what)
|
|
8
|
+
require "open3"
|
|
9
|
+
Open3.popen2(what, :err => [:child, :out]) do |i,o,t|
|
|
10
|
+
o.each_line {|line| notify :progress, line}
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "An audible shell" do
|
|
17
|
+
it "notifies for each line of output" do
|
|
18
|
+
result = StringIO.new
|
|
19
|
+
|
|
20
|
+
Shell.on :progress do |e, args|
|
|
21
|
+
result.puts args.first
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
Shell.exec "ls -a"
|
|
25
|
+
|
|
26
|
+
result.length.must be > 0
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
class BusyBody
|
|
4
|
-
require "audible"; include Audible
|
|
5
|
-
|
|
6
|
-
def go
|
|
7
|
-
step_one
|
|
8
|
-
step_two
|
|
9
|
-
step_three
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
%w{one two three}.each do |name|
|
|
15
|
-
full_name = "step_#{name}".to_sym
|
|
16
|
-
|
|
17
|
-
define_method(full_name){ notify full_name }
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class LogSpy
|
|
22
|
-
attr_reader :messages
|
|
23
|
-
|
|
24
|
-
def initialize(what)
|
|
25
|
-
@messages = []
|
|
26
|
-
|
|
27
|
-
what.on :step_one do
|
|
28
|
-
@messages << "Step 1"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
what.on :step_two do
|
|
32
|
-
@messages << "Step 2"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
what.on :step_three do
|
|
36
|
-
@messages << "Step 3"
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe BusyBody, "and notifying instead of logging" do
|
|
42
|
-
it "attach the log by notification rather than as dependency" do
|
|
43
|
-
busy_body = BusyBody.new
|
|
44
|
-
|
|
45
|
-
log = LogSpy.new busy_body
|
|
46
|
-
|
|
47
|
-
busy_body.go
|
|
48
|
-
|
|
49
|
-
log.messages.must == ["Step 1", "Step 2", "Step 3"]
|
|
50
|
-
end
|
|
51
|
-
end
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
class BusyBody
|
|
4
|
+
require "audible"; include Audible
|
|
5
|
+
|
|
6
|
+
def go
|
|
7
|
+
step_one
|
|
8
|
+
step_two
|
|
9
|
+
step_three
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
%w{one two three}.each do |name|
|
|
15
|
+
full_name = "step_#{name}".to_sym
|
|
16
|
+
|
|
17
|
+
define_method(full_name){ notify full_name }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class LogSpy
|
|
22
|
+
attr_reader :messages
|
|
23
|
+
|
|
24
|
+
def initialize(what)
|
|
25
|
+
@messages = []
|
|
26
|
+
|
|
27
|
+
what.on :step_one do
|
|
28
|
+
@messages << "Step 1"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
what.on :step_two do
|
|
32
|
+
@messages << "Step 2"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
what.on :step_three do
|
|
36
|
+
@messages << "Step 3"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe BusyBody, "and notifying instead of logging" do
|
|
42
|
+
it "attach the log by notification rather than as dependency" do
|
|
43
|
+
busy_body = BusyBody.new
|
|
44
|
+
|
|
45
|
+
log = LogSpy.new busy_body
|
|
46
|
+
|
|
47
|
+
busy_body.go
|
|
48
|
+
|
|
49
|
+
log.messages.must == ["Step 1", "Step 2", "Step 3"]
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe "You always get notified, even when another listener fails" do
|
|
4
|
+
let(:an_audible_object) do
|
|
5
|
+
Class.new do
|
|
6
|
+
require "audible"; include Audible
|
|
7
|
+
|
|
8
|
+
def poke; notify :poked; end
|
|
9
|
+
end.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "notifies despite prior error, AND raises the error" do
|
|
13
|
+
notified = false
|
|
14
|
+
|
|
15
|
+
an_audible_object.on(:poked){|e,args| fail "This is supposed to fail" }
|
|
16
|
+
an_audible_object.on(:poked){|e,args| notified = true }
|
|
17
|
+
|
|
18
|
+
expect{an_audible_object.poke}.to raise_error /fail/
|
|
19
|
+
|
|
20
|
+
expect(notified).to be_true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "only raises the first error" do
|
|
24
|
+
an_audible_object.on(:poked){|e,args| fail "ERROR A" }
|
|
25
|
+
an_audible_object.on(:poked){|e,args| fail "ERROR B" }
|
|
26
|
+
an_audible_object.on(:poked){|e,args| fail "ERROR C" }
|
|
27
|
+
|
|
28
|
+
expect{an_audible_object.poke}.to raise_error /A/
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe "An audible object" do
|
|
4
|
-
let(:an_audible_object) do
|
|
5
|
-
an_audible_class = Class.new do
|
|
6
|
-
require "audible"; include Audible
|
|
7
|
-
|
|
8
|
-
def poke; notify :poked ; end
|
|
9
|
-
def tap ; notify :tapped; end
|
|
10
|
-
|
|
11
|
-
protected
|
|
12
|
-
|
|
13
|
-
def accepts?(e);
|
|
14
|
-
[:poked,:tapped].include? e
|
|
15
|
-
end
|
|
16
|
-
end.new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "notifies of the event I ask for" do
|
|
20
|
-
notified = false
|
|
21
|
-
|
|
22
|
-
an_audible_object.on :poked do
|
|
23
|
-
notified = true
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
an_audible_object.poke
|
|
27
|
-
|
|
28
|
-
notified.must be_true
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "fails if the event does not match a supported one" do
|
|
32
|
-
expect{an_audible_object.on(:xxx_does_not_exist_xxx){}}.to raise_error /Event .+ not supported/
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "fails without a block" do
|
|
36
|
-
expect{an_audible_object.on :tapped}.to raise_error /No block supplied. How will I notify you?/
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "you can subscribe to multiple events at once and receive multiple notifications" do
|
|
40
|
-
notifications = 0
|
|
41
|
-
|
|
42
|
-
an_audible_object.on(:poked, :tapped) do
|
|
43
|
-
notifications += 1
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
an_audible_object.poke
|
|
47
|
-
an_audible_object.tap
|
|
48
|
-
|
|
49
|
-
notifications.must === 2
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# TEST: what about notification order?
|
|
53
|
-
end
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe "An audible object" do
|
|
4
|
+
let(:an_audible_object) do
|
|
5
|
+
an_audible_class = Class.new do
|
|
6
|
+
require "audible"; include Audible
|
|
7
|
+
|
|
8
|
+
def poke; notify :poked ; end
|
|
9
|
+
def tap ; notify :tapped; end
|
|
10
|
+
|
|
11
|
+
protected
|
|
12
|
+
|
|
13
|
+
def accepts?(e);
|
|
14
|
+
[:poked,:tapped].include? e
|
|
15
|
+
end
|
|
16
|
+
end.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "notifies of the event I ask for" do
|
|
20
|
+
notified = false
|
|
21
|
+
|
|
22
|
+
an_audible_object.on :poked do
|
|
23
|
+
notified = true
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
an_audible_object.poke
|
|
27
|
+
|
|
28
|
+
notified.must be_true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "fails if the event does not match a supported one" do
|
|
32
|
+
expect{an_audible_object.on(:xxx_does_not_exist_xxx){}}.to raise_error /Event .+ not supported/
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "fails without a block" do
|
|
36
|
+
expect{an_audible_object.on :tapped}.to raise_error /No block supplied. How will I notify you?/
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "you can subscribe to multiple events at once and receive multiple notifications" do
|
|
40
|
+
notifications = 0
|
|
41
|
+
|
|
42
|
+
an_audible_object.on(:poked, :tapped) do
|
|
43
|
+
notifications += 1
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
an_audible_object.poke
|
|
47
|
+
an_audible_object.tap
|
|
48
|
+
|
|
49
|
+
notifications.must === 2
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# TEST: what about notification order?
|
|
53
|
+
end
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe "The relayed notifications" do
|
|
4
|
-
before :all do
|
|
5
|
-
an_audible_object = Class.new do
|
|
6
|
-
require "audible"; include Audible
|
|
7
|
-
|
|
8
|
-
def poke; notify :poked, {:a => "1", :b => "2"}; end
|
|
9
|
-
end.new
|
|
10
|
-
|
|
11
|
-
a_relaying_class = Class.new do
|
|
12
|
-
require "audible"; include Audible
|
|
13
|
-
|
|
14
|
-
def initialize(inner)
|
|
15
|
-
@inner = inner
|
|
16
|
-
relay @inner, :poked
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
a_relaying_object = a_relaying_class.new(an_audible_object)
|
|
21
|
-
|
|
22
|
-
a_relaying_object.on :poked do |e,args|
|
|
23
|
-
@relayed_notification,@relayed_args = e,args
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
an_audible_object.poke
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it ("notifies with the same name") { expect(@relayed_notification).to eql :poked }
|
|
30
|
-
it ("notifies with the same arguments") { expect(@relayed_args.first).to eql({:a => "1", :b => "2"}) }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe "You can rename the relayed notification to something else" do
|
|
34
|
-
let :an_audible_object do
|
|
35
|
-
Class.new do
|
|
36
|
-
require "audible"; include Audible
|
|
37
|
-
|
|
38
|
-
def poke; notify :poked; end
|
|
39
|
-
end.new
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
before do
|
|
43
|
-
a_relaying_class = Class.new do
|
|
44
|
-
require "audible"; include Audible
|
|
45
|
-
|
|
46
|
-
def initialize(inner)
|
|
47
|
-
relay inner, :poked, :as => :any_new_name
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
@a_relaying_object = a_relaying_class.new(an_audible_object)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "notifies with the new name and suppresses the original" do
|
|
55
|
-
@a_relaying_object.on :poked do |e,args|
|
|
56
|
-
fail "Expected the <:poked> notification to be suppressed"
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
@a_relaying_object.on :any_new_name do |e,args|
|
|
60
|
-
notified = true
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
notified = false
|
|
64
|
-
|
|
65
|
-
an_audible_object.poke
|
|
66
|
-
|
|
67
|
-
expect(:notified).to be_true, "Expected to be notified with <#{:any_new_name}>"
|
|
68
|
-
end
|
|
69
|
-
end
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe "The relayed notifications" do
|
|
4
|
+
before :all do
|
|
5
|
+
an_audible_object = Class.new do
|
|
6
|
+
require "audible"; include Audible
|
|
7
|
+
|
|
8
|
+
def poke; notify :poked, {:a => "1", :b => "2"}; end
|
|
9
|
+
end.new
|
|
10
|
+
|
|
11
|
+
a_relaying_class = Class.new do
|
|
12
|
+
require "audible"; include Audible
|
|
13
|
+
|
|
14
|
+
def initialize(inner)
|
|
15
|
+
@inner = inner
|
|
16
|
+
relay @inner, :poked
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
a_relaying_object = a_relaying_class.new(an_audible_object)
|
|
21
|
+
|
|
22
|
+
a_relaying_object.on :poked do |e,args|
|
|
23
|
+
@relayed_notification,@relayed_args = e,args
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
an_audible_object.poke
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it ("notifies with the same name") { expect(@relayed_notification).to eql :poked }
|
|
30
|
+
it ("notifies with the same arguments") { expect(@relayed_args.first).to eql({:a => "1", :b => "2"}) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "You can rename the relayed notification to something else" do
|
|
34
|
+
let :an_audible_object do
|
|
35
|
+
Class.new do
|
|
36
|
+
require "audible"; include Audible
|
|
37
|
+
|
|
38
|
+
def poke; notify :poked; end
|
|
39
|
+
end.new
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
before do
|
|
43
|
+
a_relaying_class = Class.new do
|
|
44
|
+
require "audible"; include Audible
|
|
45
|
+
|
|
46
|
+
def initialize(inner)
|
|
47
|
+
relay inner, :poked, :as => :any_new_name
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
@a_relaying_object = a_relaying_class.new(an_audible_object)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "notifies with the new name and suppresses the original" do
|
|
55
|
+
@a_relaying_object.on :poked do |e,args|
|
|
56
|
+
fail "Expected the <:poked> notification to be suppressed"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
@a_relaying_object.on :any_new_name do |e,args|
|
|
60
|
+
notified = true
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
notified = false
|
|
64
|
+
|
|
65
|
+
an_audible_object.poke
|
|
66
|
+
|
|
67
|
+
expect(:notified).to be_true, "Expected to be notified with <#{:any_new_name}>"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe "Relaying notifications" do
|
|
4
|
-
let(:an_audible_object) do
|
|
5
|
-
an_audible_class = Class.new do
|
|
6
|
-
require "audible"; include Audible
|
|
7
|
-
|
|
8
|
-
def poke; notify :poked ; end
|
|
9
|
-
def tap ; notify :tapped; end
|
|
10
|
-
|
|
11
|
-
protected
|
|
12
|
-
|
|
13
|
-
def accepts?(e);
|
|
14
|
-
[:poked,:tapped].include? e
|
|
15
|
-
end
|
|
16
|
-
end.new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
let(:a_relaying_class) do
|
|
20
|
-
Class.new do
|
|
21
|
-
require "audible"; include Audible
|
|
22
|
-
|
|
23
|
-
def initialize(inner)
|
|
24
|
-
@inner = inner
|
|
25
|
-
relay @inner, :poked
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "can be asked to relay requests" do
|
|
31
|
-
notified = false
|
|
32
|
-
|
|
33
|
-
a_relaying_object = a_relaying_class.new(an_audible_object)
|
|
34
|
-
|
|
35
|
-
a_relaying_object.on(:poked){ notified = true }
|
|
36
|
-
|
|
37
|
-
an_audible_object.poke
|
|
38
|
-
|
|
39
|
-
expect(notified).to be_true, "Expected the notification to have been relayed"
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "can be asked to rename the notification to something else"
|
|
43
|
-
end
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe "Relaying notifications" do
|
|
4
|
+
let(:an_audible_object) do
|
|
5
|
+
an_audible_class = Class.new do
|
|
6
|
+
require "audible"; include Audible
|
|
7
|
+
|
|
8
|
+
def poke; notify :poked ; end
|
|
9
|
+
def tap ; notify :tapped; end
|
|
10
|
+
|
|
11
|
+
protected
|
|
12
|
+
|
|
13
|
+
def accepts?(e);
|
|
14
|
+
[:poked,:tapped].include? e
|
|
15
|
+
end
|
|
16
|
+
end.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
let(:a_relaying_class) do
|
|
20
|
+
Class.new do
|
|
21
|
+
require "audible"; include Audible
|
|
22
|
+
|
|
23
|
+
def initialize(inner)
|
|
24
|
+
@inner = inner
|
|
25
|
+
relay @inner, :poked
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "can be asked to relay requests" do
|
|
31
|
+
notified = false
|
|
32
|
+
|
|
33
|
+
a_relaying_object = a_relaying_class.new(an_audible_object)
|
|
34
|
+
|
|
35
|
+
a_relaying_object.on(:poked){ notified = true }
|
|
36
|
+
|
|
37
|
+
an_audible_object.poke
|
|
38
|
+
|
|
39
|
+
expect(notified).to be_true, "Expected the notification to have been relayed"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "can be asked to rename the notification to something else"
|
|
43
|
+
end
|