spec/mongo/session_spec.rb in mongo-2.17.4 vs spec/mongo/session_spec.rb in mongo-2.18.0.beta1
- old
+ new
@@ -266,10 +266,25 @@
expect do
session.session_id
end.to raise_error(Mongo::Error::SessionEnded)
end
end
+
+ context "when the sesion is not materialized" do
+ let(:session) { authorized_client.get_session(implicit: true) }
+
+ before do
+ expect(session.materialized?).to be false
+ end
+
+ it "raises SessionNotMaterialized" do
+
+ expect do
+ session.session_id
+ end.to raise_error(Mongo::Error::SessionNotMaterialized)
+ end
+ end
end
describe '#txn_num' do
it 'returns an integer' do
expect(session.txn_num).to be_a(Integer)
@@ -310,25 +325,25 @@
end
end
end
describe '#start_session' do
- context 'when block doesn\'t raise an error' do
- it 'closes the session after the block' do
+ context 'when block doesn\'t raise an error' do
+ it 'closes the session after the block' do
block_session = nil
- authorized_client.start_session do |session|
+ authorized_client.start_session do |session|
expect(session.ended?).to be false
- block_session = session
+ block_session = session
end
expect(block_session.ended?).to be true
end
end
context 'when block raises an error' do
it 'closes the session after the block' do
block_session = nil
- expect do
+ expect do
authorized_client.start_session do |session|
block_session = session
raise 'This is an error!'
end
end.to raise_error(StandardError, 'This is an error!')
@@ -336,13 +351,18 @@
end
end
context 'when block returns value' do
it 'is returned by the function' do
- res = authorized_client.start_session do |session|
+ res = authorized_client.start_session do |session|
4
end
expect(res).to be 4
end
+ end
+
+ it 'returns a session with session id' do
+ session = authorized_client.start_session
+ session.session_id.should be_a(BSON::Document)
end
end
end