forked from usergenic/entrails
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
126 lines (105 loc) · 3.75 KB
/
Rakefile
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
#!/usr/bin/env ruby
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
require 'rubygems'
require './lib/entrails.rb'
require 'rake'
require 'spec/rake/spectask'
desc "Generates the gemspec, Manifest.txt and builds the gem."
task :gem => ["gem:gemspec","gem:manifest"]
namespace :gem do
desc "Generates the entrails.gemspec file"
task :gemspec do
gemspec_code = <<-gemspec
Gem::Specification.new do |s|
s.name = %q{entrails}
s.version = #{Entrails::VERSION.inspect}
s.specification_version = 2 if s.respond_to? :specification_version=
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = #{Entrails::AUTHORS.inspect}
s.date = #{Time.now.strftime('%Y-%m-%d').inspect}
s.default_executable = %q{entrails}
s.description = #{Entrails::DESCRIPTION.inspect}
s.email = #{Entrails::EMAIL.inspect}
s.executables = []
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
s.files = #{Entrails::MANIFEST.inspect}
s.has_rdoc = true
s.homepage = #{Entrails::HOMEPAGE.inspect}
s.rdoc_options = ["--main", "README.txt"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.1.1}
s.summary = #{Entrails::DESCRIPTION.inspect}
end
gemspec
gemspec = File.open(File.join(File.dirname(__FILE__),'entrails.gemspec'),'w')
gemspec.write(gemspec_code)
gemspec.close
end
desc "Generates the Manifest.txt file"
task :manifest do
manifest = File.open(File.join(File.dirname(__FILE__),'Manifest.txt'),'w')
manifest.write(Entrails::MANIFEST.join("\n")<<"\n")
manifest.close
end
end
desc "Run all specs"
Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList['spec/**/*_spec.rb']
end
namespace :spec do
desc "Run all specs and stake out all files/folders for changes, running rake spec upon change"
task :auto => 'spec' do
# This task assumes you are running on a Mac, with growl installed. Perhaps
# there will be a better way to abstract this, but it works for us now.
def growl(title, msg, img, pri=0, sticky="")
system "growlnotify -n autotest --image ~/.autotest_images/#{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
end
def self.growl_fail(output)
growl "FAIL", "#{output}", "fail.png", 2
end
def self.growl_pass(output)
growl "Pass", "#{output}", "pass.png"
end
command = 'rake spec'
files = {}
def files.reglob
Dir['**/*.rb'].each {|file| self[file] ||= File.mtime(file)}
end
files.reglob
puts "Watching #{files.keys.join(', ')}\n\nFiles: #{files.keys.length}"
trap('INT') do
puts "\nQuitting..."
exit
end
loop do
sleep 3
files.reglob
changed_file, last_changed = files.find do |file, last_changed|
begin
File.mtime(file) > last_changed
rescue
files.delete(file)
end
end
if changed_file
files[changed_file] = File.mtime(changed_file)
puts "=> #{changed_file} changed, running #{command}"
results = `#{command}`
puts results
if results.include? 'tests'
output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/)
if output
$~[3].to_i + $~[5].to_i > 0 ? growl_fail(output) : growl_pass(output)
end
else
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
if output
$~[2].to_i > 0 ? growl_fail(output) : growl_pass(output)
end
end
# TODO Generic growl notification for other actions
puts "=> done"
end
end
end
end