spec/lib/rambling/trie/enumerable_spec.rb in rambling-trie-2.3.0 vs spec/lib/rambling/trie/enumerable_spec.rb in rambling-trie-2.3.1
- old
+ new
@@ -6,36 +6,44 @@
module Trie
describe Enumerable do
let(:node) { Rambling::Trie::Nodes::Raw.new }
let(:words) { %w(add some words and another word) }
- before do
- add_words node, words
- end
+ before { add_words node, words }
describe '#each' do
- it 'returns an enumerator' do
- expect(node.each).to be_a Enumerator
+ it 'returns an enumerator when no block is given' do
+ expect(node.each).to be_an Enumerator
end
+ it 'has the same word count as the trie' do
+ expect(node.count).to eq words.count
+ end
+
it 'includes every word contained in the trie' do
- node.each do |word|
- expect(words).to include word
- end
+ node.each { |word| expect(words).to include word }
+ end
- expect(node.count).to eq words.count
+ it 'returns the enumerable when a block is given' do
+ expect(node.each { |_| }).to eq node
end
end
describe '#size' do
it 'delegates to #count' do
expect(node.size).to eq words.size
end
end
- it 'includes the core Enumerable module' do
+ it 'includes #all? from the core Enumerable module' do
expect(node.all? { |word| words.include? word }).to be true
+ end
+
+ it 'includes #any? from the core Enumerable module' do
expect(node.any? { |word| word.start_with? 's' }).to be true
+ end
+
+ it 'includes #to_a from the core Enumerable module' do
expect(node.to_a).to match_array words
end
end
end
end