test/merge_test.rb in frappuccino-0.2.0 vs test/merge_test.rb in frappuccino-0.3.0
- old
+ new
@@ -5,11 +5,11 @@
button_one = Button.new
button_two = Button.new
stream_one = Frappuccino::Stream.new(button_one)
stream_two = Frappuccino::Stream.new(button_two)
- merged_stream = to_array(Frappuccino::Stream.merge(stream_one, stream_two))
+ merged_stream = to_array(stream_one.merge(stream_two))
button_one.push
button_two.push
assert_equal 2, merged_stream.length
@@ -19,12 +19,11 @@
plus_button = PlusOneButton.new
minus_button = MinusOneButton.new
stream_one = Frappuccino::Stream.new(plus_button)
stream_two = Frappuccino::Stream.new(minus_button)
-
- merged_stream = Frappuccino::Stream.merge(stream_one, stream_two)
+ merged_stream = stream_one.merge(stream_two)
counter = merged_stream
.map do |event|
case event
when :+
1
@@ -48,6 +47,35 @@
assert_equal(-2, counter.now)
4.times { plus_button.push }
assert_equal 2, counter.now
end
+
+ it "works if the callee has a different constructor from Stream" do
+ button_one = Button.new
+ button_two = Button.new
+
+ stream_one = Frappuccino::Stream.new(button_one).map { 0 }
+ stream_two = Frappuccino::Stream.new(button_two)
+
+ # This would explode if the merge was calling
+ # self.class.new rather than Stream.new
+ stream_one.merge(stream_two)
+ end
end
+
+
+describe "merging stream with Frappuccino::Stream#merge" do
+ it "produces one stream with both sets of events" do
+ button_one = Button.new
+ button_two = Button.new
+
+ stream_one = Frappuccino::Stream.new(button_one)
+ stream_two = Frappuccino::Stream.new(button_two)
+ merged_stream = to_array(Frappuccino::Stream.merge(stream_one, stream_two))
+
+ button_one.push
+ button_two.push
+
+ assert_equal 2, merged_stream.length
+ end
+end
\ No newline at end of file