test/lib/vedeu/repositories/repository_test.rb in vedeu-0.4.13 vs test/lib/vedeu/repositories/repository_test.rb in vedeu-0.4.14

- old
+ new

@@ -37,40 +37,32 @@ it { instance.must_be_instance_of(Vedeu::Repository) } it { instance.instance_variable_get('@model').must_equal(model) } it { instance.instance_variable_get('@storage').must_equal(storage) } end - describe '#all' do - subject { instance.all } + describe '#find' do + subject { instance.find(model_name) } - it 'returns the whole repository' do - subject.must_equal(storage) + context 'when the model cannot be found' do + let(:model_name) { 'not_found' } + + it { subject.must_be_instance_of(NilClass) } end - end - describe '#each' do - subject { instance.each } + context 'when the model is found' do + let(:model_instance) { model.new('terbium') } - it { subject.must_be_instance_of(Enumerator) } - end + before { instance.store(model_instance) } - describe '#empty?' do - subject { instance.empty? } - - context 'when the storage is empty' do - it { subject.must_equal(true) } + it 'returns the stored model' do + subject.must_equal(model_instance) + end end - - context 'when the storage is not empty' do - let(:storage) { [:item] } - - it { subject.must_equal(false) } - end end - describe '#find' do - subject { instance.find(model_name) } + describe '#find!' do + subject { instance.find!(model_name) } context 'when the model cannot be found' do let(:model_name) { 'not_found' } it { proc { subject }.must_raise(ModelNotFound) } @@ -90,12 +82,10 @@ describe '#find_or_create' do let(:model_instance) { TestModel.new('niobium') } subject { instance.find_or_create(model_name) } - it { instance.find_or_create('zinc').must_be_instance_of(Vedeu::TestModel) } - context 'when the model exists' do let(:model_name) { 'niobium' } before { instance.store(model_instance) } @@ -117,11 +107,11 @@ end context 'when the storage is a Hash' do it 'returns a collection of the names of all the registered entities' do repo = RepositoriesTestClass.new - repo.add({ 'rutherfordium' => { name: 'rutherfordium' } }) + repo.add('rutherfordium' => { name: 'rutherfordium' }) repo.registered.must_equal(['rutherfordium']) end end @@ -161,11 +151,11 @@ RepositoriesTestClass.new.registered?('terbium').must_equal(false) end it 'returns false when the model is not registered' do repo = RepositoriesTestClass.new - repo.add({ name: 'samarium' }) + repo.add(name: 'samarium') repo.registered?('terbium').must_equal(false) end end @@ -195,19 +185,9 @@ end it 'returns the storage with the model removed' do subject.size.must_equal(1) end - end - end - - describe '#reset' do - it 'returns a Hash' do - instance.reset.must_be_instance_of(Hash) - end - - it 'resets the repository' do - instance.reset.must_equal({}) end end describe '#store' do subject { instance.store(model_instance) }