-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.rb
105 lines (90 loc) · 3.48 KB
/
test.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
103
104
105
require "test/unit"
class TestLogger < Test::Unit::TestCase
def setup
`rm -r ./planning-poker/.log_cs169`
@dir = "./planning-poker/.log_cs169"
sleep 10
end
def teardown
`rm -r ./planning-poker/.log_cs169`
end
def test_a_file_created_testenv
puts "Starting File Created - Test Environment"
`cd planning-poker; RUBYOPT="-W0" bundle exec rspec; cd ..`
assert(File.directory?(@dir))
files = Dir.foreach(@dir).select { |x| File.file?("#{@dir}/#{x}") }
puts files
assert_equal(1, files.count)
file = files[0]
file_str = IO.read("#{@dir}/#{file}")
assert(file_str.match(/cs169_testing, test\n.+\n--\n.+/m))
end
def test_d_adds_to_same_folder
puts "Starting Logs add to same folder"
sleep 10
puts Time.now.getutc.to_i
`cd planning-poker; RUBYOPT="-W0" bundle exec rspec; cd ..`
puts Time.now.getutc.to_i
assert(File.directory?(@dir))
files = Dir.foreach(@dir).select { |x| File.file?("#{@dir}/#{x}") }
puts files
puts `cat #{@dir}/#{files[0]}`
puts `cat #{@dir}/#{files[1]}`
assert_equal(1, files.count)
`cd planning-poker; RUBYOPT="-W0" bundle exec rspec; cd ..`
assert(File.directory?(@dir))
files = Dir.foreach(@dir).select { |x| File.file?("#{@dir}/#{x}") }
assert_equal(2, files.count)
end
def test_b_file_name
puts "Starting Filenames are of a certain pattern"
`cd planning-poker; RUBYOPT="-W0" bundle exec rspec; cd ..`
files = Dir.foreach(@dir).select { |x| File.file?("#{@dir}/#{x}") }
file = files[0]
assert(file.match(/(\d{10})_([a-z0-9]{40}).txt/))
end
def test_c_correct_file_content
puts "Starting Files have a certain pattern"
`cd planning-poker; RUBYOPT="-W0" bundle exec rspec; cd ..`
files = Dir.foreach(@dir).select { |x| File.file?("#{@dir}/#{x}") }
file = files[0]
file_str = IO.read("#{@dir}/#{file}")
assert(file_str.match(/[a-z0-9_]+, [a-z]+\n.+\n--\n.+/m))
end
def test_e_file_created_devenv
puts "Starting File Created - Dev Environment"
# puts Rails.env
pid = fork do
exec "cd planning-poker; RAILS_ENV=development rails server"
end
sleep 10
f = File.new('./planning-poker/app/models/activity.rb', 'w')
f.write("puts 'abcd'\n")
f.close
puts "changed file 1"
puts `cat './planning-poker/app/models/activity.rb'`
sleep 10
assert(File.directory?(@dir))
files = Dir.foreach(@dir).select { |x| File.file?("#{@dir}/#{x}") }
puts "assertion file 1"
puts files
puts `cat ./planning-poker/.log_cs169/#{files[0]}`
assert_equal(1, files.count)
f = File.new('./planning-poker/app/models/activity.rb', 'w')
f.write("puts 'efgh'\n")
f.close
puts "changed file 2"
sleep 10
assert(File.directory?(@dir))
files = Dir.foreach(@dir).select { |x| File.file?("#{@dir}/#{x}") }
puts "assertion file 2"
puts files
puts `cat ./planning-poker/.log_cs169/#{files[0]}`
puts `cat ./planning-poker/.log_cs169/#{files[1]}`
assert_equal(2, files.count)
Process.kill("HUP", pid)
file = files[0]
file_str = IO.read("#{@dir}/#{file}")
assert(file_str.match(/cs169_testing, development\n.+\n--\n.+/m))
end
end