Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Various ConversionObserver methods handling files to check.

.files_to_check is a simple attr reader
Adding a file to check appends it to the array and ensures there are no duplicates
Clearing the array is only there as a convenience for testing
  • Loading branch information...
commit bbdca94b019bdaee119114c463c29fdc335a56f8 1 parent 2ec5533
@ymendel authored
Showing with 52 additions and 0 deletions.
  1. +11 −0 lib/conversion_observer.rb
  2. +41 −0 spec/conversion_observer_spec.rb
View
11 lib/conversion_observer.rb
@@ -1,8 +1,10 @@
module ConversionObserver
@files_to_convert = []
+ @files_to_check = []
class << self
attr_reader :files_to_convert
+ attr_reader :files_to_check
def add_file_to_convert(file)
@files_to_convert << file
@@ -13,12 +15,21 @@ def file_to_convert
files_to_convert.shift
end
+ def add_file_to_check(file)
+ @files_to_check << file
+ @files_to_check.uniq!
+ end
+
private
def clear_files_to_convert
@files_to_convert = []
end
+
+ def clear_files_to_check
+ @files_to_check = []
+ end
end
end
View
41 spec/conversion_observer_spec.rb
@@ -68,4 +68,45 @@
end
end
end
+
+ it 'should have files to check' do
+ ConversionObserver.should respond_to(:files_to_check)
+ end
+
+ it 'should add a file to check' do
+ ConversionObserver.should respond_to(:add_file_to_check)
+ end
+
+ describe 'files to check' do
+ it 'should default to an empty array' do
+ ConversionObserver.files_to_check.should == []
+ end
+
+ describe 'when added' do
+ before :each do
+ ConversionObserver.send(:clear_files_to_check)
+ end
+
+ it 'should be in the returned array' do
+ @file = stub('file')
+ ConversionObserver.add_file_to_check(@file)
+ ConversionObserver.files_to_check.should == [@file]
+ end
+
+ it 'should add to the end of the array' do
+ @file = stub('file')
+ @other_file = stub('other file')
+ ConversionObserver.add_file_to_check(@file)
+ ConversionObserver.add_file_to_check(@other_file)
+ ConversionObserver.files_to_check.should == [@file, @other_file]
+ end
+
+ it 'should remove duplicates' do
+ @file = stub('file')
+ ConversionObserver.add_file_to_check(@file)
+ ConversionObserver.add_file_to_check(@file)
+ ConversionObserver.files_to_check.should == [@file]
+ end
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.