Skip to content
Browse files

autosync/close files in specs even for mem storage

  • Loading branch information...
1 parent 6cc664d commit 03795003ae925546efc24a45b3bb5047d76b6c36 Yurii Rashkovskii committed May 24, 2008
Showing with 33 additions and 35 deletions.
  1. +33 −35 spec/spec_helper.rb
View
68 spec/spec_helper.rb
@@ -7,52 +7,50 @@
TEMP_STORAGES = TEMP_DIR + '/storages'
def setup_default_store(store=nil)
- if store
- StrokeDB.stub!(:default_store).and_return(store)
- return store
- end
- @path = TEMP_STORAGES
- FileUtils.rm_rf @path
+if store
+ StrokeDB.stub!(:default_store).and_return(store)
+ return store
+end
+@path = TEMP_STORAGES
+FileUtils.rm_rf @path
- @storage = if ENV['STORAGE'].to_s.downcase == 'file'
- StrokeDB::FileStorage.new(:path => @path + '/file_storage')
- else
- StrokeDB::MemoryStorage.new
- end
+@storage = if ENV['STORAGE'].to_s.downcase == 'file'
+ StrokeDB::FileStorage.new(:path => @path + '/file_storage')
+else
+ StrokeDB::MemoryStorage.new
+end
- $store = StrokeDB::Store.new(:storage => @storage,:index => @index, :path => @path)
- StrokeDB.stub!(:default_store).and_return($store)
- StrokeDB.default_store
+$store = StrokeDB::Store.new(:storage => @storage,:index => @index, :path => @path)
+StrokeDB.stub!(:default_store).and_return($store)
+StrokeDB.default_store
end
def stub_meta_in_store(store=nil)
- store ||= StrokeDB.default_store
- meta = store.find(NIL_UUID)
- store.should_receive(:find).with(NIL_UUID).any_number_of_times.and_return(meta)
- store.should_receive(:include?).with(NIL_UUID).any_number_of_times.and_return(true)
+store ||= StrokeDB.default_store
+meta = store.find(NIL_UUID)
+store.should_receive(:find).with(NIL_UUID).any_number_of_times.and_return(meta)
+store.should_receive(:include?).with(NIL_UUID).any_number_of_times.and_return(true)
end
def setup_index(store=nil)
- store ||= StrokeDB.default_store
- index_storage = StrokeDB::InvertedListFileStorage.new(:path => TEMP_STORAGES + '/inverted_list_storage')
- index_storage.clear!
- @index = StrokeDB::InvertedListIndex.new(index_storage)
- @index.document_store = store
- store.index_store = @index
- @index
+store ||= StrokeDB.default_store
+index_storage = StrokeDB::InvertedListFileStorage.new(:path => TEMP_STORAGES + '/inverted_list_storage')
+index_storage.clear!
+@index = StrokeDB::InvertedListIndex.new(index_storage)
+@index.document_store = store
+store.index_store = @index
+@index
end
Spec::Runner.configure do |config|
- config.after(:all) do
+config.after(:all) do
+
+ ObjectSpace.each_object do |obj|
+ obj.stop_autosync! if obj.is_a?(Store) rescue nil
+ end
- if ENV['STORAGE'].to_s.downcase == 'file'
- ObjectSpace.each_object do |obj|
- obj.stop_autosync! if obj.is_a?(Store)
- end
-
- ObjectSpace.each_object do |obj|
- obj.close if obj.is_a?(::File) rescue nil
- end
+ ObjectSpace.each_object do |obj|
+ obj.close if obj.is_a?(::File) rescue nil
end
- end
+end
end

0 comments on commit 0379500

Please sign in to comment.
Something went wrong with that request. Please try again.