scout-essentials 1.3.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +33 -1
  3. data/VERSION +1 -1
  4. data/lib/scout/annotation/annotated_object.rb +69 -0
  5. data/lib/scout/annotation/annotation_module.rb +59 -0
  6. data/lib/scout/annotation/array.rb +74 -0
  7. data/lib/scout/annotation.rb +45 -0
  8. data/lib/scout/concurrent_stream.rb +4 -1
  9. data/lib/scout/config.rb +3 -3
  10. data/lib/scout/exceptions.rb +2 -1
  11. data/lib/scout/indiferent_hash/options.rb +2 -1
  12. data/lib/scout/log/color.rb +1 -1
  13. data/lib/scout/log.rb +11 -11
  14. data/lib/scout/misc/digest.rb +39 -8
  15. data/lib/scout/misc/filesystem.rb +23 -0
  16. data/lib/scout/misc/format.rb +32 -0
  17. data/lib/scout/misc/helper.rb +37 -0
  18. data/lib/scout/misc/math.rb +109 -0
  19. data/lib/scout/misc/system.rb +18 -2
  20. data/lib/scout/misc.rb +1 -0
  21. data/lib/scout/named_array.rb +8 -6
  22. data/lib/scout/open/remote.rb +8 -3
  23. data/lib/scout/open/stream.rb +5 -1
  24. data/lib/scout/open/util.rb +1 -1
  25. data/lib/scout/path/find.rb +30 -8
  26. data/lib/scout/path/util.rb +1 -1
  27. data/lib/scout/path.rb +10 -4
  28. data/lib/scout/persist/open.rb +1 -1
  29. data/lib/scout/persist/serialize.rb +5 -1
  30. data/lib/scout/persist.rb +49 -20
  31. data/lib/scout/resource/path.rb +1 -1
  32. data/lib/scout/resource/scout.rb +2 -0
  33. data/lib/scout/resource/util.rb +8 -3
  34. data/lib/scout/resource.rb +15 -3
  35. data/scout-essentials.gemspec +21 -13
  36. data/test/scout/annotation/test_annotated_object.rb +0 -0
  37. data/test/scout/annotation/test_array.rb +119 -0
  38. data/test/scout/misc/test_digest.rb +54 -0
  39. data/test/scout/misc/test_filesystem.rb +28 -0
  40. data/test/scout/misc/test_helper.rb +14 -0
  41. data/test/scout/misc/test_math.rb +9 -0
  42. data/test/scout/path/test_find.rb +32 -0
  43. data/test/scout/test_annotation.rb +169 -0
  44. data/test/scout/test_persist.rb +17 -1
  45. data/test/scout/test_resource.rb +8 -8
  46. metadata +13 -5
  47. data/lib/scout/meta_extension.rb +0 -101
  48. data/test/scout/test_meta_extension.rb +0 -80
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: scout-essentials 1.3.1 ruby lib
5
+ # stub: scout-essentials 1.5.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "scout-essentials".freeze
9
- s.version = "1.3.1"
9
+ s.version = "1.5.0".freeze
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Miguel Vazquez".freeze]
14
- s.date = "2023-11-07"
14
+ s.date = "2024-05-28"
15
15
  s.description = "Things a scout can use anywhere".freeze
16
16
  s.email = "mikisvaz@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -27,6 +27,10 @@ Gem::Specification.new do |s|
27
27
  "Rakefile",
28
28
  "VERSION",
29
29
  "lib/scout-essentials.rb",
30
+ "lib/scout/annotation.rb",
31
+ "lib/scout/annotation/annotated_object.rb",
32
+ "lib/scout/annotation/annotation_module.rb",
33
+ "lib/scout/annotation/array.rb",
30
34
  "lib/scout/cmd.rb",
31
35
  "lib/scout/concurrent_stream.rb",
32
36
  "lib/scout/config.rb",
@@ -42,13 +46,13 @@ Gem::Specification.new do |s|
42
46
  "lib/scout/log/progress/report.rb",
43
47
  "lib/scout/log/progress/util.rb",
44
48
  "lib/scout/log/trap.rb",
45
- "lib/scout/meta_extension.rb",
46
49
  "lib/scout/misc.rb",
47
50
  "lib/scout/misc/digest.rb",
48
51
  "lib/scout/misc/filesystem.rb",
