This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
/
runner.rb
66 lines (57 loc) · 1.83 KB
/
runner.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
module Spec
module Mate
class Runner
def run_files(stdout, options={})
files = ENV['TM_SELECTED_FILES'].scan(/'(.*?)'/).flatten.map do |path|
File.expand_path(path)
end
options.merge!({:files => files})
run(stdout, options)
end
def run_file(stdout, options={})
options.merge!({:files => [single_file]})
run(stdout, options)
end
def run_last_remembered_file(stdout, options={})
options.merge!({:files => [last_remembered_single_file]})
run(stdout, options)
end
def run_focussed(stdout, options={})
options.merge!({:files => [single_file], :line => ENV['TM_LINE_NUMBER']})
run(stdout, options)
end
def run(stdout, options)
argv = options[:files].dup
argv << '--format'
argv << 'textmate'
if options[:line]
argv << '--line'
argv << options[:line]
end
argv += ENV['TM_RSPEC_OPTS'].split(" ") if ENV['TM_RSPEC_OPTS']
Dir.chdir(project_directory) do
::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(argv, STDERR, stdout))
end
end
def save_as_last_remembered_file(file)
File.open(last_remembered_file_cache, "w") do |f|
f << file
end
end
def last_remembered_file_cache
"/tmp/textmate_rspec_last_remembered_file_cache.txt"
end
protected
def single_file
File.expand_path(ENV['TM_FILEPATH'])
end
def last_remembered_single_file
file = File.read(last_remembered_file_cache).strip
File.expand_path(file) if file.size > 0
end
def project_directory
File.expand_path(ENV['TM_PROJECT_DIRECTORY']) rescue File.dirname(single_file)
end
end
end
end