-
Notifications
You must be signed in to change notification settings - Fork 8
/
Guardfile
75 lines (57 loc) · 1.4 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
# frozen_string_literal: true
require "colorize"
def running_test file, command
Notifier.notify "Running", title: "#{command} #{file}", image: :pending
end
def guard_all?
return false unless guard_env_var
guard_env_var['all'] || guard_env_var[/^a/]
end
def guard_rspec?
return true if guard_all?
return true if guard_env_var.nil?
guard_env_var['spec'] || guard_env_var[/^s/]
end
def guard_rubocop?
return true if guard_all?
return false unless guard_env_var
guard_env_var['rubocop'] || guard_env_var[/^r/]
end
def not_guarding_anything?
!(guard_rspec? || guard_rubocop?)
end
def guard_env_var
ENV["GUARD"]
end
if guard_rspec?
puts "Guarding rspec".green
guard :rspec, cmd: "bundle exec rspec" do
watch(%r{^app/(.+)\.rb$}) do |m|
file = "spec/#{m[1]}_spec.rb"
file.tap { running_test file, :rspec }
end
watch(%r{^lib/(.+)\.rb$}) do |m|
file = "spec/lib/#{m[1]}_spec.rb"
file.tap { running_test file, :rspec }
end
watch(%r{^spec/(.+_spec.rb)$}) do |m|
file = m[0]
file.tap { running_test file, :rspec }
end
end
# Do not run all specs.
ObjectSpace.each_object(Guard::RSpec) do |object|
def object.run_all
end
end
end
if guard_rubocop?
puts "Guarding rubocop".green
guard :rubocop, all_on_start: false do
watch(/.+\.rb$/)
end
end
if not_guarding_anything?
puts 'Not guarding anything!'.red
exit 1
end