49
52
  "lib/scout/misc/format.rb",
50
53
  "lib/scout/misc/helper.rb",
51
54
  "lib/scout/misc/insist.rb",
55
+ "lib/scout/misc/math.rb",
52
56
  "lib/scout/misc/monitor.rb",
53
57
  "lib/scout/misc/system.rb",
54
58
  "lib/scout/named_array.rb",
@@ -85,6 +89,8 @@ Gem::Specification.new do |s|
85
89
  "share/color/color_names",
86
90
  "share/color/diverging_colors.hex",
87
91
  "share/software/install_helpers",
92
+ "test/scout/annotation/test_annotated_object.rb",
93
+ "test/scout/annotation/test_array.rb",
88
94
  "test/scout/indiferent_hash/test_case_insensitive.rb",
89
95
  "test/scout/indiferent_hash/test_options.rb",
90
96
  "test/scout/log/test_color.rb",
@@ -92,7 +98,9 @@ Gem::Specification.new do |s|
92
98
  "test/scout/log/test_progress.rb",
93
99
  "test/scout/misc/test_digest.rb",
94
100
  "test/scout/misc/test_filesystem.rb",
101
+ "test/scout/misc/test_helper.rb",
95
102
  "test/scout/misc/test_insist.rb",
103
+ "test/scout/misc/test_math.rb",
96
104
  "test/scout/misc/test_system.rb",
97
105
  "test/scout/open/test_lock.rb",
98
106
  "test/scout/open/test_remote.rb",
@@ -111,12 +119,12 @@ Gem::Specification.new do |s|
111
119
  "test/scout/simple_opt/test_get.rb",
112
120
  "test/scout/simple_opt/test_parse.rb",
113
121
  "test/scout/simple_opt/test_setup.rb",
122
+ "test/scout/test_annotation.rb",
114
123
  "test/scout/test_cmd.rb",
115
124
  "test/scout/test_concurrent_stream.rb",
116
125
  "test/scout/test_config.rb",
117
126
  "test/scout/test_indiferent_hash.rb",
118
127
  "test/scout/test_log.rb",
119
- "test/scout/test_meta_extension.rb",
120
128
  "test/scout/test_misc.rb",
121
129
  "test/scout/test_named_array.rb",
122
130
  "test/scout/test_open.rb",
@@ -128,17 +136,17 @@ Gem::Specification.new do |s|
128
136
  ]
129
137
  s.homepage = "http://github.com/mikisvaz/scout-essentials".freeze
130
138
  s.licenses = ["MIT".freeze]
131
- s.rubygems_version = "3.5.0.dev".freeze
139
+ s.rubygems_version = "3.5.10".freeze
132
140
  s.summary = "Scout essential tools".freeze
133
141
 
134
142
  s.specification_version = 4
135
143
 
136
- s.add_development_dependency(%q<shoulda>.freeze, [">= 0"])
137
- s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
138
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
139
- s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
140
- s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
141
- s.add_runtime_dependency(%q<term-ansicolor>.freeze, [">= 0"])
142
- s.add_runtime_dependency(%q<yaml>.freeze, [">= 0"])
144
+ s.add_development_dependency(%q<shoulda>.freeze, [">= 0".freeze])
145
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12".freeze])
146
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0".freeze])
147
+ s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0".freeze])
148
+ s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
149
+ s.add_runtime_dependency(%q<term-ansicolor>.freeze, [">= 0".freeze])
150
+ s.add_runtime_dependency(%q<yaml>.freeze, [">= 0".freeze])
143
151
  end
144
152
 
