-
Notifications
You must be signed in to change notification settings - Fork 1
/
guard.rb
173 lines (138 loc) · 5.18 KB
/
guard.rb
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
say_recipe 'guard'
gem 'rb-fsevent', :group => :test, :platforms => :ruby
gem 'growl', :group => :test
# 0.9 rc needed for rails3, see
# http:https://opinionated-programmer.com/2011/02/profiling-spork-for-faster-start-up-time/
gem 'spork', '~> 0.9.0.rc', :group => :test
gem 'rspec-instafail', :group => :test
# cli to easily handle events on files modifications
# git version to make guard-spork and guard-ego play nice, see
# https://github.com/guard/guard/pull/34
gem "guard", :git => "git:https://github.com/guard/guard.git", :group => :test
# the alter ego of Guard and will reload Guard when necessary
gem "guard-ego", :group => :test
if recipe_list.include?('rspec') || recipe_list.include?('cucumber')
# automatically manage Spork DRb servers
gem "guard-spork", :group => :test
end
# automatically install/update your gem bundle when needed
gem "guard-bundler", :group => :test
if recipe_list.include? 'rspec'
# automatically run your RSpec specs when files are modified
gem "guard-rspec", :group => :test
end
if recipe_list.include? 'cucumber'
# automatically run Cucumber features when files are modified
gem "guard-cucumber", :group => :test
end
# automatically reload your browser when ‘view’ files are modified
gem "guard-livereload", :group => :test
create_file 'Guardfile' do
<<-'GUARDFILE'.gsub(/^ {4}/, '')
# More info at https://github.com/guard/guard#readme
guard 'ego' do
watch('Guardfile')
end
guard 'spork' do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.*\.rb$})
watch(%r{^config/initializers/.*\.rb$})
watch('spec/spec_helper.rb')
end
guard 'bundler' do
watch('Gemfile')
end
guard 'rspec', :cli => "-r rspec/instafail -f RSpec::Instafail --color --drb" do
watch(%r{^spec/.+_spec\.rb})
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
watch(%r{^spec/.+_spec\.rb})
watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
end
guard 'cucumber', :drb => true, :profile => "spork" do
watch(%r{features/.+\.feature}) { 'features' }
watch(%r{features/support/.+}) { 'features' }
watch(%r{features/step_definitions/.+}) { 'features' }
end
guard 'livereload' do
watch(%r{app/.+\.(erb|haml)})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
end
GUARDFILE
end
create_file "script/guard" do
<<-'GUARD'.gsub(/^ {4}/, '')
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler'
Bundler.setup(:default, :test)
require 'guard'
load File.join(Gem.loaded_specs['guard'].full_gem_path, 'bin', 'guard')
GUARD
end
chmod "script/guard", 0755
after_bundler do
# make Spork reload model classes
# see: http:https://www.rubyinside.com/how-to-rails-3-and-rspec-2-4336.html
gsub_file "config/environments/test.rb",
/(config\.cache_classes += +)true/, '\1false'
if recipe_list.include? 'cucumber'
# Add spork erb opts
gsub_file "config/cucumber.yml", /^(std_opts = .*wip")$/, '\1' << <<-'OPTS'.gsub(/^ {6}/, '')
std_opts += " --tags ~@proposed --color"
spork_opts = "--format rerun --out rerun.txt --strict --tags ~@proposed"
OPTS
# Add spork formats
gsub_file "config/cucumber.yml", /^(rerun: .* ~@wip)$/, '\1 --tags ~@proposed'
append_to_file "config/cucumber.yml" do
<<-'YAML'.gsub(/^ {8}/, '')
spork: <%= spork_opts %> features
YAML
end
# Add spork support for Cucumber
gsub_file "features/support/env.rb", /^(.+)$/, ' \1'
gsub_file "features/support/env.rb", /^ (ENV\["RAILS_ENV"\].*)$/,
<<-'ENV'.gsub(/^ {6}/, '') + ' \1'
require 'spork'
Spork.prefork do
ENV
gsub_file "features/support/env.rb", /^ (Capybara.default_selector.*)$/,
' \1' << <<-'ENV'.gsub(/^ {6}/, '')
end
Spork.each_run do
ENV
append_to_file "features/support/env.rb" do
<<-'THEEND'.gsub(/^ {8}/, '')
end
# the end :)
THEEND
end
end
if recipe_list.include? 'rspec'
# Add spork support for RSpec
gsub_file "spec/spec_helper.rb", /^/, ' '
gsub_file "spec/spec_helper.rb", /^ # This file is .*$\n/, ''
gsub_file "spec/spec_helper.rb", /^ (ENV\["RAILS_ENV"\].*)$/,
'\1' << <<-'SPEC'.gsub(/^ {6}/, '')
require 'spork'
Spork.prefork do
SPEC
append_to_file "spec/spec_helper.rb" do
<<-'SPEC'.gsub(/^ {8}/, '')
end
Spork.each_run do
# This code will be run each time you run your specs
end
SPEC
end
end
end