Module: Cuprum::Collections::RSpec::Contracts::RelationContracts::ShouldDefineCardinalityContract
- Extended by:
- RSpec::SleepingKingStudios::Contract
- Defined in:
- lib/cuprum/collections/rspec/contracts/relation_contracts.rb
Overview
Contract validating a Relation’s cardinality properties.
Instance Method Summary collapse
-
#apply(example_group) ⇒ Object
Adds the contract to the example group.
Instance Method Details
#apply(example_group) ⇒ Object
Adds the contract to the example group.
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 |
# File 'lib/cuprum/collections/rspec/contracts/relation_contracts.rb', line 1190 contract do describe '.new' do describe 'with plural: an Object' do let(:constructor_options) do super().merge(plural: Object.new.freeze) end let(:error_message) do 'plural must be true or false' end it 'should raise an exception' do expect { described_class.new(**) } .to raise_error ArgumentError, end end describe 'with singular: an Object' do let(:constructor_options) do super().merge(singular: Object.new.freeze) end let(:error_message) do 'singular must be true or false' end it 'should raise an exception' do expect { described_class.new(**) } .to raise_error ArgumentError, end end describe 'with singular: nil and plural: value' do let(:constructor_options) do super().merge(plural: true, singular: nil) end it 'should not raise an exception' do expect { described_class.new(**) } .not_to raise_error end end describe 'with singular: value and plural: nil' do let(:constructor_options) do super().merge(plural: nil, singular: true) end it 'should not raise an exception' do expect { described_class.new(**) } .not_to raise_error end end describe 'with singular: value and plural: value' do let(:constructor_options) do super().merge(singular: true, plural: false) end let(:error_message) do 'ambiguous cardinality: initialized with parameters ' \ 'plural: false and singular: true' end it 'should raise an exception' do expect { described_class.new(**) } .to raise_error ArgumentError, end end end describe '#plural?' do include_examples 'should define predicate', :plural?, true context 'when initialized with plural: false' do let(:constructor_options) { super().merge(plural: false) } it { expect(subject.plural?).to be false } end context 'when initialized with plural: true' do let(:constructor_options) { super().merge(plural: true) } it { expect(subject.plural?).to be true } end context 'when initialized with singular: false' do let(:constructor_options) { super().merge(singular: false) } it { expect(subject.plural?).to be true } end context 'when initialized with singular: true' do let(:constructor_options) { super().merge(singular: true) } it { expect(subject.plural?).to be false } end end describe '#singular?' do include_examples 'should define predicate', :singular?, false context 'when initialized with plural: false' do let(:constructor_options) { super().merge(plural: false) } it { expect(subject.singular?).to be true } end context 'when initialized with plural: true' do let(:constructor_options) { super().merge(plural: true) } it { expect(subject.singular?).to be false } end context 'when initialized with singular: false' do let(:constructor_options) { super().merge(singular: false) } it { expect(subject.singular?).to be false } end context 'when initialized with singular: true' do let(:constructor_options) { super().merge(singular: true) } it { expect(subject.singular?).to be true } end end end |