File without changes
@@ -0,0 +1,119 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestAnnotationArray < Test::Unit::TestCase
5
+ module AnnotationClass
6
+ extend Annotation
7
+
8
+ annotation :code, :code2
9
+ end
10
+
11
+ module AnnotationClass2
12
+ extend Annotation
13
+
14
+ annotation :code3, :code4
15
+ end
16
+
17
+ def test_array
18
+ ary = ["string"]
19
+ code = "Annotation String"
20
+ AnnotationClass.setup(ary, code)
21
+ ary.extend AnnotatedArray
22
+ assert_equal [AnnotationClass], ary.annotation_types
23
+ assert_equal code, ary.code
24
+ assert_equal code, ary[0].code
25
+
26
+ assert_equal code, ary.first.code
27
+ assert_equal code, ary.last.code
28
+ end
29
+
30
+ def test_array_first_last
31
+ %w(first last).each do |method|
32
+ ary = ["string"]
33
+ code = "Annotation String"
34
+ AnnotationClass.setup(ary, code)
35
+ ary.extend AnnotatedArray
36
+ assert_equal [AnnotationClass], ary.annotation_types
37
+
38
+ assert_equal code, ary.send(method).code
39
+ end
40
+ end
41
+
42
+ def test_array_each
43
+ ary = ["string"]
44
+ code = "Annotation String"
45
+ AnnotationClass.setup(ary, code)
46
+ ary.extend AnnotatedArray
47
+
48
+ codes = []
49
+ ary.each{|v| codes << v.code }
50
+ assert_equal [code], codes
51
+ end
52
+
53
+ def test_array_inject
54
+ ary = ["string"]
55
+ code = "Annotation String"
56
+ AnnotationClass.setup(ary, code)
57
+ ary.extend AnnotatedArray
58
+
59
+ codes = []
60
+ codes = ary.inject(codes){|acc,v| acc.push(v.code) }
61
+ assert_equal [code], codes
62
+ end
63
+
64
+ def test_array_collect
65
+ ary = ["string"]
66
+ code = "Annotation String"
67
+ AnnotationClass.setup(ary, code)
68
+ ary.extend AnnotatedArray
69
+
70
+ codes = ary.collect{|v| v.code }
71
+ assert_equal [code], codes
72
+ end
73
+
74
+ def test_array_collect_no_block
75
+ ary = ["string"]
76
+ code = "Annotation String"
77
+ AnnotationClass.setup(ary, code)
78
+ ary.extend AnnotatedArray
79
+
80
+ codes = ary.collect
81
+ assert_equal ["string"], codes
82
+ end
83
+
84
+ def test_compact
85
+ ary = [nil,"string"]
86
+ code = "Annotation String"
87
+ AnnotationClass.setup(ary, code)
88
+ ary.extend AnnotatedArray
89
+
90
+ assert_equal code, ary.compact.first.code
91
+ end
92
+
93
+ def test_reverse
94
+ ary = ["string2", "string1"]
95
+ code = "Annotation String"
96
+ AnnotationClass.setup(ary, code)
97
+ ary.extend AnnotatedArray
98
+
99
+ assert_equal code, ary.reverse.first.code
100
+ assert_equal "string1", ary.reverse.first
101
+ end
102
+
103
+ def test_purge
104
+ ary = ["string2", "string1"]
105
+ code = "Annotation String"
106
+ AnnotationClass.setup(ary, code)
107
+ ary.extend AnnotatedArray
108
+
109
+ assert Annotation.is_annotated?(ary)
110
+ assert Annotation.is_annotated?(ary.first)
111
+
112
+ ary = Annotation.purge(ary)
113
+
114
+ refute Annotation.is_annotated?(ary)
115
+ refute Annotation.is_annotated?(ary.first)
116
+
117
+ end
118
+ end
119
+
@@ -26,5 +26,59 @@ class TestMiscDigest < Test::Unit::TestCase
26
26
  end
27
27
  end
28
28
  end
29
+
30
+ def test_file_digest
31
+ content1 =<<-EOF
32
+ This is one file
33
+ EOF
34
+
35
+ content2 =<<-EOF
36
+ This is another file
37
+ EOF
38
+
39
+ TmpFile.with_file(content1) do |file1|
40
+ TmpFile.with_file(content2) do |file2|
41
+ digest1 = Misc.digest_file(file1)
42
+ digest2 = Misc.digest_file(file2)
43
+ refute_equal digest1, digest2
44
+ end
45
+ end
46
+ end
47
+
48
+ def test_file_digest_fast
49
+ content1 =<<-EOF
50
+ This is one file
51
+ EOF
52
+
53
+ content2 =<<-EOF
54
+ This is another file
55
+ EOF
56
+
57
+ TmpFile.with_file(content1) do |file1|
58
+ TmpFile.with_file(content2) do |file2|
59
+ digest1 = Misc.fast_file_md5(file1, 5)
60
+ digest2 = Misc.fast_file_md5(file2, 5)
61
+ refute_equal digest1, digest2
62
+ end
63
+ end
64
+ end
65
+
66
+ def test_file_digest_fast_2
67
+ content1 =<<-EOF
68
+ This is file 2
69
+ EOF
70
+
71
+ content2 =<<-EOF
72
+ This is file 1
73
+ EOF
74
+
75
+ TmpFile.with_file(content1) do |file1|
76
+ TmpFile.with_file(content2) do |file2|
77
+ digest1 = Misc.fast_file_md5(file1, 5)
78
+ digest2 = Misc.fast_file_md5(file2, 5)
79
+ refute_equal digest1, digest2
80
+ end
81
+ end
82
+ end
29
83
  end
