-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspecs.watchr
52 lines (41 loc) · 939 Bytes
/
specs.watchr
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
def test(spec)
system('clear')
system("node #{spec}")
end
class CodeSpecMap
def initialize
@mappers = []
end
def add_map(mapper)
@mappers.push(mapper)
end
def find_spec_for(code)
p @mappers
@mappers.each do |mapper|
puts 'finding spec for: ' + code
found_spec = mapper.spec_for(code)
return found_spec if found_spec
end
# code must be the spec!
code
end
end
class OneToOneMap
def initialize(code, spec)
@code = code
@spec = spec
end
def spec_for(code)
@spec if code === @code
end
end
$mappers = CodeSpecMap.new
def code_spec(code, spec)
$mappers.add_map(OneToOneMap.new(code, spec))
end
code_spec('loopback.js', 'test.js')
code_spec('cupoftea.js', 'cupoftea_test.js')
watch '.*' do |code|
test($mappers.find_spec_for(code[0]))
end
test('cupoftea_test.js')