-
Notifications
You must be signed in to change notification settings - Fork 269
/
Copy pathGuardfile
130 lines (98 loc) · 2.52 KB
/
Guardfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
79
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
117
118
119
120
121
122
123
124
125
126
require 'guard/plugin'
require 'shellwords'
# README:
# `guard -g tests` to run unit tests whenever a source file changes.
# `guard -g misc` for git status, bundle install whenever the Gemfile changes, and more.
module ::Guard
class XCTest < ::Guard::Plugin
def _setup
scheme = "OS X Tests"
xcodebuild_test_cmd = "xcodebuild -workspace Typhoon.xcworkspace/ -scheme '#{scheme}' test"
@rspec_test_task = "#{xcodebuild_test_cmd} | xcpretty -tc"
@simple_test_task = "#{xcodebuild_test_cmd} | xcpretty -sc"
end
def start
_setup
_run
end
def reload
_run
end
def run_all
_run
end
def run_on_change(paths)
if paths == ["Guardfile"]
# We just ran in #start, don't run again.
return
end
_run(paths)
end
def _run(paths=[])
output = `#{@rspec_test_task}`
ansi_color_regex = /\u001b\[[;\d]*m/
stripped = output.gsub(ansi_color_regex, '').strip
if stripped.empty? || $?.success? == false
::Guard::Notifier.notify("Unable to build the project.", :image => :failed, :title => 'Build failed')
return
end
last_line = stripped.lines.last.strip
# success = $?.success? # xcpretty doesn't return xcodebuild's exit code
# so do some horrible things instead
num_failed_regex = /(\d) failure/
number_failed = last_line.match(num_failed_regex)[1].to_i
success = (number_failed == 0)
if success
::Guard::Notifier.notify(last_line, :image => :success, :title => 'Tests passed')
else
::Guard::Notifier.notify(last_line, :image => :failed, :title => 'Tests failed')
end
puts output # need to preserve colors!
end
end
class GitStatus < ::Guard::Plugin
def start
_run
end
# def reload
# _run
# end
def run_all
_run
end
def run_on_change(paths)
if paths == ["Guardfile"]
# We just ran in #start, don't run again.
return
end
_run
end
def _run
puts `git status` # tell git it can use colors, it assumes it cannot
end
end
end
group :tests do
guard :xctest do
watch /.*/
ignore [/.git/, /xcuserdata/, %r{Tests/Pods/}, %r{Tests/Podfile.lock}, /.idea/, /build/]
end
end
group :misc do
guard :shell do
watch /.*/ do |m|
puts m[0] + " has changed."
end
ignore [/.git/, /xcuserdata/, %r{Tests/Pods/}, %r{Tests/Podfile.lock}]
ignore [/build/]
end
guard :bundler do
watch('Gemfile')
# Uncomment next line if your Gemfile contains the `gemspec' command.
# watch(/^.+\.gemspec/)
end
guard :gitstatus do
watch /.*/
ignore [/build/]
end
end