1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
require 'spec_helper'
describe Mongo::Error::Parser do
describe '#message' do
let(:parser) do
described_class.new(document)
end
context 'when the document contains no error message' do
let(:document) do
{ 'ok' => 1 }
end
it 'returns an empty string' do
expect(parser.message).to be_empty
end
end
context 'when the document contains an errmsg' do
let(:document) do
{ 'errmsg' => 'no such command: notacommand', 'code'=>59 }
end
it 'returns the message' do
expect(parser.message).to eq('no such command: notacommand (59)')
end
end
context 'when the document contains writeErrors' do
context 'when only a single error exists' do
let(:document) do
{ 'writeErrors' => [{ 'code' => 9, 'errmsg' => 'Unknown modifier: $st' }]}
end
it 'returns the message' do
expect(parser.message).to eq('Unknown modifier: $st (9)')
end
end
context 'when multiple errors exist' do
let(:document) do
{
'writeErrors' => [
{ 'code' => 9, 'errmsg' => 'Unknown modifier: $st' },
{ 'code' => 9, 'errmsg' => 'Unknown modifier: $bl' }
]
}
end
it 'returns the messages concatenated' do
expect(parser.message).to eq(
'Unknown modifier: $st (9), Unknown modifier: $bl (9)'
)
end
end
end
context 'when the document contains $err' do
let(:document) do
{ '$err' => 'not authorized for query', 'code' => 13 }
end
it 'returns the message' do
expect(parser.message).to eq('not authorized for query (13)')
end
end
context 'when the document contains err' do
let(:document) do
{ 'err' => 'not authorized for query', 'code' => 13 }
end
it 'returns the message' do
expect(parser.message).to eq('not authorized for query (13)')
end
end
context 'when the document contains a writeConcernError' do
let(:document) do
{ 'writeConcernError' => { 'code' => 100, 'errmsg' => 'Not enough data-bearing nodes' } }
end
it 'returns the message' do
expect(parser.message).to eq('Not enough data-bearing nodes (100)')
end
end
end
end
|