bee 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/tc_bee_util.rb DELETED
@@ -1,85 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright 2006-2007 Michel Casabianca <michel.casabianca@gmail.com>
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require 'fileutils'
18
- $:.unshift(File.join(File.dirname(__FILE__)))
19
- require 'tmp_test_case'
20
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
21
- require 'bee_util'
22
-
23
- # Test case for utility methods.
24
- class TestBeeUtil < TmpTestCase
25
-
26
- include Bee::Util::FileSelector
27
-
28
- # Test FileSelector class.
29
- def test_select_files
30
- # make test files
31
- path = File.join(@tmp_dir, '1.txt')
32
- File.open(path, 'w') {|file| file.write('TEST')}
33
- path = File.join(@tmp_dir, '2.txt')
34
- File.open(path, 'w') {|file| file.write('TEST')}
35
- path = File.join(@tmp_dir, '3.txt')
36
- File.open(path, 'w') {|file| file.write('TEST')}
37
- path = File.join(@tmp_dir, '1.tst')
38
- File.open(path, 'w') {|file| file.write('TEST')}
39
- path = File.join(@tmp_dir, '2.tst')
40
- File.open(path, 'w') {|file| file.write('TEST')}
41
- path = File.join(@tmp_dir, '3.tst')
42
- File.open(path, 'w') {|file| file.write('TEST')}
43
- # test file selection
44
- includes = "#{@tmp_dir}/*"
45
- excludes = nil
46
- actual = select_files(includes, excludes)
47
- expected = ["#{@tmp_dir}/1.tst", "#{@tmp_dir}/1.txt",
48
- "#{@tmp_dir}/2.tst", "#{@tmp_dir}/2.txt",
49
- "#{@tmp_dir}/3.tst", "#{@tmp_dir}/3.txt"]
50
- assert_equal(expected, actual)
51
- includes = "#{@tmp_dir}/*"
52
- excludes = "#{@tmp_dir}/*.tst"
53
- actual = select_files(includes, excludes)
54
- expected = ["#{@tmp_dir}/1.txt", "#{@tmp_dir}/2.txt", "#{@tmp_dir}/3.txt"]
55
- assert_equal(expected, actual)
56
- includes = "#{@tmp_dir}/1.*"
57
- excludes = nil
58
- actual = select_files(includes, excludes)
59
- expected = ["#{@tmp_dir}/1.tst", "#{@tmp_dir}/1.txt"]
60
- assert_equal(expected, actual)
61
- end
62
-
63
- # Test find method.
64
- def test_find
65
- # nominal case
66
- file = File.join(@tmp_dir, 'file.txt')
67
- File.open(file, 'w') {|file| file.write('TEST')}
68
- dir = File.join(@tmp_dir, 'dir')
69
- FileUtils.mkdir(dir)
70
- Dir.chdir(dir)
71
- actual = Bee::Util::find('file.txt')
72
- expected = '../file.txt'
73
- assert_equal(expected, actual)
74
- # failure: file not found
75
- begin
76
- Bee::Util::find('foo.bar')
77
- flunk "Should have failed"
78
- rescue
79
- expected = 'File not found'
80
- actual = $!.to_s
81
- assert_equal(expected, actual)
82
- end
83
- end
84
-
85
- end
@@ -1,58 +0,0 @@
1
- # Copyright 2006-2007 Michel Casabianca <michel.casabianca@gmail.com>
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'test/unit'
16
- require 'fileutils'
17
-
18
- # Test case that creates a 'tmp' directory before each test and deletes it
19
- # after. Also disable tests if we can't write on disk (if we run tests while
20
- # installing with gem in a system directory for instance).
21
- class TmpTestCase < Test::Unit::TestCase
22
-
23
- # Temporary directory.
24
- TEMP_DIR = 'tmp'
25
-
26
- # Constructor: disable test if we don't have write permission.
27
- def initialize(*args)
28
- super(*args)
29
- @home = File.expand_path(File.dirname(__FILE__))
30
- @working_dir = Dir.getwd
31
- @tmp_dir = File.join(@home, TEMP_DIR)
32
- begin
33
- FileUtils.makedirs(@tmp_dir)
34
- @run_tests = true
35
- rescue
36
- @run_tests = false
37
- methods = self.class.public_instance_methods
38
- for method in methods
39
- self.class.remove_method(Symbol.new(method)) if method =~ /^test_.*/
40
- end
41
- end
42
- end
43
-
44
- # Run before any test: create temporary directory.
45
- def setup
46
- FileUtils.makedirs(@tmp_dir)
47
- end
48
-
49
- # Run after any test: delete temporary directory.
50
- def teardown
51
- Dir.chdir(@working_dir)
52
- FileUtils.rm_rf(@tmp_dir)
53
- end
54
-
55
- def test_
56
- end
57
-
58
- end