spec/stream_spec.rb in eventus-0.2.0 vs spec/stream_spec.rb in eventus-0.3.0
- old
+ new
@@ -1,11 +1,12 @@
require 'spec_helper'
describe Eventus::Stream do
let(:id) { UUID.generate(:compact) }
- let(:stream) { Eventus::Stream.new(id, persistence) }
+ let(:stream) { Eventus::Stream.new(id, persistence, dispatcher) }
let(:persistence) { stub(:persistence).as_null_object }
+ let(:dispatcher) { stub(:dispatcher).as_null_object }
it "should use id" do
stream.id.should == id
end
@@ -31,24 +32,37 @@
end
end
describe "when events added" do
before do
- stream << stub
- stream.add stub
+ stream.add "french"
+ stream.add "bread"
end
it "should have uncommitted events" do
stream.uncommitted_events.length.should == 2
end
describe "when committed" do
before do
persistence.should_receive(:commit)
+ dispatcher.should_receive(:dispatch)
stream.commit
end
+ it "should have timestamp on committed events" do
+ stream.committed_events.all?{ |e| e['time'] }.should == true
+ end
+
+ it "should have stream id on committed events" do
+ stream.committed_events.all?{ |e| e['sid'] }.should == true
+ end
+
+ it "should have sequence id on committed events" do
+ stream.committed_events.all?{ |e| e['sequence'] }.should == true
+ end
+
it "should have committed events" do
stream.version.should == 2
end
it "should have no uncommitted events" do
@@ -58,10 +72,10 @@
end
describe "when a concurrency error occurs" do
before do
persistence.should_receive(:commit).and_raise(Eventus::ConcurrencyError)
- stream << stub(:event)
+ stream.add "butter"
end
it "should reraise concurrency error" do
lambda {stream.commit}.should raise_error(Eventus::ConcurrencyError)
end