spec/lib/index/files_spec.rb in picky-0.12.1 vs spec/lib/index/files_spec.rb in picky-0.12.2

- old
+ new

@@ -1,21 +1,22 @@ require 'spec_helper' describe Index::Files do before(:each) do - @index = stub :index, :name => :some_index - @category = stub :category, :name => :some_category - @configuration = Configuration::Index.new @index, @category + index = stub :index, :name => :some_index + category = stub :category, :name => :some_category + configuration = Configuration::Index.new index, category - @files = Index::Files.new :some_name, @configuration + @files = Index::Files.new :some_name, configuration @prepared = @files.prepared @index = @files.index - @similarity = @files.similarity @weights = @files.weights + @similarity = @files.similarity + @configuration = @files.configuration end describe "retrieve" do it "delegates to the prepared" do @prepared.should_receive(:retrieve).once.with @@ -30,22 +31,29 @@ @index.should_receive(:dump).once.with :some_hash @files.dump_index :some_hash end end + describe "dump_weights" do + it "uses the right file" do + @weights.should_receive(:dump).once.with :some_hash + + @files.dump_weights :some_hash + end + end describe "dump_similarity" do it "uses the right file" do @similarity.should_receive(:dump).once.with :some_hash @files.dump_similarity :some_hash end end - describe "dump_weights" do + describe "dump_configuration" do it "uses the right file" do - @weights.should_receive(:dump).once.with :some_hash + @configuration.should_receive(:dump).once.with :some_hash - @files.dump_weights :some_hash + @files.dump_configuration :some_hash end end end describe "loading indexes" do @@ -59,100 +67,112 @@ File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_index.json', 'r' @files.load_index end end + describe "load_weights" do + it "uses the right file" do + Yajl::Parser.stub! :parse + + File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_weights.json', 'r' + + @files.load_weights + end + end describe "load_similarity" do it "uses the right file" do Marshal.stub! :load File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_similarity.dump', 'r:binary' @files.load_similarity end end - describe "load_weights" do + describe "load_configuration" do it "uses the right file" do Yajl::Parser.stub! :parse - File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_weights.json', 'r' + File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_configuration.json', 'r' - @files.load_weights + @files.load_configuration end end end describe "dump indexes" do describe "index_cache_ok?" do - it "uses the right method" do + it 'uses the right method' do @index.should_receive(:cache_ok?).once.with @files.index_cache_ok? end end - describe "similarity_cache_ok?" do - it "uses the right method" do - @similarity.should_receive(:cache_ok?).once.with - - @files.similarity_cache_ok? - end - end describe "weights_cache_ok?" do - it "uses the right method" do + it 'uses the right method' do @weights.should_receive(:cache_ok?).once.with @files.weights_cache_ok? end end + describe "similarity_cache_ok?" do + it 'uses the right method' do + @similarity.should_receive(:cache_ok?).once.with + + @files.similarity_cache_ok? + end + end end - describe "dump indexes" do - describe "index_cache_small?" do - it "uses the right method" do + describe 'dump indexes' do + describe 'index_cache_small?' do + it 'uses the right method' do @index.should_receive(:cache_small?).once.with @files.index_cache_small? end end - describe "similarity_cache_small?" do - it "uses the right method" do - @similarity.should_receive(:cache_small?).once.with + describe 'weights_cache_small?' do + it 'uses the right method' do + @weights.should_receive(:cache_small?).once.with - @files.similarity_cache_small? + @files.weights_cache_small? end end - describe "weights_cache_small?" do - it "uses the right method" do - @weights.should_receive(:cache_small?).once.with + describe 'similarity_cache_small?' do + it 'uses the right method' do + @similarity.should_receive(:cache_small?).once.with - @files.weights_cache_small? + @files.similarity_cache_small? end end end describe 'backup' do it 'should call backup on all' do @index.should_receive(:backup).once.with - @similarity.should_receive(:backup).once.with @weights.should_receive(:backup).once.with + @similarity.should_receive(:backup).once.with + @configuration.should_receive(:backup).once.with @files.backup end end describe 'restore' do it 'should call delete on all' do @index.should_receive(:restore).once.with - @similarity.should_receive(:restore).once.with @weights.should_receive(:restore).once.with + @similarity.should_receive(:restore).once.with + @configuration.should_receive(:restore).once.with @files.restore end end describe 'delete' do it 'should call delete on all' do @index.should_receive(:delete).once.with - @similarity.should_receive(:delete).once.with @weights.should_receive(:delete).once.with + @similarity.should_receive(:delete).once.with + @configuration.should_receive(:delete).once.with @files.delete end end \ No newline at end of file