30
84
 
@@ -26,5 +26,33 @@ class TestFilesystem < Test::Unit::TestCase
26
26
  assert Misc.path_relative_to(File.dirname(tmpdir), File.join(tmpdir, "foo"))
27
27
  end
28
28
  end
29
+
30
+ def test_tarize
31
+ TmpFile.with_path do |source|
32
+ Open.write(source.data.file1, 'test1')
33
+ Open.write(source.data.file2, 'test2')
34
+ TmpFile.with_path extension: 'tar.gz' do |tarball|
35
+ Misc.tarize(source, tarball)
36
+ TmpFile.with_path do |dest|
37
+ Misc.untar(tarball, dest)
38
+ assert dest.data.file1.exists?
39
+ assert_equal 'test2', Open.read(dest.data.file2)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ def test_tarize_stream
46
+ TmpFile.with_path do |source|
47
+ Open.write(source.data.file1, 'test1')
48
+ Open.write(source.data.file2, 'test2')
49
+ stream = Misc.tarize(source)
50
+ TmpFile.with_path do |dest|
51
+ Misc.untar(stream, dest)
52
+ assert dest.data.file1.exists?
53
+ assert_equal 'test2', Open.read(dest.data.file2)
54
+ end
55
+ end
56
+ end
29
57
  end
30
58
 
@@ -0,0 +1,14 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestMiscHelper < Test::Unit::TestCase
5
+ def test_divide
6
+ assert_equal 2, Misc.divide(%w(1 2 3 4 5 6 7 8 9),2).length
7
+ end
8
+
9
+ def test_ordered_divide
10
+ assert_equal 5, Misc.ordered_divide(%w(1 2 3 4 5 6 7 8 9),2).length
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,9 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestMiscMath < Test::Unit::TestCase
5
+ def test_mean
6
+ assert_equal 4, Misc.mean([6,2])
7
+ end
8
+ end
9
+
@@ -106,5 +106,37 @@ class TestPathFind < Test::Unit::TestCase
106
106
  end
107
107
  end
108
108
 
109
+ def test_plain_map
110
+ path = Path.setup("somefile")
111
+ TmpFile.with_path do |tmpdir|
112
+ Open.write(tmpdir.somefile, 'test')
113
+ path.path_maps["tmpdir"] = tmpdir
114
+ assert path.exists?
115
+ end
116
+ end
117
+
118
+ def test_add_path
119
+ TmpFile.with_path do |dir1|
120
+ TmpFile.with_path do |dir2|
121
+ TmpFile.with_path do |dir3|
122
+ TmpFile.with_path do |dir4|
123
+ Open.write(dir1.foo, "FOO1")
124
+ Open.write(dir2.foo, "FOO2")
125
+ Open.write(dir3.foo, "FOO3")
126
+ Open.write(dir4.foo, "FOO4")
127
+ file = Path.setup('foo')
128
+ file.append_path 'dir1', dir1
129
+ assert_equal "FOO1", Open.read(file)
130
+ file.prepend_path 'dir2', dir2
131
+ assert_equal "FOO2", Open.read(file)
132
+ file.prepend_path 'dir3', dir3
133
+ assert_equal "FOO3", Open.read(file)
134
+ file.append_path 'dir4', dir4
135
+ assert_equal "FOO3", Open.read(file)
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
109
141
  end
110
142
 
