Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'spec'
- require 'spec/autorun'
- @watches = []
- def watch(matcher, &block)
- @watches << Matcher.new(matcher, &block)
- end
- def do_a_loop(sender, arg)
- puts "found a #{arg.change_type} with #{arg.name}"
- @watches.each {|w| w.do_if_matched arg.name }
- end
- def start_watching
- watcher = System::IO::FileSystemWatcher.new
- watcher.path = "."
- watcher.include_subdirectories = true
- watcher.notify_filter = System::IO::NotifyFilters.last_write | System::IO::NotifyFilters.file_name | System::IO::NotifyFilters.directory_name
- # watcher.changed do |s,a|
- # do_a_loop s, a
- # end
- watcher.created do |s,a|
- do_a_loop s, a
- end
- # watcher.deleted do |s,a|
- # do_a_loop s, a
- # end
- # watcher.renamed do |s,a|
- # do_a_loop s, a
- # end
- watcher.enable_raising_events = true
- puts "pres 'q' to quit."
- while "q" != System::Console.read
- end
- end
- class Matcher
- def initialize(matcher, &block)
- @matcher = Regexp.compile(matcher)
- @block = block
- end
- def do_if_matched(arg)
- matches = @matcher.match arg
- if not matches.nil?
- if matches.size == 1
- @block.call arg
- else
- @block.call matches[1]
- end
- end
- end
- end
- watch( 'lib\\\\(.*)\\.rb' ) do |md|
- puts "Running specs because of #{md}"
- puts "spec spec\\#{md}_spec.rb"
- system "spec spec\\#{md}_spec.rb"
- end
- watch( 'spec\\\\(.*)_spec.rb') do |md|
- puts "Running specs because of specs"
- system("spec spec\\#{md}_spec.rb")
- end
- start_watching()
Add Comment
Please, Sign In to add comment