module SpecWatchr::EmacsConnection
Public Instance Methods
alist(hash)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 35 def alist (hash) hash.merge(:magic_convert_to => :alist) end
elispify_symbol(symbol)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 44 def elispify_symbol(symbol) symbol.to_s.gsub(/_/,'-') end
eregister()
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 131 def eregister esend :register => @enotify_slot_id, :handler_fn => :enotify_rspec_result_message_handler end
esend(object)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 82 def esend (object) msg = object_to_esexp object @sock.puts("|#{msg.length}|#{msg}") # @sock.print("|#{msg.length}|") # sleep 2 # @sock.puts msg end
esend_results(results)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 137 def esend_results(results) summ = extract_rspec_summary(results) status = summ[:status] message = { :id => @enotify_slot_id, :notification => { :text => @notification_message[status], :face => @notification_face[status], :help => format_help(summ), :mouse_1 => :enotify_rspec_mouse_1_handler}, :data => results, } esend message end
extract_rspec_counts(results, line)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 100 def extract_rspec_counts(results, line) err_line = results.split("\n")[line] err_regex = /^(\d*)\sexamples?,\s(\d*)\s(errors?|failures?)[^\d]*((\d*)\spending)?/ _, examples, errors, _, pending = (err_line.match err_regex).to_a summ = { :examples => examples.to_i, :errors => errors.to_i, :pending => pending.to_i } summ.merge(:status => rspec_status(summ)) end
extract_rspec_summary(results)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 108 def extract_rspec_summary(results) case @custom_extract_summary_proc when Proc @custom_extract_summary_proc.call(results) else begin extract_rspec_counts(results, @error_count_line) rescue puts "--- Error while matching error counts.".red print "--- Summary line number: ".yellow @error_count_line = STDIN.gets.to_i extract_rspec_summary results end end end
flatten(hash)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 38 def flatten (hash) hash.merge(:magic_convert_to => :flat) end
format_help(summary)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 124 def format_help(summary) h = "#{summary[:errors]} errors\n" h << ("#{summary[:pending]} pending\n" if summary[:pending]>0).to_s h << "\nmouse-1: switch to result buffer" end
hash_to_esexp(hash)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 47 def hash_to_esexp (hash) h = hash.clone h.delete(:magic_convert_to) case hash[:magic_convert_to] when :alist res = h.map { |k, v| "(#{object_to_esexp k} . #{object_to_esexp v})" } "(#{res.join(' ')})" when :flat res = h.map { |k, v| "#{object_to_esexp k} #{object_to_esexp v}" } "(#{res.join(' ')})" else if hash.keys.reduce(true) { |base, el| base && Symbol === el } res = h.map { |k, v| "#{object_to_esexp keyword(k)} #{object_to_esexp v}" } "(#{res.join(' ')})" else h[:magic_convert_to] = :alist hash_to_esexp h end end end
keyword(symbol)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 41 def keyword (symbol) :"#{symbol.inspect}" end
object_to_esexp(object)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 67 def object_to_esexp (object) case object when String object.inspect when Array res = object.map { |el| object_to_esexp(el) } "(#{res.join(' ')})" when Symbol elispify_symbol(object) when Hash hash_to_esexp object else object.to_s end end
rspec_status(err_cnt)
click to toggle source
# File lib/rspec-rails-watchr-emacs.rb, line 90 def rspec_status(err_cnt) if err_cnt[:errors] > 0 :failure elsif err_cnt[:pending] > 0 :pending else :success end end