require 'spec_helper' require 'moblues/reader/model' describe Moblues::Reader::Model do let(:model) { build(:model) } let(:model_resolver) { double(Moblues::Utils::ModelResolver) } let(:entity_reader) { double(Moblues::Reader::Entity) } let(:file_str) { < EOF } subject { described_class.new(resolver: model_resolver, reader: entity_reader) } before do allow(model_resolver).to receive(:resolve_model) allow(entity_reader).to receive(:entity) { build(:entity) } allow(File).to receive(:read) { file_str } end describe '#parse_model' do it 'resolves the model contents' do expect(model_resolver).to receive(:resolve_model).with('path') subject.model('path') end it 'maps the model' do expect(entity_reader).to receive(:entity).exactly(3).times subject.model('path') end it 'returns an array of entities' do expect(subject.model('path')).to eq([build(:entity), build(:entity), build(:entity)]) end it 'raises an assertion if path is nil' do expect { subject.model(nil) }.to raise_exception end end end