2012-09-08 23:27:41 -04:00
|
|
|
require 'guard/guard'
|
|
|
|
|
|
|
|
module ::Guard
|
|
|
|
class Bacon < Guard
|
|
|
|
def run_all
|
2012-11-15 00:37:37 -05:00
|
|
|
system "rake spec"
|
2012-09-08 23:27:41 -04:00
|
|
|
puts
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_spec(path)
|
|
|
|
if File.exists?(path)
|
2012-11-15 00:37:37 -05:00
|
|
|
cmd = "bundle exec bacon -Ispec -q #{path}"
|
|
|
|
puts cmd
|
|
|
|
@success &&= system cmd
|
2012-09-08 23:27:41 -04:00
|
|
|
puts
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_changed(path)
|
|
|
|
run_spec(path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_on_changes(paths)
|
2012-09-08 23:56:51 -04:00
|
|
|
@success = true
|
2012-09-08 23:27:41 -04:00
|
|
|
paths.delete(:all)
|
|
|
|
|
|
|
|
paths.each do |path|
|
|
|
|
file_changed(path)
|
|
|
|
end
|
|
|
|
|
2012-09-08 23:56:51 -04:00
|
|
|
run_all if @success
|
2012-09-08 23:27:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
guard 'bacon' do
|
2012-11-15 00:37:37 -05:00
|
|
|
def deduce_spec_from(token)
|
|
|
|
"spec/#{token}_spec.rb"
|
2012-09-17 03:12:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Dir['lib/pry/*.rb'].each do |rb|
|
|
|
|
rb[%r(lib/pry/(.+)\.rb$)]
|
2012-11-15 00:37:37 -05:00
|
|
|
spec_rb = deduce_spec_from $1
|
|
|
|
if File.exists?(spec_rb)
|
|
|
|
watch(rb) { spec_rb }
|
2012-09-17 03:12:40 -04:00
|
|
|
else
|
|
|
|
exempt = %w(
|
|
|
|
commands
|
|
|
|
version
|
2012-11-15 00:37:37 -05:00
|
|
|
).map {|token| deduce_spec_from token}
|
|
|
|
puts 'Missing ' + spec_rb if
|
|
|
|
ENV['WANT_SPEC_COMPLAINTS'] and not exempt.include?(spec_rb)
|
2012-09-17 03:12:40 -04:00
|
|
|
end
|
|
|
|
end
|
2012-09-08 23:27:41 -04:00
|
|
|
|
2012-11-15 00:37:37 -05:00
|
|
|
watch(%r{^lib/pry/commands/([^.]+)\.rb}) { |m| "spec/commands/#{m[1]}_spec.rb" }
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-09-08 23:27:41 -04:00
|
|
|
# If no such mapping exists, just run all of them
|
|
|
|
watch(%r{^lib/}) { :all }
|
|
|
|
|
2012-11-15 00:37:37 -05:00
|
|
|
# If we modified one spec file, run it
|
|
|
|
watch(%r{^spec/.+\.rb$})
|
2012-09-08 23:27:41 -04:00
|
|
|
end
|
|
|
|
|
2012-09-17 03:12:40 -04:00
|
|
|
# vim:ft=ruby
|