class SpecWatchr
Public Class Methods
new(watchr, options = {}) { || ... }
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 299 def initialize watchr, options = {} @default_options = { :enotify_port => 5000, :enotify_host => 'localhost', :notification_message => {:failure => "F", :success => "S", :pending => "P"}, :notification_face => { :failure => keyword(:failure), :success => keyword(:success), :pending => keyword(:warning)}, # custom_extract_summary_proc: takes the result text as argument # and returns an hash of the form # {:errors => #errors # :pending => #pending # :examples => #examples # :status => (:success|:failure|:pending) } :custom_extract_summary_proc => nil, :error_count_line => -1, # custom_matcher : takes two arguments: the path of the modified # file (CHECK) and an array of spec files. Returns an array of # matching spec files for the path given. :custom_matcher => nil } options = @default_options.merge(options) puts "========OPTIONS==========" puts options puts "=========================" @enotify_host = options[:enotify_host] @enotify_port = options[:enotify_port] @notification_message = options[:notification_message] @notification_face = options[:notification_face] @custom_extract_summary_proc = options[:custom_extract_summary_proc] @error_count_line = options[:error_count_line] @custom_matcher = options[:custom_matcher] yield if block_given? @enotify_slot_id = ((File.basename Dir.pwd).split('_').map { |s| s.capitalize }).join check_if_bundle_needed init_network @watchr = watchr watchr.watch('^spec/(.*)_spec\.rb$') {|m| rspec_files specs_for(m[1])} #watchr.watch('^(?:app|lib|script)/(.*)(?:\.rb|\.\w+|)$') {|m| rspec_files specs_for(m[1].gsub(/\.rb$/,''))} watchr.watch('^(?:app|lib|script)/(.*)(?:\.rb|\.\w+)$') {|m| rspec_files specs_for(m[1].gsub(/\.rb$/,''))} trap_int! puts '--- Waiting for changes...'.cyan end
Public Instance Methods
blank_string?(string)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 271 def blank_string?(string) string =~ /\A\s*\n?\z/ end
init_network()
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 287 def init_network begin print "=== Connecting to emacs... ".cyan @sock = TCPSocket.new(@enotify_host, @enotify_port) eregister puts "Success!".green rescue puts "Failed!".red rescue_sock_error end end
rescue_sock_error()
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 275 def rescue_sock_error print "--- Enter Enotify host [localhost:5000]: ".yellow host_and_port = STDIN.gets.strip if blank_string?(host_and_port) @enotify_host, @enotify_port = ['localhost', @default_options[:enotify_port]] else @enotify_host, @enotify_port = host_and_port.split(/\s:\s/) @enotify_port = @enotify_port.to_i end init_network end