spec/lib/indexing/bundle_spec.rb in picky-3.2.0 vs spec/lib/indexing/bundle_spec.rb in picky-3.3.0
- old
+ new
@@ -1,22 +1,22 @@
require 'spec_helper'
-describe Picky::Indexing::Bundle do
+describe Picky::Bundle do
before(:each) do
@index = Picky::Index.new :some_index
@category = Picky::Category.new :some_category, @index
@similarity = Picky::Similarity::DoubleMetaphone.new 3
end
let(:bundle) { described_class.new :some_name, @category, Picky::Backends::Memory.new, :some_weights, :some_partial, @similarity }
-
+
describe 'identifier' do
it 'is correct' do
bundle.identifier.should == 'test:some_index:some_category:some_name'
end
end
-
+
describe 'similar' do
before(:each) do
bundle.similarity = @similarity.generate_from( :dragon => [1,2,3], :dargon => [4,5,6] )
end
it 'returns the right similars (not itself)' do
@@ -30,33 +30,33 @@
end
it 'performs' do
performance_of { bundle.similar(:trkn) }.should < 0.00006
end
end
-
+
describe 'raise_cache_missing' do
it 'does something' do
expect {
bundle.raise_cache_missing :similarity
}.to raise_error("Error: The similarity cache for test:some_index:some_category:some_name is missing.")
end
end
-
+
describe 'warn_cache_small' do
it 'warns the user' do
bundle.should_receive(:warn).once.with "Warning: similarity cache for test:some_index:some_category:some_name smaller than 16 bytes."
-
+
bundle.warn_cache_small :similarity
end
end
-
+
describe 'identifier' do
it 'should return a specific identifier' do
bundle.identifier.should == 'test:some_index:some_category:some_name'
end
end
-
+
describe 'initialize_index_for' do
context 'token not yet assigned' do
before(:each) do
bundle.stub! :index => {}
end
@@ -75,57 +75,56 @@
bundle.index[:some_token].should == :already_assigned
end
end
end
-
+
describe 'retrieve' do
before(:each) do
prepared = stub :prepared
prepared.should_receive(:retrieve).once.and_yield ' 1234', :some_token
bundle.stub! :prepared => prepared
-
+
@ary = stub :ary
inverted = stub :inverted, :[] => @ary
bundle.stub! :inverted => inverted
end
context 'id key format' do
before(:each) do
@category.stub! :key_format => :to_i
end
it 'should call the other methods correctly' do
@ary.should_receive(:<<).once.with 1234
-
+
bundle.retrieve
end
end
context 'other key format' do
before(:each) do
@category.stub! :key_format => :strip
end
it 'should call the other methods correctly' do
@ary.should_receive(:<<).once.with '1234'
-
+
bundle.retrieve
end
end
context 'no key format - default' do
before(:each) do
@category.stub! :key_format => nil
end
it 'should call the other methods correctly' do
@ary.should_receive(:<<).once.with 1234
-
+
bundle.retrieve
end
end
end
describe 'load_from_index_file' do
it 'should call two methods in order' do
bundle.should_receive(:load_from_prepared_index_generation_message).once.ordered
- bundle.should_receive(:clear).once.ordered
bundle.should_receive(:retrieve).once.ordered
bundle.load_from_prepared_index_file
end
end
@@ -154,29 +153,29 @@
bundle.should_receive(:generate_caches_from_memory).once.ordered
bundle.generate_caches_from_source
end
end
-
+
describe 'dump' do
it 'should trigger dumps' do
bundle.stub! :timed_exclaim
-
+
bundle.should_receive(:dump_inverted).once.with
bundle.should_receive(:dump_weights).once.with
bundle.should_receive(:dump_similarity).once.with
bundle.should_receive(:dump_configuration).once.with
-
+
bundle.dump
end
end
describe 'raise_unless_cache_exists' do
it "calls methods in order" do
bundle.should_receive(:raise_unless_index_exists).once.ordered
bundle.should_receive(:raise_unless_similarity_exists).once.ordered
-
+
bundle.raise_unless_cache_exists
end
end
describe 'raise_unless_index_exists' do
context 'partial strategy saved' do
@@ -185,11 +184,11 @@
bundle.stub! :partial_strategy => strategy
end
it "calls the methods in order" do
bundle.should_receive(:warn_if_index_small).once.ordered
bundle.should_receive(:raise_unless_index_ok).once.ordered
-
+
bundle.raise_unless_index_exists
end
end
context 'partial strategy not saved' do
before(:each) do
@@ -197,11 +196,11 @@
bundle.stub! :partial_strategy => strategy
end
it "calls nothing" do
bundle.should_receive(:warn_if_index_small).never
bundle.should_receive(:raise_unless_index_ok).never
-
+
bundle.raise_unless_index_exists
end
end
end
describe 'raise_unless_similarity_exists' do
@@ -211,11 +210,11 @@
bundle.stub! :similarity_strategy => strategy
end
it "calls the methods in order" do
bundle.should_receive(:warn_if_similarity_small).once.ordered
bundle.should_receive(:raise_unless_similarity_ok).once.ordered
-
+
bundle.raise_unless_similarity_exists
end
end
context 'similarity strategy not saved' do
before(:each) do
@@ -223,11 +222,11 @@
bundle.stub! :similarity_strategy => strategy
end
it "calls nothing" do
bundle.should_receive(:warn_if_similarity_small).never
bundle.should_receive(:raise_unless_similarity_ok).never
-
+
bundle.raise_unless_similarity_exists
end
end
end
describe 'warn_if_similarity_small' do
@@ -235,21 +234,21 @@
before(:each) do
bundle.stub! :backend_similarity => stub(:backend_similarity, :cache_small? => true)
end
it "warns" do
bundle.should_receive(:warn_cache_small).once.with :similarity
-
+
bundle.warn_if_similarity_small
end
end
context "files similarity cache not small" do
before(:each) do
bundle.stub! :backend_similarity => stub(:backend_similarity, :cache_small? => false)
end
it "does not warn" do
bundle.should_receive(:warn_cache_small).never
-
+
bundle.warn_if_similarity_small
end
end
end
describe 'raise_unless_similarity_ok' do
@@ -257,26 +256,26 @@
before(:each) do
bundle.stub! :backend_similarity => stub(:backend_similarity, :cache_ok? => true)
end
it "warns" do
bundle.should_receive(:raise_cache_missing).never
-
+
bundle.raise_unless_similarity_ok
end
end
context "files similarity cache not ok" do
before(:each) do
bundle.stub! :backend_similarity => stub(:backend_similarity, :cache_ok? => false)
end
it "does not warn" do
bundle.should_receive(:raise_cache_missing).once.with :similarity
-
+
bundle.raise_unless_similarity_ok
end
end
end
-
+
describe 'initialization' do
it 'should initialize the index correctly' do
bundle.inverted.should == {}
end
it 'should initialize the weights index correctly' do
@@ -296,7 +295,7 @@
# end
it 'should initialize the similarity strategy correctly' do
bundle.similarity_strategy.should == @similarity
end
end
-
+
end
\ No newline at end of file