#!/usr/bin/env ruby require 'fssm' def display value end if ARGV.include? '--verbose' def display value puts value end end def run_all_specs specs = Dir['**/*_spec.rb*'].select { |f| File.file?(f) }.map do |x| File.expand_path(x) end run_these_specs specs end def run_these_specs specs requires = specs.map { |x| "require '#{x}'" }.join("\n") display "Specs to run: #{specs.inspect}" puts `ruby -e "#{requires}"` end def add_it(file, files) return if file.index('.git') == 0 display "Adding: #{file}" files << file end def run_it(file, files) filename = file.downcase.split('/')[-1].gsub('_spec', '') display "File to run is: #{file}" display "Filename: #{filename}" matches = files.select { |x| x.gsub('_spec.rb', '.rb').include?(filename) && x != file } matches << file specs = matches.select! { |x| x.include?('_spec') && File.file?(x) }.map { |x| File.expand_path x } display "Matches: #{specs.inspect}" run_these_specs specs end def delete_it(file, files) return if file.index('.git') == 0 display "Deleting: #{file}" files.delete(file) end if ARGV.include? '--watch' files = Dir['**/*'] location = File.expand_path(File.dirname(Dir['**/*_spec.rb*'].first)) FSSM.monitor(location, '**/*') do update {|base, relative| run_it relative, files } delete {|base, relative| delete_it relative, files } create {|base, relative| add_it relative, files } end else run_all_specs end