Skip to content

Commit

Permalink
Add Guard to run tests and git status during development whenever fil…
Browse files Browse the repository at this point in the history
…es change.
  • Loading branch information
rhgills committed Dec 15, 2013
1 parent 432d55b commit 5d28b28
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
source "https://rubygems.org"

gem 'cocoapods'
group :development do
gem 'cocoapods'

gem 'terminal-notifier-guard'
gem 'guard'
gem 'guard-shell'
gem 'guard-bundler'
gem 'xcpretty'
end

39 changes: 39 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ GEM
activesupport (3.2.15)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
celluloid (0.15.2)
timers (~> 1.1.0)
claide (0.4.0)
cocoapods (0.28.0)
activesupport (>= 3.2.15, < 4)
Expand All @@ -21,23 +23,60 @@ GEM
json (~> 1.8)
nap (~> 0.5)
cocoapods-downloader (0.2.0)
coderay (1.1.0)
colored (1.2)
escape (0.0.4)
ffi (1.9.3)
formatador (0.2.4)
fuzzy_match (2.0.4)
guard (2.2.5)
formatador (>= 0.2.4)
listen (~> 2.1)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-bundler (2.0.0)
bundler (~> 1.0)
guard (~> 2.2)
guard-shell (0.5.2)
guard (>= 1.1.0)
i18n (0.6.5)
json (1.8.1)
json_pure (1.8.1)
listen (2.4.0)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.4)
method_source (0.8.2)
multi_json (1.8.2)
nap (0.6.0)
open4 (1.3.0)
pry (0.9.12.4)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
rake (10.1.0)
rb-fsevent (0.9.3)
rb-inotify (0.9.3)
ffi (>= 0.5.0)
slop (3.4.7)
terminal-notifier-guard (1.5.3)
thor (0.18.1)
timers (1.1.0)
xcodeproj (0.14.1)
activesupport (~> 3.0)
colored (~> 1.2)
rake
xcpretty (0.0.6)

PLATFORMS
ruby

DEPENDENCIES
cocoapods
guard
guard-bundler
guard-shell
terminal-notifier-guard
xcpretty
129 changes: 129 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
require 'guard/plugin'
require 'shellwords'

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

module ::Guard
class XCTest < ::Guard::Plugin
def _setup
scheme = "OS X Tests (Cocoapods)"
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




0 comments on commit 5d28b28

Please sign in to comment.