@@ -0,0 +1,169 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestAnnotation < Test::Unit::TestCase
5
+
6
+ module EmptyAnnotationClass
7
+ extend Annotation
8
+ end
9
+
10
+ module AnnotationClass
11
+ extend Annotation
12
+
13
+ annotation :code, :code2
14
+ end
15
+
16
+ module AnnotationClass2
17
+ extend Annotation
18
+
19
+ annotation :code3, :code4
20
+ end
21
+
22
+ module AnnotationClassInherit
23
+ extend Annotation
24
+
25
+ annotation :code_pre
26
+
27
+ include AnnotationClass
28
+ include AnnotationClass2
29
+
30
+ annotation :code5
31
+ end
32
+
33
+ def test_setup_annotate
34
+ str = "String"
35
+ refute Annotation.is_annotated?(str)
36
+ AnnotationClass.setup(str, :code)
37
+ assert AnnotationClass === str
38
+ assert Annotation.is_annotated?(str)
39
+ assert_equal :code, str.code
40
+
41
+ str2 = "String2"
42
+ str.annotate(str2)
43
+ assert_equal :code, str2.code
44
+ end
45
+
46
+ def test_inheritance
47
+ str = "String"
48
+ AnnotationClass.setup(str, :c, :c2)
49
+ assert_equal :c, str.code
50
+
51
+ str = "String"
52
+ AnnotationClassInherit.setup(str, :c_pre, :c, :c2, :c3, :c4, :c5)
53
+ assert_equal :c_pre, str.code_pre
54
+ assert_equal :c, str.code
55
+ assert_equal :c4, str.code4
56
+ assert_equal :c5, str.code5
57
+ end
58
+
59
+ def test_setup_annotate_double
60
+ str = "String"
61
+ AnnotationClass.setup(str, :c, :c2)
62
+ AnnotationClass2.setup(str, :c3, :c4)
63
+ assert Annotation.is_annotated?(str)
64
+ assert AnnotationClass === str
65
+ assert AnnotationClass2 === str
66
+ assert_equal :c, str.code
67
+ assert_equal :c2, str.code2
68
+ assert_equal :c3, str.code3
69
+ assert_equal :c4, str.code4
70
+
71
+ str2 = "String2"
72
+ str.annotate(str2)
73
+ assert Annotation.is_annotated?(str2)
74
+ assert AnnotationClass === str2
75
+ assert AnnotationClass2 === str2
76
+ assert_equal :c, str2.code
77
+ assert_equal :c2, str2.code2
78
+ assert_equal :c3, str2.code3
79
+ assert_equal :c4, str2.code4
80
+ end
81
+
82
+ def test_marshal
83
+ str = "String"
84
+ AnnotationClass.setup(str, :code)
85
+ assert AnnotationClass === str
86
+ assert_equal :code, str.code
87
+
88
+ str2 = Marshal.load(Marshal.dump(str))
89
+ assert_equal :code, str2.code
90
+ end
91
+
92
+ def test_setup_alternatives
93
+ str = "String"
94
+
95
+ AnnotationClass.setup(str, nil, :code)
96
+ assert_equal nil, str.code
97
+ assert_equal :code, str.code2
98
+
99
+ AnnotationClass.setup(str, :code2 => :code)
100
+ assert_equal :code, str.code2
101
+
102
+ AnnotationClass.setup(str, code2: :code)
103
+ assert_equal :code, str.code2
104
+
105
+ AnnotationClass.setup(str, "code2" => :code)
106
+ assert_equal :code, str.code2
107
+ end
108
+
109
+ def test_setup_block
110
+ o = AnnotationClass.setup nil, :code => :c, :code2 => :c2 do
111
+ puts 1
112
+ end
113
+
114
+ assert o.annotation_hash.include?(:code)
115
+ assert o.annotation_hash.include?(:code2)
116
+ end
117
+
118
+ def test_twice
119
+ str = "String"
120
+
121
+ AnnotationClass.setup(str, :code2 => :code)
122
+ assert_equal :code, str.code2
123
+ assert_include str.instance_variable_get(:@annotations), :code
124
+
125
+ str.extend AnnotationClass2
126
+ str.code3 = :code_alt
127
+ assert_equal :code, str.code2
128
+ assert_equal :code_alt, str.code3
129
+ assert_include str.instance_variable_get(:@annotations), :code
130
+ assert_include str.instance_variable_get(:@annotations), :code3
131
+
132
+ assert_include str.annotation_hash, :code
133
+ assert_include str.annotation_hash, :code3
134
+ end
135
+
136
+ def test_annotation_types
137
+ str = "String"
138
+ AnnotationClass.setup(str, :code)
139
+ assert AnnotationClass === str
140
+ assert_include str.annotation_types, AnnotationClass
141
+ end
142
+
143
+ def test_meta_setup
144
+ str = "String"
145
+ Annotation.setup(str, [AnnotationClass], code: 'Some code')
146
+
147
+ assert_equal 'Some code', str.code
148
+ end
149
+
150
+ def test_empty
151
+ refute EmptyAnnotationClass.setup("foo").nil?
152
+ end
153
+
154
+ def test_dump
155
+ a = AnnotationClass.setup("a", code: 'test1', code2: 'test2')
156
+ d = Marshal.dump(a)
157
+ a2 = Marshal.load(d)
158
+ assert_equal 'test1', a2.code
159
+ end
160
+
161
+ def test_dump_array
162
+ a = AnnotationClass.setup(["a"], code: 'test1', code2: 'test2')
163
+ a.extend AnnotatedArray
164
+ d = Marshal.dump(a)
165
+ a2 = Marshal.load(d)
166
+ assert_equal 'test1', a2.first.code
167
+ end
168
+ end
169
+
@@ -158,11 +158,27 @@ class TestPersist < Test::Unit::TestCase
158
158
  end
