tap 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Basic Overview +151 -0
- data/Command Reference +99 -0
- data/History +24 -0
- data/MIT-LICENSE +1 -1
- data/README +29 -57
- data/Rakefile +30 -37
- data/Tutorial +243 -191
- data/bin/tap +66 -35
- data/lib/tap.rb +47 -29
- data/lib/tap/app.rb +700 -342
- data/lib/tap/{script → cmd}/console.rb +0 -0
- data/lib/tap/{script → cmd}/destroy.rb +0 -0
- data/lib/tap/{script → cmd}/generate.rb +0 -0
- data/lib/tap/cmd/run.rb +156 -0
- data/lib/tap/constants.rb +4 -0
- data/lib/tap/dump.rb +57 -0
- data/lib/tap/env.rb +316 -0
- data/lib/tap/file_task.rb +106 -109
- data/lib/tap/generator.rb +4 -1
- data/lib/tap/generator/generators/command/USAGE +6 -0
- data/lib/tap/generator/generators/command/command_generator.rb +17 -0
- data/lib/tap/generator/generators/{script/templates/script.erb → command/templates/command.erb} +10 -10
- data/lib/tap/generator/generators/config/USAGE +21 -0
- data/lib/tap/generator/generators/config/config_generator.rb +17 -7
- data/lib/tap/generator/generators/file_task/USAGE +3 -0
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +16 -0
- data/lib/tap/generator/generators/file_task/templates/file.txt +2 -0
- data/lib/tap/generator/generators/file_task/templates/file.yml +3 -0
- data/lib/tap/generator/generators/file_task/templates/task.erb +26 -20
- data/lib/tap/generator/generators/file_task/templates/test.erb +20 -10
- data/lib/tap/generator/generators/generator/generator_generator.rb +1 -1
- data/lib/tap/generator/generators/generator/templates/generator.erb +21 -12
- data/lib/tap/generator/generators/root/templates/Rakefile +33 -24
- data/lib/tap/generator/generators/root/templates/tap.yml +28 -31
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +1 -0
- data/lib/tap/generator/generators/task/USAGE +3 -0
- data/lib/tap/generator/generators/task/task_generator.rb +18 -5
- data/lib/tap/generator/generators/task/templates/task.erb +7 -12
- data/lib/tap/generator/generators/task/templates/test.erb +10 -11
- data/lib/tap/generator/generators/workflow/templates/task.erb +1 -1
- data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
- data/lib/tap/patches/rake/rake_test_loader.rb +8 -0
- data/lib/tap/patches/rake/testtask.rb +55 -0
- data/lib/tap/patches/ruby19/backtrace_filter.rb +51 -0
- data/lib/tap/patches/ruby19/parsedate.rb +16 -0
- data/lib/tap/root.rb +172 -67
- data/lib/tap/script.rb +70 -336
- data/lib/tap/support/aggregator.rb +55 -0
- data/lib/tap/support/audit.rb +281 -280
- data/lib/tap/support/batchable.rb +59 -0
- data/lib/tap/support/class_configuration.rb +279 -0
- data/lib/tap/support/configurable.rb +92 -0
- data/lib/tap/support/configurable_methods.rb +296 -0
- data/lib/tap/support/executable.rb +98 -0
- data/lib/tap/support/executable_queue.rb +82 -0
- data/lib/tap/support/logger.rb +9 -15
- data/lib/tap/support/rake.rb +43 -54
- data/lib/tap/support/run_error.rb +32 -13
- data/lib/tap/support/shell_utils.rb +47 -0
- data/lib/tap/support/tdoc.rb +9 -8
- data/lib/tap/support/tdoc/config_attr.rb +40 -16
- data/lib/tap/support/validation.rb +77 -0
- data/lib/tap/support/versions.rb +36 -36
- data/lib/tap/task.rb +276 -482
- data/lib/tap/test.rb +20 -261
- data/lib/tap/test/env_vars.rb +7 -5
- data/lib/tap/test/file_methods.rb +126 -121
- data/lib/tap/test/subset_methods.rb +86 -45
- data/lib/tap/test/tap_methods.rb +271 -0
- data/lib/tap/workflow.rb +174 -46
- data/test/app/config/another/task.yml +1 -0
- data/test/app/config/erb.yml +2 -1
- data/test/app/config/some/task.yml +1 -0
- data/test/app/config/template.yml +2 -6
- data/test/app_test.rb +1241 -1008
- data/test/env/test_configure/recurse_a.yml +2 -0
- data/test/env/test_configure/recurse_b.yml +2 -0
- data/test/env/test_configure/tap.yml +23 -0
- data/test/env/test_load_env_config/dir/tap.yml +3 -0
- data/test/env/test_load_env_config/recurse_a.yml +2 -0
- data/test/env/test_load_env_config/recurse_b.yml +2 -0
- data/test/env/test_load_env_config/tap.yml +3 -0
- data/test/env_test.rb +198 -0
- data/test/file_task_test.rb +70 -53
- data/{lib/tap/generator/generators/package/USAGE → test/root/file.txt} +0 -0
- data/test/root_test.rb +621 -454
- data/test/script_test.rb +38 -174
- data/test/support/aggregator_test.rb +99 -0
- data/test/support/audit_test.rb +409 -416
- data/test/support/batchable_test.rb +74 -0
- data/test/support/{task_configuration_test.rb → class_configuration_test.rb} +106 -47
- data/test/{task/config/overriding.yml → support/configurable/config/configured.yml} +0 -0
- data/test/support/configurable_test.rb +295 -0
- data/test/support/executable_queue_test.rb +103 -0
- data/test/support/executable_test.rb +38 -0
- data/test/support/logger_test.rb +17 -17
- data/test/support/rake_test.rb +4 -2
- data/test/support/shell_utils_test.rb +24 -0
- data/test/support/tdoc_test.rb +265 -258
- data/test/support/validation_test.rb +54 -0
- data/test/support/versions_test.rb +38 -38
- data/test/tap_test_helper.rb +19 -5
- data/test/tap_test_suite.rb +5 -2
- data/test/task_base_test.rb +13 -104
- data/test/task_syntax_test.rb +300 -0
- data/test/task_test.rb +258 -381
- data/test/test/env_vars_test.rb +40 -40
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/one.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/two.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/one.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/two.txt +0 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/one.txt +0 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/two.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/one.txt +1 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_different_content}/expected/two.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/input/two.txt +1 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_missing_expected_file}/expected/one.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/two.txt +1 -0
- data/test/test/file_methods_doc/test_sub/expected/one.txt +1 -0
- data/test/test/file_methods_doc/test_sub/expected/two.txt +1 -0
- data/test/test/file_methods_doc/test_sub/input/one.txt +1 -0
- data/test/test/file_methods_doc/test_sub/input/two.txt +1 -0
- data/test/test/file_methods_doc_test.rb +29 -0
- data/test/test/file_methods_test.rb +214 -143
- data/test/test/subset_methods_test.rb +111 -115
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/a.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/b.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/a.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/b.txt +0 -0
- data/test/test/tap_methods_test.rb +399 -0
- data/test/workflow_test.rb +101 -91
- metadata +86 -70
- data/lib/tap/generator/generators/package/package_generator.rb +0 -38
- data/lib/tap/generator/generators/package/templates/package.erb +0 -186
- data/lib/tap/generator/generators/script/USAGE +0 -0
- data/lib/tap/generator/generators/script/script_generator.rb +0 -17
- data/lib/tap/script/run.rb +0 -154
- data/lib/tap/support/batch_queue.rb +0 -162
- data/lib/tap/support/combinator.rb +0 -114
- data/lib/tap/support/task_configuration.rb +0 -169
- data/lib/tap/support/template.rb +0 -81
- data/lib/tap/support/templater.rb +0 -155
- data/lib/tap/version.rb +0 -4
- data/test/app/config/addition_template.yml +0 -6
- data/test/app_class_test.rb +0 -33
- data/test/check/binding_eval.rb +0 -23
- data/test/check/define_method_check.rb +0 -22
- data/test/check/dependencies_check.rb +0 -175
- data/test/check/inheritance_check.rb +0 -22
- data/test/support/batch_queue_test.rb +0 -320
- data/test/support/combinator_test.rb +0 -249
- data/test/support/template_test.rb +0 -122
- data/test/support/templater/erb.txt +0 -2
- data/test/support/templater/erb.yml +0 -2
- data/test/support/templater/somefile.txt +0 -2
- data/test/support/templater_test.rb +0 -192
- data/test/task/config/template.yml +0 -4
- data/test/task_class_test.rb +0 -170
- data/test/task_execute_test.rb +0 -262
- data/test/test/file_methods/test_assert_expected/expected/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/expected/folder/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/input/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/input/folder/file.txt +0 -1
- data/test/test/file_methods/test_assert_files_exist/input/input_1.txt +0 -0
- data/test/test/file_methods/test_assert_files_exist/input/input_2.txt +0 -0
- data/test/test/file_methods/test_file_compare/expected/output_1.txt +0 -3
- data/test/test/file_methods/test_file_compare/expected/output_2.txt +0 -1
- data/test/test/file_methods/test_file_compare/input/input_1.txt +0 -3
- data/test/test/file_methods/test_file_compare/input/input_2.txt +0 -3
- data/test/test/file_methods/test_infer_glob/expected/file.yml +0 -0
- data/test/test/file_methods/test_infer_glob/expected/file_1.txt +0 -0
- data/test/test/file_methods/test_infer_glob/expected/file_2.txt +0 -0
- data/test/test/file_methods/test_yml_compare/expected/output_1.yml +0 -6
- data/test/test/file_methods/test_yml_compare/expected/output_2.yml +0 -6
- data/test/test/file_methods/test_yml_compare/input/input_1.yml +0 -4
- data/test/test/file_methods/test_yml_compare/input/input_2.yml +0 -4
- data/test/test_test.rb +0 -373
data/test/script_test.rb
CHANGED
@@ -1,194 +1,58 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'tap_test_helper')
|
2
2
|
require 'tap/script'
|
3
3
|
|
4
|
-
class
|
5
|
-
include Tap
|
6
|
-
|
7
|
-
acts_as_tap_test
|
8
|
-
|
9
|
-
#
|
10
|
-
# class default tests
|
11
|
-
#
|
12
|
-
|
13
|
-
def test_defaults
|
14
|
-
assert_equal({
|
15
|
-
:gems => [],
|
16
|
-
:load_once_paths => [],
|
17
|
-
:load_paths => ["lib"],
|
18
|
-
:script_paths => ["script"]},
|
19
|
-
ScriptConfig.defaults)
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# class spec_filepath test
|
24
|
-
#
|
25
|
-
|
26
|
-
def test_spec_filepath
|
27
|
-
assert_equal "tapspec.yml", ScriptConfig.spec_filepath
|
28
|
-
assert_equal "path/to/dir/tapspec.yml", ScriptConfig.spec_filepath("path/to/dir")
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# default script config
|
33
|
-
#
|
34
|
-
|
35
|
-
def test_default_script_config
|
36
|
-
config = ScriptConfig.new
|
37
|
-
assert config.kind_of?(OpenStruct)
|
38
|
-
assert_equal({
|
39
|
-
:gems => [],
|
40
|
-
:gemspecs => [],
|
41
|
-
:load_once_paths => [],
|
42
|
-
:load_paths => [app["lib"]],
|
43
|
-
:script_paths => [app["script"]]},
|
44
|
-
config.marshal_dump)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_script_config_with_inputs
|
48
|
-
config = ScriptConfig.new :key => 'value', :load_paths => ['lib', 'test']
|
49
|
-
|
50
|
-
assert_equal({
|
51
|
-
:gems => [],
|
52
|
-
:gemspecs => [],
|
53
|
-
:load_once_paths => [],
|
54
|
-
:load_paths => [app["lib"], app['test']],
|
55
|
-
:script_paths => [app["script"]],
|
56
|
-
:key => 'value'},
|
57
|
-
config.marshal_dump)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_single_arguments_are_allowed
|
61
|
-
config = ScriptConfig.new(
|
62
|
-
:load_paths => "alt",
|
63
|
-
:load_once_paths => "once")
|
64
|
-
|
65
|
-
assert_equal({
|
66
|
-
:gems => [],
|
67
|
-
:gemspecs => [],
|
68
|
-
:load_once_paths => [app["once"]],
|
69
|
-
:load_paths => [app["alt"]],
|
70
|
-
:script_paths => [app["script"]]},
|
71
|
-
config.marshal_dump)
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_gemspecs_and_paths_are_collected_for_the_specified_gem
|
75
|
-
config = ScriptConfig.new :gems => 'activesupport'
|
76
|
-
spec = Gem.loaded_specs["activesupport"]
|
77
|
-
|
78
|
-
assert_equal 'activesupport', config.gems
|
79
|
-
assert_equal [spec], config.gemspecs
|
80
|
-
assert_equal [app['lib'], File.join(spec.full_gem_path, 'lib')], config.load_paths
|
81
|
-
assert_equal [app['script'], File.join(spec.full_gem_path, 'script')], config.script_paths
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# TODO -- find a way to test the gem loading behavior,
|
86
|
-
# especially when the tapspec contains nested gems
|
87
|
-
# and when the tapspec contains unsafe filepaths
|
88
|
-
#
|
4
|
+
class ScriptTest < Test::Unit::TestCase
|
5
|
+
include Tap::Script
|
89
6
|
|
90
7
|
#
|
91
|
-
#
|
8
|
+
# split_argv test
|
92
9
|
#
|
93
|
-
end
|
94
|
-
|
95
|
-
class ScriptTest < Test::Unit::TestCase
|
96
|
-
|
97
|
-
acts_as_tap_test
|
98
10
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
11
|
+
def test_split_argv
|
12
|
+
argv = ["a", "-b", "--c", "--", "d", "-e", "--f"]
|
13
|
+
assert_equal([
|
14
|
+
[["a", "-b", "--c"], ["d", "-e", "--f"]]
|
15
|
+
], split_argv(argv))
|
104
16
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
17
|
+
argv.unshift("--")
|
18
|
+
argv.push("--")
|
19
|
+
assert_equal([
|
20
|
+
[["a", "-b", "--c"], ["d", "-e", "--f"]]
|
21
|
+
], split_argv(argv))
|
22
|
+
|
23
|
+
argv.concat ["--++", "x", "-y", "--z"]
|
24
|
+
assert_equal([
|
25
|
+
[["a", "-b", "--c"], ["d", "-e", "--f"]],
|
26
|
+
[["x", "-y", "--z"]]
|
27
|
+
], split_argv(argv))
|
28
|
+
|
29
|
+
argv.concat ["--+", "m", "-n", "--o"]
|
30
|
+
assert_equal([
|
31
|
+
[["a", "-b", "--c"], ["d", "-e", "--f"]],
|
32
|
+
[["m", "-n", "--o"]],
|
33
|
+
[["x", "-y", "--z"]]
|
34
|
+
], split_argv(argv))
|
114
35
|
end
|
115
36
|
|
116
|
-
def script
|
117
|
-
Tap::Script.instance
|
118
|
-
end
|
119
|
-
|
120
|
-
def tap_lib_dir
|
121
|
-
File.expand_path(File.dirname(__FILE__) + "/../lib")
|
122
|
-
end
|
123
|
-
|
124
37
|
#
|
125
|
-
#
|
38
|
+
# parse_yaml tests
|
126
39
|
#
|
127
40
|
|
128
|
-
def
|
129
|
-
|
130
|
-
|
131
|
-
assert_equal
|
132
|
-
assert_equal
|
133
|
-
assert_equal [tap_lib_dir, app['lib']], config.load_paths
|
134
|
-
assert_equal [app['script']], config.script_paths
|
135
|
-
|
136
|
-
config = script.configure_app :load_paths => ['alt'], :key => 'value'
|
137
|
-
|
138
|
-
assert_equal [], config.gemspecs
|
139
|
-
assert_equal [], config.load_once_paths
|
140
|
-
assert_equal [tap_lib_dir, app['alt']], config.load_paths
|
141
|
-
assert_equal [app['script']], config.script_paths
|
142
|
-
assert_equal 'value', config.key
|
41
|
+
def test_parse_yaml_documentation
|
42
|
+
str = {'key' => 'value'}.to_yaml
|
43
|
+
assert_equal "--- \nkey: value\n", str
|
44
|
+
assert_equal({'key' => 'value'}, parse_yaml(str))
|
45
|
+
assert_equal "str", parse_yaml("str")
|
143
46
|
end
|
144
47
|
|
145
|
-
def
|
146
|
-
|
147
|
-
assert_equal
|
148
|
-
assert_equal [], Dependencies.load_once_paths
|
149
|
-
|
150
|
-
script.configure_app
|
151
|
-
|
152
|
-
assert $LOAD_PATH.include?( app['lib'] )
|
153
|
-
|
154
|
-
assert_equal [tap_lib_dir, app['lib']], Dependencies.load_paths
|
155
|
-
assert_equal [], Dependencies.load_once_paths
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_configure_app_resolves_aliases_and_sets_paths
|
159
|
-
app['lib'] = "alt_lib"
|
160
|
-
app['script'] = "alt_script"
|
161
|
-
app['load_once'] = "load/once/lib"
|
162
|
-
|
163
|
-
assert !$LOAD_PATH.include?( app['lib'] )
|
164
|
-
assert_equal [], Dependencies.load_paths
|
165
|
-
assert_equal [], Dependencies.load_once_paths
|
166
|
-
|
167
|
-
script.configure_app(
|
168
|
-
:load_paths => ["lib", "load_once"],
|
169
|
-
:load_once_paths => ["load_once"],
|
170
|
-
:script_paths => ['script'])
|
171
|
-
|
172
|
-
assert $LOAD_PATH.include?( app['lib'] )
|
173
|
-
assert $LOAD_PATH.include?( app['load_once'] )
|
174
|
-
|
175
|
-
assert_equal [tap_lib_dir, app['lib'], app['load_once']], Dependencies.load_paths
|
176
|
-
assert_equal [app['load_once']], Dependencies.load_once_paths
|
48
|
+
def test_parse_yaml_loads_arg_if_arg_matches_yaml_document_string
|
49
|
+
string = "---\nkey: value"
|
50
|
+
assert_equal({"key" => "value"}, parse_yaml(string))
|
177
51
|
end
|
178
52
|
|
179
|
-
def
|
180
|
-
|
181
|
-
|
182
|
-
:load_paths => [],
|
183
|
-
:load_once_paths => ["lib"])
|
184
|
-
end
|
53
|
+
def test_parse_yaml_returns_arg_unless_matches_yaml_document_string
|
54
|
+
string = "key: value"
|
55
|
+
assert_equal("key: value", parse_yaml(string))
|
185
56
|
end
|
186
57
|
|
187
|
-
#
|
188
|
-
# split_to_length test
|
189
|
-
#
|
190
|
-
|
191
|
-
# def test_split_to_length
|
192
|
-
# assert_equal ["a a a a", "aaa aa ","a "], Tap::Script.split_to_length("a a a a aaa aa \na", 7)
|
193
|
-
# end
|
194
58
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../tap_test_helper')
|
2
|
+
require 'tap/support/aggregator'
|
3
|
+
require 'tap/support/audit'
|
4
|
+
|
5
|
+
class AggregatorTest < Test::Unit::TestCase
|
6
|
+
include Tap::Support
|
7
|
+
|
8
|
+
attr_accessor :aggregator
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@aggregator = Aggregator.new
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# store test
|
16
|
+
#
|
17
|
+
|
18
|
+
def test_store_appends_audit_to_array_keyed_by_current_source
|
19
|
+
a = Audit.new
|
20
|
+
a._record(:a, 1)
|
21
|
+
assert_equal :a, a._current_source
|
22
|
+
|
23
|
+
aggregator.store(a)
|
24
|
+
assert_equal({:a => [a]}, aggregator.to_hash)
|
25
|
+
|
26
|
+
aggregator.store(a)
|
27
|
+
assert_equal({:a => [a, a]}, aggregator.to_hash)
|
28
|
+
|
29
|
+
a._record(:b, 2)
|
30
|
+
assert_equal :b, a._current_source
|
31
|
+
|
32
|
+
aggregator.store(a)
|
33
|
+
assert_equal({:a => [a, a], :b => [a]}, aggregator.to_hash)
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# clear test
|
38
|
+
#
|
39
|
+
|
40
|
+
def test_clear
|
41
|
+
a = Audit.new
|
42
|
+
a._record(:a, 1)
|
43
|
+
|
44
|
+
aggregator.store(a)
|
45
|
+
aggregator.store(a)
|
46
|
+
assert_equal({:a => [a, a]}, aggregator.to_hash)
|
47
|
+
|
48
|
+
aggregator.clear
|
49
|
+
assert_equal({}, aggregator.to_hash)
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# retrieve test
|
54
|
+
#
|
55
|
+
|
56
|
+
def test_retrieve_returns_array_for_source
|
57
|
+
a = Audit.new
|
58
|
+
a._record(:a, 1)
|
59
|
+
|
60
|
+
aggregator.store(a)
|
61
|
+
aggregator.store(a)
|
62
|
+
assert_equal({:a => [a, a]}, aggregator.to_hash)
|
63
|
+
|
64
|
+
assert_equal [a,a], aggregator.retrieve(:a)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_retrieve_returns_nil_for_unknown_source
|
68
|
+
assert_nil aggregator.retrieve(:unknown)
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# retrieve_all test
|
73
|
+
#
|
74
|
+
|
75
|
+
def test_retrieve_all_returns_concatenated_arrays_for_sources
|
76
|
+
a = Audit.new
|
77
|
+
a._record(:a, 1)
|
78
|
+
|
79
|
+
aggregator.store(a)
|
80
|
+
aggregator.store(a)
|
81
|
+
|
82
|
+
b = Audit.new
|
83
|
+
b._record(:b, 1)
|
84
|
+
aggregator.store(b)
|
85
|
+
|
86
|
+
assert_equal({:a => [a, a], :b => [b]}, aggregator.to_hash)
|
87
|
+
|
88
|
+
assert_equal [a,a], aggregator.retrieve_all(:a)
|
89
|
+
assert_equal [b], aggregator.retrieve_all(:b)
|
90
|
+
assert_equal [a,a,b], aggregator.retrieve_all(:a, :b)
|
91
|
+
assert_equal [b,a,a], aggregator.retrieve_all(:b, :a)
|
92
|
+
|
93
|
+
assert_equal [a,a,b], aggregator.retrieve_all(:a, :unknown, :b)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_retrieve_all_returns_empty_array_for_all_unknown_sources
|
97
|
+
assert_equal [], aggregator.retrieve_all(:a, :unknown, :b)
|
98
|
+
end
|
99
|
+
end
|
data/test/support/audit_test.rb
CHANGED
@@ -2,311 +2,275 @@ require File.dirname(__FILE__) + '/../tap_test_helper'
|
|
2
2
|
require 'tap/support/audit'
|
3
3
|
|
4
4
|
class AuditTest < Test::Unit::TestCase
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
def test_value_trail_returns_value_trail_when_source_is_an_audit
|
276
|
-
c = setup_audit(:p, a, :q)
|
277
|
-
|
278
|
-
assert_equal [nil, :p, a, :q], c._sources
|
279
|
-
assert_equal [nil, 'p', [nil, 'a', 'b', 'c'], 'q'], c._value_trail
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_value_trail_resolves_each_member_in_an_arrays_of_sources
|
283
|
-
c = setup_audit(:p, [a, b, :q], [:r, :s], :t)
|
284
|
-
|
285
|
-
assert_equal [nil, 'p', [[nil, 'a', 'b', 'c'], [nil, 'x', 'y', 'z'], 'q'],['r', 's'], 't'], c._value_trail
|
286
|
-
end
|
287
|
-
|
288
|
-
#
|
289
|
-
# merge tests
|
290
|
-
#
|
291
|
-
|
292
|
-
def test_merge_returns_new_audit_with_self_added_to_sources_and_value_as_array_of_current_values
|
293
|
-
c = a._merge(b, 'p')
|
294
|
-
c._record(:q, 'q')
|
295
|
-
c._record(:r, 'r')
|
296
|
-
|
297
|
-
assert_equal [[a, b, nil], :q, :r], c._sources
|
298
|
-
assert_equal [['c', 'z', 'p'], 'q', 'r'], c._values
|
299
|
-
assert_equal [[[nil, :a, :b, :c], [nil, :x, :y, :z], nil], :q, :r], c._source_trail
|
300
|
-
end
|
301
|
-
|
302
|
-
def test_merge_with_no_sources_provided_returns_fork
|
303
|
-
c = a._merge
|
304
|
-
|
305
|
-
assert_not_equal a.object_id, c.object_id
|
306
|
-
assert_equal a._sources, c._sources
|
307
|
-
assert_equal a._values, c._values
|
308
|
-
end
|
309
|
-
|
5
|
+
include Tap::Support
|
6
|
+
|
7
|
+
attr_reader :audit, :a, :b
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@audit = Audit.new('original')
|
11
|
+
@a = setup_audit(:a, :b, :c)
|
12
|
+
@b = setup_audit(:x, :y, :z)
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# methods to setup audits for testing, and tests of the setup
|
17
|
+
#
|
18
|
+
|
19
|
+
def setup_audit(*sources)
|
20
|
+
audit = Audit.new
|
21
|
+
sources.each do |source|
|
22
|
+
value = case source
|
23
|
+
when Array
|
24
|
+
source.collect {|s| s.to_s }
|
25
|
+
else
|
26
|
+
source.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
audit._record(source, value)
|
30
|
+
end
|
31
|
+
audit
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_setup
|
35
|
+
assert_equal [nil], audit._sources
|
36
|
+
assert_equal ['original'], audit._values
|
37
|
+
assert_equal 'original', audit._original
|
38
|
+
assert_equal 'original', audit._current
|
39
|
+
|
40
|
+
assert_equal [:a, :b, :c], a._sources
|
41
|
+
assert_equal ['a', 'b', 'c'], a._values
|
42
|
+
assert_equal 'c', a._current
|
43
|
+
assert_equal 'a', a._original
|
44
|
+
|
45
|
+
assert_equal [:x, :y, :z], b._sources
|
46
|
+
assert_equal ['x', 'y', 'z'], b._values
|
47
|
+
assert_equal 'z', b._current
|
48
|
+
assert_equal 'x', b._original
|
49
|
+
|
50
|
+
c = setup_audit([a, b, :c])
|
51
|
+
assert_equal [[a, b, :c]], c._sources
|
52
|
+
assert_equal [[a.to_s, b.to_s, 'c']], c._values
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# documentation tests
|
57
|
+
#
|
58
|
+
|
59
|
+
def test_documentation
|
60
|
+
# initialize a new audit
|
61
|
+
a = Audit.new(1, nil)
|
62
|
+
|
63
|
+
# record some values
|
64
|
+
a._record(:A, 2)
|
65
|
+
a._record(:B, 3)
|
66
|
+
|
67
|
+
assert_equal [nil, :A, :B], a._source_trail
|
68
|
+
assert_equal [1, 2, 3], a._value_trail
|
69
|
+
assert_equal 1, a._original
|
70
|
+
assert_equal nil, a._original_source
|
71
|
+
assert_equal 3, a._current
|
72
|
+
assert_equal :B, a._current_source
|
73
|
+
|
74
|
+
b = Audit.new(10, nil)
|
75
|
+
b._record(:C, 11)
|
76
|
+
b._record(:D, 12)
|
77
|
+
|
78
|
+
c = Audit.merge(a, b)
|
79
|
+
assert_equal [ [[nil, :A, :B], [nil, :C, :D]] ], c._source_trail
|
80
|
+
assert_equal [ [[1,2,3], [10, 11, 12]] ], c._value_trail
|
81
|
+
assert_equal [3, 12], c._current
|
82
|
+
|
83
|
+
c._record(:E, "a string value")
|
84
|
+
c._record(:F, {'a' => 'hash value'})
|
85
|
+
c._record(:G, ['an', 'array', 'value'])
|
86
|
+
|
87
|
+
assert_equal [ [[nil, :A, :B], [nil, :C, :D]], :E, :F, :G], c._source_trail
|
88
|
+
assert_equal [ [[1,2,3], [10, 11, 12]], "a string value", {'a' => 'hash value'}, ['an', 'array', 'value']], c._value_trail
|
89
|
+
|
90
|
+
a1 = a._fork
|
91
|
+
a._record(:X, -1)
|
92
|
+
a1._record(:Y, -2)
|
93
|
+
|
94
|
+
assert_equal [nil, :A, :B, :X], a._source_trail
|
95
|
+
assert_equal [nil, :A, :B, :Y], a1._source_trail
|
96
|
+
assert_equal [ [[nil, :A, :B], [nil, :C, :D]], :E, :F, :G], c._source_trail
|
97
|
+
|
98
|
+
expected = %Q{o-[] 1
|
99
|
+
o-[A] 2
|
100
|
+
o-[B] 3
|
101
|
+
|
|
102
|
+
| o-[] 10
|
103
|
+
| o-[C] 11
|
104
|
+
| o-[D] 12
|
105
|
+
| |
|
106
|
+
`-`-o-[E] "a string value"
|
107
|
+
o-[F] {"a"=>"hash value"}
|
108
|
+
o-[G] ["an", "array", "value"]
|
109
|
+
}
|
110
|
+
|
111
|
+
assert_equal expected, c._to_s
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# Audit merge tests
|
116
|
+
#
|
117
|
+
|
118
|
+
def test_merge_documentation
|
119
|
+
a = Audit.new
|
120
|
+
a._record(:a, 'a')
|
121
|
+
|
122
|
+
b = Audit.new
|
123
|
+
b._record(:b, 'b')
|
124
|
+
|
125
|
+
c = Audit.merge(a, b, 1)
|
126
|
+
c._record(:c, 'c')
|
127
|
+
|
128
|
+
assert_equal [['a','b', 1], 'c'], c._values
|
129
|
+
assert_equal [AuditMerge[a, b, Audit.new(1)], :c], c._sources
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_merge
|
133
|
+
c = Audit.merge(a, b, 'p')
|
134
|
+
c._record(:q, 'q')
|
135
|
+
c._record(:r, 'r')
|
136
|
+
|
137
|
+
assert_equal [AuditMerge[a, b, Audit.new('p')], :q, :r], c._sources
|
138
|
+
assert_equal [['c', 'z', 'p'], 'q', 'r'], c._values
|
139
|
+
|
140
|
+
assert_equal [[[:a, :b, :c], [:x, :y, :z], [nil]], :q, :r], c._source_trail
|
141
|
+
assert_equal [[['a', 'b', 'c'], ['x', 'y', 'z'], ['p']], 'q', 'r'], c._value_trail
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_merge_with_one_input_returns_fork
|
145
|
+
c = Audit.merge(a)
|
146
|
+
assert_equal c, a
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_merge_with_no_inputs_returns_new_audit
|
150
|
+
a = Audit.merge
|
151
|
+
assert_equal Audit.new, a
|
152
|
+
end
|
153
|
+
|
154
|
+
#
|
155
|
+
# record tests
|
156
|
+
#
|
157
|
+
|
158
|
+
def test_record
|
159
|
+
audit._record(:a, 'next')
|
160
|
+
audit._record(:b, 'final')
|
161
|
+
|
162
|
+
assert_equal [nil, :a, :b], audit._sources
|
163
|
+
assert_equal ['original', 'next', 'final'], audit._values
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_record_with_arrays_and_audits
|
167
|
+
audit._record(:a, a)
|
168
|
+
audit._record(:array, [a, b, 'str'])
|
169
|
+
|
170
|
+
assert_equal [nil, :a, :array], audit._sources
|
171
|
+
assert_equal ['original', a, [a, b, 'str']], audit._values
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_record_returns_self
|
175
|
+
assert audit, audit._record(:a, 'next')
|
176
|
+
end
|
177
|
+
|
178
|
+
#
|
179
|
+
# original tests
|
180
|
+
#
|
181
|
+
|
182
|
+
def test_original_is_first_recorded_value
|
183
|
+
a = Audit.new('a', :a)
|
184
|
+
assert_equal 'a', a._original
|
185
|
+
|
186
|
+
audit._record(:b, 'next')
|
187
|
+
assert_equal 'a', a._original
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_original_source_is_original_recorded_source
|
191
|
+
a = Audit.new('a', :a)
|
192
|
+
assert_equal :a, a._original_source
|
193
|
+
|
194
|
+
audit._record(:b, 'next')
|
195
|
+
assert_equal :a, a._original_source
|
196
|
+
end
|
197
|
+
|
198
|
+
#
|
199
|
+
# current tests
|
200
|
+
#
|
201
|
+
|
202
|
+
def test_current_is_last_recorded_value
|
203
|
+
audit._record(:a, 'next')
|
204
|
+
assert_equal 'next', audit._current
|
205
|
+
|
206
|
+
audit._record(:a, 'final')
|
207
|
+
assert_equal 'final', audit._current
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_current_source_is_last_recorded_source
|
211
|
+
audit._record(:a, 'next')
|
212
|
+
assert_equal :a, audit._current_source
|
213
|
+
|
214
|
+
audit._record(:b, 'final')
|
215
|
+
assert_equal :b, audit._current_source
|
216
|
+
end
|
217
|
+
|
218
|
+
#
|
219
|
+
# source trail tests
|
220
|
+
#
|
221
|
+
|
222
|
+
def test_source_trail_helper_method_is_hidden
|
223
|
+
assert !a.respond_to?(:source_trail)
|
224
|
+
assert_raise(NoMethodError) { a.source_trail }
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_source_trail_returns_all_sources
|
228
|
+
a = setup_audit(:a, :b, :c)
|
229
|
+
|
230
|
+
assert_equal [:a, :b, :c], a._source_trail
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_source_trail_returns_source_trail_when_source_is_an_audit
|
234
|
+
c = setup_audit(:p, a, :q)
|
235
|
+
|
236
|
+
assert_equal [:p, a, :q], c._sources
|
237
|
+
assert_equal [:p, [:a, :b, :c], :q], c._source_trail
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_source_trail_resolves_each_member_in_an_audit_merge_source
|
241
|
+
c = setup_audit(:p, AuditMerge[a, b, :q], [:r, :s], :t)
|
242
|
+
|
243
|
+
assert_equal [:p, [[:a, :b, :c], [:x, :y, :z], :q],[:r, :s], :t], c._source_trail
|
244
|
+
end
|
245
|
+
|
246
|
+
#
|
247
|
+
# value trail tests
|
248
|
+
#
|
249
|
+
|
250
|
+
def test_value_trail_helper_method_is_hidden
|
251
|
+
assert !a.respond_to?(:value_trail)
|
252
|
+
assert_raise(NoMethodError) { a.value_trail }
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_value_trail_returns_all_values
|
256
|
+
a = setup_audit(:a, :b, :c)
|
257
|
+
|
258
|
+
assert_equal ['a', 'b', 'c'], a._value_trail
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_value_trail_returns_value_trail_when_source_is_an_audit
|
262
|
+
c = setup_audit(:p, a, :q)
|
263
|
+
|
264
|
+
assert_equal [:p, a, :q], c._sources
|
265
|
+
assert_equal ['p', ['a', 'b', 'c'], 'q'], c._value_trail
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_value_trail_resolves_each_member_in_an_audit_merge_source
|
269
|
+
c = setup_audit(:p, AuditMerge[a, b, :q], [:r, :s], :t)
|
270
|
+
|
271
|
+
assert_equal ['p', [['a', 'b', 'c'], ['x', 'y', 'z'], 'q'],['r', 's'], 't'], c._value_trail
|
272
|
+
end
|
273
|
+
|
310
274
|
#
|
311
275
|
# test fork
|
312
276
|
#
|
@@ -328,125 +292,154 @@ class AuditTest < Test::Unit::TestCase
|
|
328
292
|
a._record(:c, 'c')
|
329
293
|
b._record(:d, 'd')
|
330
294
|
|
331
|
-
assert_equal([
|
332
|
-
assert_equal([
|
333
|
-
end
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
#
|
338
|
-
|
339
|
-
def test_split_records_block_as_source_and_return_as_value
|
340
|
-
block = lambda { |current| current += 'ar' }
|
341
|
-
c = a._split(&block)
|
342
|
-
|
343
|
-
assert_equal [a, block], c._sources
|
344
|
-
assert_equal [nil, 'car'], c._values
|
345
|
-
assert_equal [[nil, :a, :b, :c], block], c._source_trail
|
346
|
-
end
|
347
|
-
|
348
|
-
def test_split_raises_error_if_no_block_given
|
349
|
-
assert_raise(LocalJumpError) { a._split }
|
350
|
-
end
|
351
|
-
|
352
|
-
#
|
353
|
-
# comparator and method missing test
|
354
|
-
#
|
355
|
-
|
356
|
-
def test_comparators_sent_to_current
|
357
|
-
a = Audit.new(1)
|
358
|
-
assert a < 2
|
359
|
-
assert a > 0
|
360
|
-
assert a == 1
|
361
|
-
end
|
362
|
-
|
363
|
-
def test_regexp_match_sent_to_current
|
364
|
-
a = Audit.new("abcd")
|
365
|
-
assert a =~ /ab(\w)/
|
366
|
-
# note: this is not ideal behavior... should be
|
367
|
-
#assert_equal 'c', $1
|
368
|
-
assert_nil $1
|
369
|
-
|
370
|
-
assert !(a=~ /q/)
|
371
|
-
end
|
372
|
-
|
373
|
-
def test_regexp_not_match_sent_to_current
|
374
|
-
a = Audit.new("abcd")
|
375
|
-
assert !(a !~ /ab(\w)/)
|
376
|
-
# note: this is not ideal behavior... should be
|
377
|
-
#assert_equal 'c', $1
|
378
|
-
assert_nil $1
|
379
|
-
|
380
|
-
assert a !~ /q/
|
381
|
-
end
|
382
|
-
|
383
|
-
def test_missing_methods_sent_to_current
|
384
|
-
a = Audit.new("abcd")
|
385
|
-
assert "ABCD", a.upcase
|
386
|
-
|
387
|
-
a = Audit.new(3)
|
388
|
-
assert a > 2
|
389
|
-
assert a <= 3
|
390
|
-
end
|
391
|
-
|
392
|
-
#
|
393
|
-
# documentation tests
|
295
|
+
assert_equal([:a, :b, :c], a._sources)
|
296
|
+
assert_equal([:a, :b, :d], b._sources)
|
297
|
+
end
|
298
|
+
|
299
|
+
#
|
300
|
+
# split tests
|
394
301
|
#
|
395
302
|
|
396
|
-
def
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
# part 1
|
401
|
-
audit = Audit.new(3)
|
402
|
-
audit._record(:a, 4)
|
403
|
-
audit._record(:b, 5)
|
404
|
-
audit._record(:c, 7)
|
405
|
-
assert_equal([nil, :a, :b, :c], audit._source_trail)
|
303
|
+
def test_split_forks_and_records_result_yielding_to_current
|
304
|
+
block = lambda { |current| current += 'ar' }
|
305
|
+
c = a._split(&block)
|
406
306
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
307
|
+
assert_equal [:a, :b, :c, AuditSplit.new(block)], c._sources
|
308
|
+
assert_equal ['a', 'b', 'c', 'car'], c._values
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_split_raises_error_if_no_block_given
|
312
|
+
assert_raise(LocalJumpError) { a._split }
|
313
|
+
end
|
314
|
+
|
315
|
+
#
|
316
|
+
# expand tests
|
317
|
+
#
|
318
|
+
|
319
|
+
def test_expand_forks_for_and_records_each_in_current
|
320
|
+
a = Audit.new([1,2,3])
|
321
|
+
e = a._expand
|
412
322
|
|
413
|
-
|
414
|
-
fork_c._record(:c, 6)
|
415
|
-
assert_equal([nil, :a, :b], fork_b._source_trail)
|
416
|
-
assert_equal([nil, :a, :c], fork_c._source_trail)
|
323
|
+
assert_equal 3, e.length
|
417
324
|
|
418
|
-
|
419
|
-
|
420
|
-
assert_equal([[[nil,:a,:b], [nil,:a,:c]], :d], merged_audit._source_trail)
|
325
|
+
assert_equal [nil, AuditExpand.new(0)], e[0]._sources
|
326
|
+
assert_equal [[1,2,3], 1], e[0]._values
|
421
327
|
|
422
|
-
|
423
|
-
|
424
|
-
t.on_complete do |results|
|
425
|
-
results.each do |result|
|
426
|
-
|
427
|
-
assert_equal Audit, result.class
|
428
|
-
assert_equal "str", result._current
|
429
|
-
assert result == "str"
|
430
|
-
assert_equal "STR", result.upcase
|
328
|
+
assert_equal [nil, AuditExpand.new(1)], e[1]._sources
|
329
|
+
assert_equal [[1,2,3], 2], e[1]._values
|
431
330
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
331
|
+
assert_equal [nil, AuditExpand.new(2)], e[2]._sources
|
332
|
+
assert_equal [[1,2,3], 3], e[2]._values
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_expand_raises_error_if_current_does_not_respond_to_each
|
336
|
+
a = Audit.new(nil)
|
337
|
+
assert_raise(NoMethodError) { a._expand }
|
338
|
+
end
|
339
|
+
|
340
|
+
#
|
341
|
+
# _to_s test
|
342
|
+
#
|
343
|
+
|
344
|
+
def new_audit(letter, n=0)
|
345
|
+
a = Tap::Support::Audit.new
|
346
|
+
1.upto(n) {|i| a._record(letter, "#{letter}#{i}")}
|
347
|
+
a
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_to_s_for_sequence
|
351
|
+
a = Audit.new
|
352
|
+
assert_equal %Q{\n}, a._to_s
|
353
|
+
|
354
|
+
a = new_audit(:a, 3)
|
355
|
+
assert_equal %Q{
|
356
|
+
o-[a] "a1"
|
357
|
+
o-[a] "a2"
|
358
|
+
o-[a] "a3"
|
359
|
+
}[1..-1], a._to_s
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_to_s_for_fork_is_same_as_forked
|
363
|
+
a = new_audit(:a)
|
364
|
+
assert_equal a._to_s, a._fork._to_s
|
365
|
+
|
366
|
+
a = new_audit(:a, 3)._fork
|
367
|
+
assert_equal a._to_s, a._fork._to_s
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_to_s_for_merge_without_additional_records
|
371
|
+
a = new_audit(:a, 3)
|
372
|
+
b = new_audit(:b, 3)
|
373
|
+
c = Tap::Support::Audit.merge(a,b)
|
374
|
+
|
375
|
+
assert_equal %Q{
|
376
|
+
o-[a] "a1"
|
377
|
+
o-[a] "a2"
|
378
|
+
o-[a] "a3"
|
379
|
+
|
|
380
|
+
| o-[b] "b1"
|
381
|
+
| o-[b] "b2"
|
382
|
+
| o-[b] "b3"
|
383
|
+
}[1..-1], c._to_s
|
384
|
+
end
|
385
|
+
|
386
|
+
def test_to_s_for_merge_with_additional_records
|
387
|
+
a = new_audit(:a, 3)
|
388
|
+
b = new_audit(:b, 3)
|
389
|
+
c = Tap::Support::Audit.merge(a,b)
|
390
|
+
1.upto(3) {|i| c._record(:c, "c#{i}")}
|
391
|
+
|
392
|
+
assert_equal %Q{
|
393
|
+
o-[a] "a1"
|
394
|
+
o-[a] "a2"
|
395
|
+
o-[a] "a3"
|
396
|
+
|
|
397
|
+
| o-[b] "b1"
|
398
|
+
| o-[b] "b2"
|
399
|
+
| o-[b] "b3"
|
400
|
+
| |
|
401
|
+
`-`-o-[c] "c1"
|
402
|
+
o-[c] "c2"
|
403
|
+
o-[c] "c3"
|
404
|
+
}[1..-1], c._to_s
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_to_s_for_merge_with_multiple_input_audits
|
408
|
+
a = new_audit(:a, 1)
|
409
|
+
b = new_audit(:b, 1)
|
410
|
+
c = Tap::Support::Audit.merge(a,b)
|
411
|
+
1.upto(1) {|i| c._record(:c, "c#{i}")}
|
439
412
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
end
|
413
|
+
d = new_audit(:d, 1)
|
414
|
+
e = new_audit(:e, 1)
|
415
|
+
f = Tap::Support::Audit.merge(d, e, 'x1', 'y1', 'z1')
|
416
|
+
1.upto(1) {|i| f._record(:f, "f#{i}")}
|
445
417
|
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
assert_equal
|
450
|
-
|
418
|
+
g = Tap::Support::Audit.merge(c, f)
|
419
|
+
1.upto(1) {|i| g._record(:g, "g#{i}")}
|
420
|
+
|
421
|
+
assert_equal %Q{
|
422
|
+
o-[a] "a1"
|
423
|
+
|
|
424
|
+
| o-[b] "b1"
|
425
|
+
| |
|
426
|
+
`-`-o-[c] "c1"
|
427
|
+
|
|
428
|
+
| o-[d] "d1"
|
429
|
+
| |
|
430
|
+
| | o-[e] "e1"
|
431
|
+
| | |
|
432
|
+
| | | o-[] "x1"
|
433
|
+
| | | |
|
434
|
+
| | | | o-[] "y1"
|
435
|
+
| | | | |
|
436
|
+
| | | | | o-[] "z1"
|
437
|
+
| | | | | |
|
438
|
+
| `-`-`-`-`-o-[f] "f1"
|
439
|
+
| |
|
440
|
+
`-----------`-o-[g] "g1"
|
441
|
+
}[1..-1], g._to_s
|
451
442
|
end
|
443
|
+
|
444
|
+
|
452
445
|
end
|