Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#all_test_filesObject



20
21
22
# File 'lib/watch-me-now.rb', line 20

def all_test_files
  Dir["#{test_folder}/**/*_#{test_suffix}.rb"]
end

#execute(cmd) ⇒ Object



51
52
53
54
# File 'lib/watch-me-now.rb', line 51

def execute(cmd)
  puts("> #{cmd}")
  system(cmd)
end

#find_in_load_path(path) ⇒ Object



4
5
6
7
# File 'bin/watch-me-now', line 4

def find_in_load_path(path)
  dir = (['.'] + $LOAD_PATH).uniq.detect {|p| Pathname(p).join(path).exist? }
  dir ? path.expand_path(dir) : nil
end

#include_lib_folder_if_existsObject



8
9
10
# File 'lib/watch-me-now.rb', line 8

def include_lib_folder_if_exists
  "-Ilib" if File.directory?("lib")
end

#no_int_for_youObject



56
57
58
# File 'lib/watch-me-now.rb', line 56

def no_int_for_you
  @sent_an_int = nil
end

#run(files_to_run) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/watch-me-now.rb', line 41

def run(files_to_run)
  if files_to_run.strip.empty?
    puts "No files to run"
  else
    cmd = "#{runner} #{include_lib_folder_if_exists} -I#{test_folder} #{files_to_run}"
    execute cmd
  end
  no_int_for_you
end

#run_all_testsObject



37
38
39
# File 'lib/watch-me-now.rb', line 37

def run_all_tests
  run(all_test_files.join(' '))
end

#run_test_matching(thing_to_match) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/watch-me-now.rb', line 28

def run_test_matching(thing_to_match)
  matches = all_test_files.grep(/#{thing_to_match}/i)
  if matches.empty?
    puts "Sorry, thanks for playing, but there were no matches for #{thing_to_match}"  
  else
    run matches.join(' ')
  end
end

#runnerObject



24
25
26
# File 'lib/watch-me-now.rb', line 24

def runner
  ENV["WATCHR_RUNNER"] || "ruby"
end

#test_folderObject


Convenience Methods




4
5
6
# File 'lib/watch-me-now.rb', line 4

def test_folder
  @test_folder ||= %w[spec examples test].detect { |p| File.directory?(p) }
end

#test_suffixObject



12
13
14
15
16
17
18
# File 'lib/watch-me-now.rb', line 12

def test_suffix
  case test_folder
  when "spec" then "spec"
  when "examples" then "example"
  when "test" then "test"
  end
end