require 'spec_helper' require 'todos_export' require 'tempfile' describe TodosExport::Main do subject do TodosExport::Main.new('spec/resources') end context '#find_files' do it 'finds them' do subject.find_files subject.files.size.should == 3 end it 'clears when rerunning' do subject.find_files subject.files.size.should == 3 subject.find_files subject.files.size.should == 3 end end context '#find_exportables' do it 'finds them' do subject.find_exportables subject.exportables.size.should == 10 end it 'clears when rerunning' do subject.find_exportables subject.exportables.size.should == 10 subject.find_exportables subject.exportables.size.should == 10 end end it '#git_directory?' do TodosExport::Main.new('./').git_directory?.should be true TodosExport::Main.new(Dir.tmpdir).git_directory?.should be false end it '#git_head_sha' do TodosExport::Main.new('./').git_head_sha.should =~ /[0-9a-f]{5,40}/ end it '#delete_exportable' do copied_file = Tempfile.new('copy_of_ruby_file_with_todos.rb') copied_file.write(File.open('spec/resources/ruby_file_with_todos.rb', 'rb').read) copied_file.rewind s = TodosExport::Main.new(copied_file.path) lines = File.readlines(copied_file.path).size s.find_exportables s.exportables.size.should == 8 while !s.exportables.empty? do s.delete_exportable(s.exportables[0][:file], s.exportables[0][:line]) s.find_exportables end s.find_exportables s.exportables.size.should == 0 File.readlines(copied_file.path).size.should == (lines - 8) end it '#delete_exportables' do copied_file = Tempfile.new('copy_of_ruby_file_with_todos.rb') copied_file.write(File.open('spec/resources/ruby_file_with_todos.rb', 'rb').read) copied_file.rewind s = TodosExport::Main.new(copied_file.path) lines = File.readlines(copied_file.path).size s.find_exportables s.exportables.size.should == 8 s.delete_exportables s.find_exportables s.exportables.size.should == 0 File.readlines(copied_file.path).size.should == (lines - 8) end it '#exportables' do subject.find_exportables subject.exportable_todos + subject.exportable_fixmes + subject.exportable_bugs.each do |e| subject.exportables.should include e end end it '#exportable_todos' do subject.find_exportables exportable_todos = [ { :type => "TODO", :content => "Find a kinder message", :original_content => "#TODO: Find a kinder message", :file => 'spec/resources/ruby_file_with_todos.rb', :original_file => "spec/resources/ruby_file_with_todos.rb", :line => 12, :line_peek => 'puts "Pick a tasty cheese dammit"' }, { :type => "TODO", :content => "Make a list", :original_content => "# TODO: Make a list", :file => 'spec/resources/ruby_file_with_todos.rb', :original_file => "spec/resources/ruby_file_with_todos.rb", :line => 18, :line_peek => 'end' # This can be better }, { :type => "TODO", :content => "Add more cheese types", :original_content => "#todo: Add more cheese types", :file => 'spec/resources/ruby_file_with_todos.rb', :original_file => "spec/resources/ruby_file_with_todos.rb", :line => 26, :line_peek => 'return true' }, { :type => "TODO", :content => "Add more region cheeses", :original_content => "#todo Add more region cheeses", :file => 'spec/resources/ruby_file_with_todos.rb', :original_file => "spec/resources/ruby_file_with_todos.rb", :line => 35, :line_peek => 'return false' }, { :type => "TODO", :content => "Personalize the class to your taste", :original_content => "# TODO Personalize the class to your taste", :file => 'spec/resources/ruby_file_with_todos.rb', :original_file => "spec/resources/ruby_file_with_todos.rb", :line => 41, :line_peek => 'return true' }, { :type => "TODO", :content => "Be a better Ruby file", :original_content => "# TODO: Be a better Ruby file", :file => 'spec/resources/sub_directory/another_ruby_file_with_todos.rb', :original_file => "spec/resources/sub_directory/another_ruby_file_with_todos.rb", :line => 1, :line_peek => '# BUG: This should say it\'s a Ruby file' # this can be better } ] exportable_todos.each do |e| subject.exportable_todos.should include e end end it '#exportable_fixmes' do subject.find_exportables exportable_fixmes = [ { :type => "FIXME", :content => "This is a useless class, what we really need to do is sit down and eat some cheese", :original_content => "# fixme: This is a useless class, what we really need to do is sit down and eat some cheese", :file => 'spec/resources/ruby_file_with_todos.rb', :original_file => 'spec/resources/ruby_file_with_todos.rb', :line => 2, :line_peek => '# This is a class for cheeses' }, { :type => "FIXME", :content => "Use case statement", :original_content => "#FIXME: Use case statement", :file => 'spec/resources/ruby_file_with_todos.rb', :original_file => 'spec/resources/ruby_file_with_todos.rb', :line => 22, :line_peek => "if self.cheese == 'chedar'" } ] exportable_fixmes.each do |e| subject.exportable_fixmes.should include e end end it '#exportable_bugs' do subject.find_exportables exportable_bugs = [ { :type => "BUG", :content => "This should be false", :original_content => "# BUG: This should be false", :file => 'spec/resources/ruby_file_with_todos.rb', :original_file => 'spec/resources/ruby_file_with_todos.rb', :line => 46, :line_peek => 'return true' }, { :type => "BUG", :content => "This should say it's a Ruby file", :original_content => "# BUG: This should say it's a Ruby file", :file => 'spec/resources/sub_directory/another_ruby_file_with_todos.rb', :original_file => 'spec/resources/sub_directory/another_ruby_file_with_todos.rb', :line => 2, :line_peek => 'puts "I\'m a Perl file"' } ] exportable_bugs.each do |e| subject.exportable_bugs.should include e end end end