Class: Guard::Bacon

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/bacon.rb

Constant Summary

Constants included from Guard

BACON_GUARD_VERSION

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ Bacon

Returns a new instance of Bacon.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/guard/bacon.rb', line 12

def initialize(watchers= [], options= {})
  super
  if options[:output]
    puts "Bacon: Using output #{options[:output]}."
    ::Bacon.extend(::Bacon::const_get(options[:output]))
  end
  
  if options[:backtrace]
    puts "Bacon: Limiting backtrace to #{options[:backtrace]} lines."
    ::Bacon.backtrace_size = options[:backtrace]
  end
end

Instance Method Details

#file_changed(path) ⇒ Object



80
81
82
83
# File 'lib/guard/bacon.rb', line 80

def file_changed(path)
  run_spec(path)
  puts ""
end

#reloadObject

Called on Ctrl-Z signal



36
37
38
# File 'lib/guard/bacon.rb', line 36

def reload
  true
end

#run_allObject

Called on Ctrl-\ signal This method should be principally used for long action like running all specs/tests/…



42
43
44
45
46
47
48
# File 'lib/guard/bacon.rb', line 42

def run_all
  Dir["specs/**/*_spec.rb"].each do |path|
    run_spec(path)
  end
  
  true
end

#run_on_changes(paths) ⇒ Object

Called on file(s) modifications



86
87
88
89
90
# File 'lib/guard/bacon.rb', line 86

def run_on_changes(paths)
  paths.each do |path|
    file_changed(path)
  end
end

#run_spec(path) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/guard/bacon.rb', line 50

def run_spec(path)
  if File.exists?(path)
     pid = Kernel.fork do
       puts "\n●●➤  Running spec: #{path}"
       counters = ::Bacon.run_file(path)
       # system "bundle exec bacon -o TestUnit #{path}"
       # {:installed_summary=>1, :specifications=>19, :depth=>0, :requirements=>30, :failed=>2, :errors => 1}
       
       all_specs = counters[:specifications]
       failed = counters[:failed].to_i + counters[:errors].to_i
       
       if failed > 0
         Notifier.notify("Specs: #{failed} Failures (#{all_specs} specs)",
             :image => :failed,
             :title => File.basename(path)
           )
       else
         Notifier.notify("Specs: OK (#{all_specs} specs)",
             :image => :success,
             :title => File.basename(path)
           )
       end
     end
     
     Process.wait(pid)
   else
     puts "spec not found: #{path}"
   end
end

#startObject



25
26
27
28
# File 'lib/guard/bacon.rb', line 25

def start
  puts "Guard::Bacon started."
  true
end

#stopObject

Called on Ctrl-C signal (when Guard quits)



31
32
33
# File 'lib/guard/bacon.rb', line 31

def stop
  true
end