Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#find_file(match) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sploek.watchr.rb', line 23

def find_file match
  path = match.to_s.sub('_spec', '').sub(/^spec\//, '')

  locations = [
    File.join("app", path),
    File.join("lib", path),
    path
  ]
  if File.exist?(match.to_s) && match.to_s["_spec"].nil?
    match
  elsif path = locations.find {|x| File.exist?(x) }
    path
  end
end

#find_spec(match) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sploek.watchr.rb', line 38

def find_spec match
  locations = [
    File.join("spec", match[1] + "_spec.rb"),
    File.join("spec", match[2] + "_spec.rb"),
    File.join("spec", match[1].sub(/^app/, '') + "_spec.rb")
  ]
  if match[1] =~ /_spec$/
    match
  elsif specpath = locations.find {|x| File.exist?(x) }
    specpath
  end
end

#nlObject



18
19
20
# File 'lib/sploek.watchr.rb', line 18

def nl
  "\n"
end

#run_cmd(cmd, match) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/sploek.watchr.rb', line 60

def run_cmd(cmd, match)
  match = find_file(match)
  return unless match
  puts "-" * 80
  print magenta, cmd, reset, " ", match, nl
  system "#{cmd} #{match}"
end

#run_spec(match) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/sploek.watchr.rb', line 51

def run_spec match
  specpath = find_spec(match)
  return unless specpath
  print magenta, "spec", reset, " ", specpath, nl


  system("spec #{specpath}")
end