Class: Spectator::ERunner

Inherits:
Runner
  • Object
show all
Includes:
Emacs, Specs
Defined in:
lib/spectator/emacs.rb

Overview

This is the class that implements the main loop of spectator-emacs. To run spectator-emacs, just create a new ERunner object.

Constant Summary

Constants included from Emacs

Spectator::Emacs::VERSION

Instance Method Summary collapse

Methods included from Emacs

#blank_string?, #enotify_connect, #enotify_notify, #enotify_register, #enotify_send, #format_tooltip, #rescue_sock_error

Methods included from Specs

#check_if_bundle_needed, #extract_rspec_stats, #extract_rspec_summary, #rspec, #rspec_send_results, #rspec_status, #run, #send_error

Constructor Details

#initialize(options = {}) {|ERunner| ... } ⇒ ERunner

Creates a new instance of ERunner. This implements the main loop of spectator-emacs. See the README for examples on how to customize the default behavior.

Parameters:

  • options (Hash) (defaults to: {})

    possible options are:

    :enotify_port (Fixnum)

    the port the Enotify host is listening to.

    :enotify_host`(String)

    the host name or IP address where Enotify is running.

    :notification_messages (Hash)

    a hash with keys :success, :failure, :pending containing the relative modeline icons strings. Defaults to {:success => "S", :failure => "F", :pending => "P"}.

    :notification_face (Hash)

    A hash table with keys :success, :failure, :pending containing the faces to apply to the notification icon in the Emacs modeline. Values must be Symbols, like for example :font_lock_constant_face in order to use Emacs' font-lock-warning-face.

    :report_buffer_mode (String)

    The major mode to use for the report buffer on emacs. It must be specified in the same way as an emacs magic comment, i.e. without the trailing "-mode". For example, if you are using RspecOrgFormatter, and you want to use org-mode to display the report, specify "org". Defaults to

       {:success => :\':success\', :failure => :\':failure\', :pending => :\':warning\'}
    

Yields:

  • (ERunner)

    Gives a reference of the ERunner object just created to the block Use this block when you need to customize the behavior of spectator-emacs. For example, if you need a custom summary extraction method, you can create the runner object as follows in your .spectator-emacs script:

    @runner = ERunner.new do |runner|
      def runner.extract_rspec_summary(output)
        ## your summary extraction code here
        ## ...
      end
    end
    


447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/spectator/emacs.rb', line 447

def initialize(options={}, &block)
  @default_options = {
    :enotify_port => 5000,
    :enotify_host => 'localhost',
    :notification_messages => {:failure => "F", :success => "S", :pending => "P", :error => "E"},
    :notification_face => {
      :failure => :failure.keyword,
      :success => :success.keyword,
      :pending => :warning.keyword,
      :error   => :error
    }
  }
  options = @default_options.merge options
  @cli_args = ARGV.to_a
  puts "======= OPTIONS ======="
  options.each {|k, v| puts "#{k} => #{v}"}
  @enotify_host = options[:enotify_host]
  @report_buffer_mode = options[:report_buffer_mode]
  @enotify_port = options[:enotify_port]
  @notification_messages = options[:notification_messages]
  @notification_face = options[:notification_face]
  @enotify_slot_id = options[:slot_id] ||
    ((File.basename Dir.pwd).split('_').map {|s| s.capitalize}).join.gsub('-','/')
  check_if_bundle_needed
  enotify_connect
  yield self  if block_given?
  # TODO: load .spectator-emacs
  # contents = File::read('.spectator-emacs')
  # eval(contents)
  super()
end