Class: SpecWatchr
- Includes:
- CommandLine, Control, EmacsConnection, Specs
- Defined in:
- lib/rspec-rails-watchr-emacs.rb
Defined Under Namespace
Modules: CommandLine, Control, EmacsConnection, Specs
Instance Method Summary collapse
- #blank_string?(string) ⇒ Boolean
- #init_network ⇒ Object
-
#initialize(watchr, options = {}) ⇒ SpecWatchr
constructor
A new instance of SpecWatchr.
- #rescue_sock_error ⇒ Object
Methods included from EmacsConnection
#alist, #elispify_symbol, #eregister, #esend, #esend_results, #extract_rspec_counts, #extract_rspec_summary, #flatten, #format_help, #hash_to_esexp, #keyword, #object_to_esexp, #rspec_status
Methods included from Control
#abort_watchr!, #exit_watchr, #reload!, #reload_file_list, #trap_int!
Methods included from Specs
#check_if_bundle_needed, #default_rails_matcher, #match_specs, #rspec, #rspec_all, #rspec_command, #rspec_files, #rspec_send_results, #specs_for
Methods included from CommandLine
#clear!, #run, #terminal_columns
Constructor Details
#initialize(watchr, options = {}) ⇒ SpecWatchr
Returns a new instance of SpecWatchr.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/rspec-rails-watchr-emacs.rb', line 299 def initialize watchr, = {} @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 } = @default_options.merge() puts "========OPTIONS==========" puts puts "=========================" @enotify_host = [:enotify_host] @enotify_port = [:enotify_port] @notification_message = [:notification_message] @notification_face = [:notification_face] @custom_extract_summary_proc = [:custom_extract_summary_proc] @error_count_line = [:error_count_line] @custom_matcher = [: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 |
Instance Method Details
#blank_string?(string) ⇒ Boolean
271 272 273 |
# File 'lib/rspec-rails-watchr-emacs.rb', line 271 def blank_string?(string) string =~ /\A\s*\n?\z/ end |
#init_network ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 |
# 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 ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 |
# 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 |