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
24
# File 'lib/guard/bacon.rb', line 12

def initialize(watchers= [], options= {})
  @last_run_spec = nil
  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



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

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

#reloadObject

Called on Ctrl-Z signal



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

def reload
  true
end

#run_allObject

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



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

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



94
95
96
97
98
# File 'lib/guard/bacon.rb', line 94

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

#run_spec(path) ⇒ Object



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
79
80
81
82
83
84
85
86
# File 'lib/guard/bacon.rb', line 51

def run_spec(path)
  if !File.exists?(path) && @last_run_spec
    puts "spec not found: #{path}"
    puts "running last one."
    path = @last_run_spec
  end
  
  if File.exists?(path)
    @last_run_spec = 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



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

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

#stopObject

Called on Ctrl-C signal (when Guard quits)



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

def stop
  true
end