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
|
# frozen_string_literal: true
# rubocop:todo all
require "spec_helper"
describe Mongo::Config do
shared_examples "a config option" do
before do
Mongo::Config.reset
end
context 'when the value is false' do
before do
Mongo.send("#{option}=", false)
end
it "is set to false" do
expect(Mongo.send(option)).to be(false)
end
end
context 'when the value is true' do
before do
Mongo.send("#{option}=", true)
end
it "is set to true" do
expect(Mongo.send(option)).to be(true)
end
end
context "when it is not set in the config" do
it "it is set to its default" do
expect(Mongo.send(option)).to be(default)
end
end
end
context 'when setting the validate_update_replace option in the config' do
let(:option) { :validate_update_replace }
let(:default) { false }
it_behaves_like "a config option"
end
describe "#options=" do
context "when an option" do
before do
described_class.options = { validate_update_replace: true }
end
it "assigns the option correctly" do
expect(described_class.validate_update_replace).to be true
end
end
context "when provided a non-existent option" do
it "raises an error" do
expect {
described_class.options = { bad_option: true }
}.to raise_error(Mongo::Error::InvalidConfigOption)
end
end
end
end
|