159
159
 
160
160
  def test_path_prefix
161
- Persist.persist('foo', :tsv, :prefix => "TSV") do |filename|
161
+ Persist.persist('foo', :marshal, :prefix => "TSV") do |filename|
162
162
  assert File.basename(filename).start_with? "TSV"
163
163
  end
164
164
  end
165
165
 
166
+ def test_persist_with_data
167
+ res = Persist.persist('foo', :marshal, :prefix => "TSV", :data => {3 => 4}) do |data|
168
+ data[1] = 2
169
+ end
170
+ assert_equal 2, res[1]
171
+ assert_equal 4, res[3]
172
+ res2 = nil
173
+ assert_nothing_raised do
174
+ res2 = Persist.persist('foo', :marshal, :prefix => "TSV", :data => {}) do |data|
175
+ raise
176
+ end
177
+ end
178
+ assert_equal 2, res2[1]
179
+ assert_equal 4, res2[3]
180
+ end
181
+
166
182
  def __test_speed
167
183
  times = 100_000
168
184
  TmpFile.with_file do |tmpfile|
@@ -1,6 +1,7 @@
1
1
  require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
2
  require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
3
 
4
+ require 'scout/resource/scout'
4
5
  class TestResourceUnit < Test::Unit::TestCase
5
6
  module TestResource
6
7
  extend Resource
@@ -8,19 +9,18 @@ class TestResourceUnit < Test::Unit::TestCase
8
9
  self.subdir = Path.setup('tmp/test-resource')
9
10
  end
10
11
 
11
-
12
12
  def test_root
13
13
 
14
14
  p = TestResource.root.some_file
15
15
  assert p.find(:user).include?(ENV["HOME"])
16
16
  end
17
17
 
18
- def __test_identify
19
- assert_equal 'etc/', Rbbt.identify(File.join(ENV["HOME"], '.rbbt/etc/'))
20
- assert_equal 'share/databases/', Rbbt.identify('/usr/local/share/rbbt/databases/')
21
- assert_equal 'share/databases/DATABASE', Rbbt.identify('/usr/local/share/rbbt/databases/DATABASE')
22
- assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify('/usr/local/share/rbbt/databases/DATABASE/FILE')
23
- assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify(File.join(ENV["HOME"], '.rbbt/share/databases/DATABASE/FILE'))
24
- assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify('/usr/local/share/rbbt/databases/DATABASE/FILE')
18
+ def test_identify
19
+ assert_equal 'etc', Scout.identify(File.join(ENV["HOME"], '.scout/etc'))
20
+ assert_equal 'share/databases', Resource.identify('/usr/local/share/scout/databases/')
21
+ assert_equal 'share/databases/DATABASE', Resource.identify('/usr/local/share/scout/databases/DATABASE')
22
+ assert_equal 'share/databases/DATABASE/FILE', Resource.identify('/usr/local/share/scout/databases/DATABASE/FILE')
23
+ assert_equal 'share/databases/DATABASE/FILE', Resource.identify(File.join(ENV["HOME"], '.scout/share/databases/DATABASE/FILE'))
24
+ assert_equal 'share/databases/DATABASE/FILE', Resource.identify('/usr/local/share/scout/databases/DATABASE/FILE')
25
25
  end
26
26
  end