forked from seattlerb/zentest
-
Notifications
You must be signed in to change notification settings - Fork 20
/
test_autotest_integration.rb
102 lines (84 loc) · 3.03 KB
/
test_autotest_integration.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require File.expand_path('test/helper')
require 'autotest'
require 'shoulda'
class TestAutotestIntegration < Test::Unit::TestCase
def temp_dir
"#{File.dirname(__FILE__)}/tmp"
end
def autotest_executable
'../../bin/autotest'
end
def run_autotest(flag_string='')
`cd #{temp_dir} && #{autotest_executable} #{flag_string}`
end
def write(file, text)
file = "#{temp_dir}/#{file}"
dir = File.dirname(file)
`mkdir -p #{dir}` unless File.directory?(dir)
File.open(file, 'w'){|f| f.write text }
end
def write_passing_tests times
write('test/test_x.rb', %{ class TestX < Test::Unit::TestCase; #{times}.times{|i| define_method("test_\#{i}"){ assert true }}; end })
end
context 'integration' do
context 'green run' do
setup do
`rm -rf #{temp_dir}`
`mkdir #{temp_dir}`
write('.autotest', "Autotest.add_hook(:all_good){print 'all_good';exit}")
end
teardown do
`rm -rf #{temp_dir}`
end
should 'do nothing when run inside an empty directory' do
assert_equal run_autotest, 'all_good'
end
should 'runs all tests' do
write('test/test_x.rb', '')
assert_match %r{test/test_x.rb}, run_autotest
end
should 'include output from tests' do
write('test/test_x.rb', "print 'YES'")
assert_match %r{YES}, run_autotest
end
should 'show one dot per passing test' do
write_passing_tests 10
assert_match %r{[^\.]#{'\.'*10}[^\.]}, run_autotest
end
should 'show test summary' do
write_passing_tests 10
assert_match /Finished.* in .*10 tests, 10 assertions, 0 failures, 0 errors/m, run_autotest
end
should 'call good hooks in correct order' do
write('.autotest', "Autotest::ALL_HOOKS.each{|hook| Autotest.add_hook(hook){print hook;hook == :all_good ? exit : nil }}")
write_passing_tests 1
assert_match /\n#{%w[ran_command green all_good died]*''}$/m, run_autotest
end
should 'run with alternate config file location' do
write('.autotest_alternate', "Autotest.add_hook(:all_good){print 'all_good';exit}")
assert_equal run_autotest('-r .autotest_alternate'), 'all_good'
end
should 'support files with whitespaces' do
write('test/test_a x.rb', "print 'YES'")
assert_match %r{YES}, run_autotest
end
should 'use given style' do
write('spec/a_spec.rb', "print 'YES'")
assert_match %r{YES}, run_autotest('--style rspec2')
end
should 'run in parallel' do
write('test/test_a.rb', "require 'test/unit';print 'YES'")
write('test/test_b.rb', "require 'test/unit';print 'YEP'")
result = run_autotest('--parallel')
assert_match %r{YES}, result
assert_match %r{YEP}, result
end
should 'use a sleep option from .autotest' do
# speed up autotest to react instantly on save like Guard
run_autotest("--delay 0")
a = Autotest.new
assert_equal a.sleep, 0
end
end
end
end