Sha256: 9d3e2a7d95666498ac9bd761d8814b2f48250071a1a26b1d3d2efc8f932d83e2
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
require 'spec_helper' describe Rambling::Trie do describe '.create' do let(:container) { double :container } before do allow(Rambling::Trie::Container).to receive(:new) .and_yield(container) .and_return container end it 'returns a new instance of the trie container' do expect(Rambling::Trie.create).to eq container end context 'with a block' do it 'yields the new container' do yielded_trie = nil Rambling::Trie.create { |trie| yielded_trie = trie } expect(yielded_trie).to eq container end end context 'with a filepath' do let(:filepath) { 'a test filepath' } let(:reader) { double :reader } let(:words) { %w(a couple of test words over here) } before do receive_and_yield = receive(:each_word) words.inject(receive_and_yield) { |yielder, word| yielder.and_yield word } allow(reader).to receive_and_yield allow(container).to receive :<< end it 'loads every word' do Rambling::Trie.create filepath, reader words.each do |word| expect(container).to have_received(:<<).with(word) end end end context 'without any reader' do let(:filepath) { 'a test filepath' } let(:reader) { double :reader, each_word: nil } before do allow(Rambling::Trie::PlainTextReader).to receive(:new) .and_return reader end it 'defaults to the PlainTextReader' do Rambling::Trie.create filepath, nil expect(reader).to have_received(:each_word).with filepath end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rambling-trie-0.9.3 | spec/lib/rambling/trie_spec.rb |