File tree 2 files changed +38
-7
lines changed 2 files changed +38
-7
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,8 @@ def has_observers?
31
31
32
32
# Gets the current value or throws an exception.
33
33
def value
34
- gate . synchronize do
35
- self . check_unsubscribed
34
+ gate . synchronize do
35
+ check_unsubscribed
36
36
raise @error if @error
37
37
@value
38
38
end
@@ -41,8 +41,8 @@ def value
41
41
# Notifies all subscribed observers about the end of the sequence.
42
42
def on_completed
43
43
os = nil
44
- @gate . synchronize do
45
- self . check_unsubscribed
44
+ @gate . synchronize do
45
+ check_unsubscribed
46
46
47
47
unless @stopped
48
48
os = @observers . clone
@@ -60,7 +60,7 @@ def on_error(error)
60
60
61
61
os = nil
62
62
@gate . synchronize do
63
- self . check_unsubscribed
63
+ check_unsubscribed
64
64
65
65
unless @stopped
66
66
os = @observers . clone
@@ -77,7 +77,7 @@ def on_error(error)
77
77
def on_next ( value )
78
78
os = nil
79
79
@gate . synchronize do
80
- self . check_unsubscribed
80
+ check_unsubscribed
81
81
@value = value
82
82
os = @observers . clone unless @stopped
83
83
end
@@ -91,7 +91,7 @@ def subscribe(observer)
91
91
92
92
err = nil
93
93
gate . synchronize do
94
- self . check_unsubscribed
94
+ check_unsubscribed
95
95
96
96
unless @stopped
97
97
observers . push ( observer )
Original file line number Diff line number Diff line change
1
+ # Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
+
3
+ require 'test_helper'
4
+
5
+ class TestBehaviorSubject < Minitest ::Test
6
+ def test_subscriber_notified_on_change
7
+ value = 0
8
+ subject = Rx ::BehaviorSubject . new 0
9
+ subject . as_observable . subscribe { |update | value = update }
10
+ subject . on_next 1
11
+ assert_equal 1 , value
12
+ end
13
+
14
+ def test_multiple_observers_notified_on_change
15
+ value1 = 0
16
+ value2 = 0
17
+ subject = Rx ::BehaviorSubject . new 0
18
+ subject . as_observable . subscribe { |update | value1 = update }
19
+ subject . as_observable . subscribe { |update | value2 = update }
20
+ subject . on_next 1
21
+ assert_equal 1 , value1
22
+ assert_equal 1 , value2
23
+ end
24
+
25
+ def test_errors_on_next_when_unsubscribed
26
+ subject = Rx ::BehaviorSubject . new 0
27
+ subject . as_observable . subscribe { }
28
+ subject . unsubscribe
29
+ assert_raises ( RuntimeError ) { subject . on_next 1 }
30
+ end
31
+ end
You can’t perform that action at this time.
0 commit comments