Class: Guard::Kitchen

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/kitchen.rb,
lib/guard/kitchen/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Kitchen

Returns a new instance of Kitchen.



23
24
25
26
27
# File 'lib/guard/kitchen.rb', line 23

def initialize(options = {})
  super
  # you can still access the watchers with options[:watchers]
  # rest of the implementation...
end

Instance Method Details

#reloadObject



59
60
61
62
# File 'lib/guard/kitchen.rb', line 59

def reload
  stop
  start
end

#run_allObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/guard/kitchen.rb', line 64

def run_all
  ::Guard::UI.info("Guard::Kitchen is running all tests")
  cmd = Mixlib::ShellOut.new("kitchen verify", :timeout => 10800)
  cmd.live_stream = STDOUT
  cmd.run_command
  begin
    cmd.error!
    Notifier.notify('Kitchen verify succeeded', :title => 'test-kitchen', :image => :success)
    ::Guard::UI.info("Kitchen verify succeeded")
  rescue Mixlib::ShellOut::ShellCommandFailed => e
    Notifier.notify('Kitchen verify failed', :title => 'test-kitchen', :image => :failed)
    ::Guard::UI.info("Kitchen verify failed with #{e.to_s}")
    throw :task_has_failed
  end
end

#run_on_changes(paths) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/guard/kitchen.rb', line 80

def run_on_changes(paths)
  suites = {}
  paths.each do |path|
    if path =~ /test\/integration\/(.+?)\/.+/
      suites[$1] = true
    end
  end
  if suites.length > 0
    ::Guard::UI.info("Guard::Kitchen is running suites: #{suites.keys.join(', ')}")
    cmd = Mixlib::ShellOut.new("kitchen verify '(#{suites.keys.join('|')})-.+' -p", :timeout => 10800)
    cmd.live_stream = STDOUT
    cmd.run_command
    begin
      cmd.error!
      Notifier.notify("Kitchen verify succeeded for: #{suites.keys.join(', ')}", :title => 'test-kitchen', :image => :success)
      ::Guard::UI.info("Kitchen verify succeeded for: #{suites.keys.join(', ')}")
    rescue Mixlib::ShellOut::ShellCommandFailed => e
      Notifier.notify("Kitchen verify failed for: #{suites.keys.join(', ')}", :title => 'test-kitchen', :image => :failed)
      ::Guard::UI.info("Kitchen verify failed with #{e.to_s}")
      throw :task_has_failed
    end
  else
    ::Guard::UI.info("Guard::Kitchen is running converge for all suites")
    cmd = Mixlib::ShellOut.new("kitchen converge", :timeout => 10800)
    cmd.live_stream = STDOUT
    cmd.run_command
    begin
      cmd.error!
      Notifier.notify("Kitchen converge succeeded", :title => 'test-kitchen', :image => :success)
      ::Guard::UI.info("Kitchen converge succeeded")
    rescue Mixlib::ShellOut::ShellCommandFailed => e
      Notifier.notify("Kitchen converge failed", :title => 'test-kitchen', :image => :failed)
      ::Guard::UI.info("Kitchen converge failed with #{e.to_s}")
      throw :task_has_failed
    end
  end
end

#startObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/guard/kitchen.rb', line 29

def start
  ::Guard::UI.info("Guard::Kitchen is starting")
  cmd = Mixlib::ShellOut.new("kitchen create", :timeout => 10800)
  cmd.live_stream = STDOUT
  cmd.run_command
  begin
    cmd.error!
    Notifier.notify('Kitchen created', :title => 'test-kitchen', :image => :success)
  rescue Mixlib::ShellOut::ShellCommandFailed => e
    Notifier.notify('Kitchen create failed', :title => 'test-kitchen', :image => :failed)
    ::Guard::UI.info("Kitchen failed with #{e.to_s}")
    throw :task_has_failed
  end
end

#stopObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/guard/kitchen.rb', line 44

def stop
  ::Guard::UI.info("Guard::Kitchen is stopping")
  cmd = Mixlib::ShellOut.new("kitchen destroy", :timeout => 10800)
  cmd.live_stream = STDOUT
  cmd.run_command
  begin
   cmd.error!
   Notifier.notify('Kitchen destroyed', :title => 'test-kitchen', :image => :success)
  rescue Mixlib::ShellOut::ShellCommandFailed => e
    Notifier.notify('Kitchen destroy failed', :title => 'test-kitchen', :image => :failed)
   ::Guard::UI.info("Kitchen failed with #{e.to_s}")
   throw :task_has_failed
  end
end