more_unit_test 0.1.2 → 0.2.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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzcyN2QwZTc2M2VjNzljMWZmMDgwMGRhYmIyMTZiYWZhOGEzOTlkMQ==
5
+ data.tar.gz: !binary |-
6
+ NjQ5YjQ1ZWRjNWEzZjZjZTFmY2UxYzFmYjllZjg5ZjgzNzljYTJiNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDI4MWZhZjkzMTQyZThjNGFiMTFiM2Q5NWYxNmE0ZGVlYmEwOWMzNzhiN2Ez
10
+ ZTVhZDNjYzQwMmY2OGY4NzY1ZTFmOTljZTlhMzA0MzE3NjVjMGMyMDE1ZTYy
11
+ ODg1Y2JiZWJmNDI2Njk3NTQ0Y2YyNTU1MTNmYjExYmI0YmY5ODM=
12
+ data.tar.gz: !binary |-
13
+ NDUwOTdmYjkyODlhMTg3ZWI3NjgyZjFkMzJhMzcwODBmMjI5MmM2ZTNmNjFh
14
+ ODBlZDE4MWU0ZmU5YjRhNmJmMzdjYWViNGZmNDA5ZDNkYzVkYWIxYWIyNjk2
15
+ OGRlMDgzNWI2OTUxNzA5ZmQ4NmY4ZTQzMjYzOTM5ZGQ5YTFmMzA=
@@ -10,4 +10,8 @@ Compare expected result with file content
10
10
  ===more_unit_test/assert_stdout.rb
11
11
  Test for stdout/stderr
12
12
 
13
- =end
13
+ =end
14
+
15
+ module More_Unit_Test
16
+ VERSION = '0.2.0'
17
+ end
@@ -14,21 +14,17 @@ Here it is: Test::Unit::TestCase#assert_equal_filecontent
14
14
  See http://rubyforge.org/tracker/?func=detail&aid=19509&group_id=5650&atid=21859
15
15
 
16
16
  ==Ruby 1.9
17
- With ruby 1.9 you get an additional encoding problem.
18
- The "expected"-file is read with a default encoding,
19
- your test result may differ.
17
+ Ruby 1.9 supports encoding information for strings.
18
+ The "expected"-file is read with the encoding of your result.
20
19
 
21
- You can set the default encoding for reading files with
22
- Encoding.default_external
23
-
24
- Or you define a read option for the test:
20
+ You may overwrite this with:
25
21
  class MyTest < Test::Unit::TestCase
26
22
  def test_utf()
27
- self.readoption = 'r:utf-8'
23
+ self.read_encoding = 'utf-8'
28
24
  assert_equal_filecontent( "expected/test_utf.txt", mycall() )
29
25
  end
30
26
  end
31
-
27
+ .
32
28
  =end
33
29
  require 'test/unit'
34
30
  #~ puts RUBY_VERSION
@@ -37,22 +33,33 @@ require 'fileutils'
37
33
  require 'date' #needed for Ruby 1.9 (class Date no standard?)
38
34
 
39
35
  =begin rdoc
40
- Extend the class TestCase with additional methods/assertions
36
+ Extend the class TestCase with additional methods/assertions:
37
+
38
+ * Test::Unit::TestCase#assert_equal_filecontent
41
39
  =end
42
40
  class Test::Unit::TestCase
43
- #define option to read "expected"-file. may define conversions.
44
- attr_writer :readoption
41
+ #Default path in case of an error.
42
+ FOLDER_FOR_FAILURE = "failure_#{Date.today}"
43
+ #Default path in case of an error. Overwrites FOLDER_FOR_FAILURE.
44
+ #With 'false' no file is written
45
+ attr_writer :folder_for_failure
46
+ #Overwrite encoding of 'expected' file.
47
+ #Needed for each test method.
48
+ attr_writer :read_encoding
45
49
 
46
50
  =begin rdoc
47
51
  Takes the content of the file 'filename' and compares it with 'actual' like in assert_equal.
48
- If 'filname' doesn't exist, the failure
52
+ If 'filename' doesn't exist, the failure
49
53
  Reference file <#{filename}> missing
50
54
  is returned.
51
55
 
52
56
  'folder_for_failure' will contain all results with differences.
53
57
 
54
58
  Example of the usage:
55
- assert_equal_filecontent( "expected/test_section.html", text.to_doc(:html))
59
+ assert_equal_filecontent( "expected/test_section.html",
60
+ text.to_doc(:html),
61
+ 'short description of test'
62
+ )
56
63
 
57
64
  What will happen:
58
65
  1. text.to_doc(:html) is the test. It creates some HTML-Text
@@ -61,58 +68,158 @@ What will happen:
61
68
  2. If it is the same -> fine
62
69
  3. If there are differences:
63
70
  3. A message is given (like in assert_equal)
64
- 4. A folder "failure#{Date.today}" is created if not already exist
65
- 5. The file 'test_section.html' with the result is created in "failure#{Date.today}/"
66
- 6. I can use a compare tool to compare the expected result and the real result.
67
-
68
- Recommendation to build up your test.
69
- 1. Create two folders: 'expected' and 'failure'
70
- 2. Define your assertion with a non-existing filename
71
- 3. Run the test with folder_for_failure = 'failure'
72
- 4. You will get a failure (filename is missing).
73
- 5. Copy the file in 'failure' to 'expected'
71
+ 4. A folder "failure_#{Date.today}" is created if not already exist (See FOLDER_FOR_FAILURE )
72
+ 5. The file 'test_section.html' with the result is created in FOLDER_FOR_FAILURE
73
+ 6. You can use a compare tool to compare the expected result and the real result.
74
+
75
+ If you don't want a failure file (step 4 and 5), you may suppress it with:
76
+ def text_no_failure file
77
+ self.folder_for_failure = false #inactivate error/reference file creation.
78
+ #...
79
+ end
80
+
81
+ ==filename
82
+ The filename may contains some parameters in <x>.
83
+ Details see Test::Unit::TestCase#build_filename
84
+
85
+ ==Recommendation to build up your test.
86
+ 1. Define your tests with your assertions.
87
+ 2. Run the test
88
+ 3. You will get errors 'Reference file <xx/not_available.txt> missing'
89
+ and a directory 'failure_<date>
90
+ 4. Rename the folder 'failure' to 'expected'
91
+ 5. Check, if the content of the folder is the wanted result.
74
92
  6. Rerun again, you have no failure (hopefully ;-) )
93
+
94
+ If you already have the result, you may start like this:
95
+ 1. Create a folder: 'expected'
96
+ 2. Define your assertion with non-existing filename in the 'expected'-folder.
97
+ 3. Copy the expected results to the 'expected'-folder.
98
+ 4. Run the test
99
+ 5. In case of errors:
100
+ Compare the content of the 'expected'-folder with the failure-folder.
101
+ Adapt your code or your expected result.
102
+ 6. Rerun again, until you get the expected results
75
103
  =end
76
- def assert_equal_filecontent( filename, actual, folder_for_failure = "failure#{Date.today}", message = nil )
104
+ def assert_equal_filecontent( filename, actual, message = nil )
77
105
  #
78
- @readoption = 'r' unless @readoption
106
+ filename = build_filename(filename)
107
+ #Set encoding, if actual includes encoding-info.
108
+ encoding = Encoding.default_external
109
+ encoding = actual.encoding if actual.respond_to?(:encoding)
110
+ encoding = @read_encoding if @read_encoding #encoding was overwritten
111
+
79
112
  #Make the tests
80
113
  if File.exist?(filename)
81
114
  #~ expected = File.read(filename)
82
115
  expected = nil
83
- File.open(filename, @readoption){|file| expected = file.read }
84
- full_message = build_message(message, "<?> expected (#{filename}) but was\n<?>.\n", expected, actual).to_s
116
+ File.open(filename, 'r', :encoding => encoding ){|file| expected = file.read }
117
+ #~ full_message = build_message(message, "<?> expected (#{filename}) but was\n<?>.\n", expected, actual).to_s
118
+ full_message = '' #main message build from assert_equal
85
119
  else
86
120
  full_message = "Reference file <#{filename}> missing"
87
121
  end
88
122
 
89
123
  #Write the real result to a file if a failure folder is given.
90
- if folder_for_failure and expected != actual
91
- FileUtils.makedirs(folder_for_failure) if ! File.directory?(folder_for_failure)
92
- File.open( "#{folder_for_failure}/#{File.basename(filename)}", 'w'){|f|
124
+ if @folder_for_failure != false and expected != actual
125
+ folder_for_failure = @folder_for_failure || FOLDER_FOR_FAILURE
126
+ FileUtils.makedirs(folder_for_failure) unless File.directory?(folder_for_failure)
127
+ File.open( "#{folder_for_failure}/#{File.basename(filename)}", 'w', :encoding => encoding){|f|
93
128
  f << actual
94
129
  }
95
130
  full_message << "\n\t-> Build <#{folder_for_failure}/#{File.basename(filename)}>"
96
131
  end
97
132
 
133
+ #Will not work with Ruby 1.9.1/1.9.2.
134
+ # -> assert( false, full_message )
98
135
  if File.exist?(filename)
136
+ #Use the standard assertion to get the layouted message.
137
+ assert_equal( expected, actual, "Result differs to file content #{filename}" + full_message )
99
138
  #~ assert_block( full_message ){ expected == actual }
100
- case RUBY_VERSION
101
- when /^1\.8/
102
- assert_block( full_message ){ expected == actual }
103
- when /^1.9/
104
- #ruby 1.9: Add "\nExpected block to return true value." to message with assert_block
105
- assert( expected == actual, full_message )
106
- end
107
139
  else
108
- case RUBY_VERSION
109
- when /^1\.8/
110
- assert_block( full_message ){ false }
111
- when /^1.9/
112
- #ruby 1.9: Add "\nExpected block to return true value." to message with assert_block
113
- assert( false, full_message )
114
- end
140
+ assert_block( full_message ){ false }
141
+ #~ assert_equal( expected, actual, full_message )
115
142
  end
116
143
  end
144
+ =begin rdoc
145
+ Make filename conversion.
146
+
147
+ The filename may contains some parameters in <x>. _x_ may be:
148
+ * c - test class name
149
+ * m - methodname from caller[level]
150
+ * cm - test class name - methodname
151
+
152
+ Parameter 'level' is needed to get the method.
153
+
154
+ Example:
155
+
156
+ class MyTest < Test::Unit::TestCase
157
+ def test_xx
158
+ assert_equal_filecontent( "<m>.txt", mycode )
159
+ end
160
+ end
161
+
162
+ The caller stack will be
163
+ ___lib/more_unit_test/assert_equal_filecontent.rb:112:in `assert_equal_filecontent'
164
+ quicktest.rb:13:in `test_xx'
165
+ ___test-unit-2.4.0/lib/test/unit/testcase.rb:531:in `run_test'
166
+
167
+ The result with default level 1 is 'test_xx' - the method from your test.
168
+
169
+ =end
170
+ def build_filename(filename, level = 1)
171
+ method = caller[level].match(/^(.+?):(\d+)(?::in `(.*)')?/)[3] #methodname
172
+ filename.gsub(/<.*?>/){ |hit|
173
+ case hit
174
+ when '<c>'; self.class.name
175
+ when '<m>'; method
176
+ when '<cm>'; "#{self.class}-#{method}" #methodname
177
+ else; raise ArgumentError, "Undefined option #{hit} in filename #{filename}"
178
+ end
179
+ }.sub(/block (\(\d+ levels\) )?in /,'')
180
+
181
+ end
117
182
  #
118
183
  end
184
+
185
+ __END__
186
+
187
+ Ziel:
188
+ Angabe der expected-Datei vereinfachen.
189
+ Generieren aus classe/methode des Aufrufers.
190
+
191
+ "#{self.class}-#{caller.first.match(/^(.+?):(\d+)(?::in `(.*)')?/)[3]}
192
+
193
+ Ben�tigt:
194
+ * extension
195
+ * variation (bei mehreren tests in methode
196
+ * Zus�tzliche Verzeichnisname (gesetzt in class?)
197
+
198
+ Idee:
199
+ Lsg per symbol/fixnum als filename
200
+ Dann filename = "#{self.class}-#{caller.first.match(/^(.+?):(\d+)(?::in `(.*)')?/)[3]}_#{filename}"
201
+ Aber: extension?
202
+
203
+ class Test_x << Test::Unit::TestCase
204
+ def test_xx
205
+ assert_equal_filecontent( :var1, actual ) #-> Test_x-test_xx-var1
206
+ assert_equal_filecontent( 1, actual ) #-> Test_x-test_xx-1
207
+ end
208
+ end
209
+
210
+ Idee 2:
211
+ analog strftime.
212
+ Nur ein parameter ben�tigt.
213
+
214
+ * <c> - class
215
+ * <m> - method
216
+ * <cm> - class-method
217
+ * <p> - predefined path
218
+ * M�glichkeiten: * <>
219
+ class Test_x << Test::Unit::TestCase
220
+ def test_xx
221
+ assert_equal_filecontent( 'expected/$$_var1', actual ) #-> Test_x-test_xx-var1
222
+ assert_equal_filecontent( 'expected/$$_1', actual ) #-> Test_x-test_xx-1
223
+ end
224
+ end
225
+
@@ -1,44 +1,51 @@
1
- #
2
- #Add some funcionality to check stdout and stderr-output with test/unit.
3
- #
4
- #Example:
5
- # require 'assert_stdout'
6
- # class MyTest < Test::Unit::TestCase
7
- # #This is a method and I wnat to test the screen output.
8
- # def any_output()
9
- # puts "Just some output"
10
- # end
11
- # def test_stdout_ok()
12
- # assert_stdout("Just some output\n", proc{ any_output()} )
13
- # assert_stdout_block("Just some output\n"){ any_output() }
14
- # end
15
- # end
16
- #
17
- #Please be aware:
18
- #Normally you should not test the output of methods, but the result of methods.
19
- #
20
- require 'test/unit'
21
- module Test::Unit
1
+ =begin rdoc
2
+ Add some functionality to check stdout and stderr-output with test/unit.
22
3
 
23
- #Class to catch the std output and stderr
24
- class Catch_IO < String
25
- #Receive content
26
- def write( cont )
27
- self << cont
4
+ Example:
5
+ require 'assert_stdout'
6
+ class MyTest < Test::Unit::TestCase
7
+ #This is a method and I wnat to test the screen output.
8
+ def any_output()
9
+ puts "Just some output"
10
+ end
11
+ def test_stdout_ok()
12
+ assert_stdout("Just some output\n", proc{ any_output()} )
13
+ assert_stdout_block("Just some output\n"){ any_output() }
14
+ end
28
15
  end
29
- end #MyIO
30
16
 
31
- #
32
- #Extend the class TestCase with additional methods/assertions
33
- #
34
- class TestCase
35
- #Catch stdout for a given procedure (Proc-Element).
36
- def catch_stdout( procedure )
37
- $stdout = output = Catch_IO.new #temporary copy
38
- procedure.call
39
- $stdout = STDOUT
40
- output
41
- end
17
+ Please be aware:
18
+ Normally you should not test the output of methods, but the result of methods.
19
+ =end
20
+ require 'test/unit'
21
+ module Test
22
+ module Unit
23
+ #Class to catch the std output and stderr
24
+ class Catch_IO < String
25
+ #Receive content
26
+ def write( cont )
27
+ self << cont
28
+ end
29
+ end #MyIO
30
+
31
+ =begin rdoc
32
+ Extend the class TestCase with additional methods/assertions
33
+
34
+ Details see
35
+ * Test::Unit::TestCase#assert_stdout
36
+ * Test::Unit::TestCase#assert_stdout_block
37
+ * Test::Unit::TestCase#assert_stderr
38
+ * Test::Unit::TestCase#assert_stderr_block
39
+
40
+ =end
41
+ class TestCase
42
+ #Catch stdout for a given procedure (Proc-Element).
43
+ def catch_stdout( procedure )
44
+ $stdout = output = Catch_IO.new #temporary copy
45
+ procedure.call
46
+ $stdout = STDOUT
47
+ output
48
+ end
42
49
  =begin rdoc
43
50
  Compare the stdout-output with your exception.
44
51
 
@@ -53,17 +60,17 @@ class TestCase
53
60
  end
54
61
  end
55
62
  =end
56
- def assert_stdout( expected, actual, message = nil )
57
- if actual.respond_to?(:call)
58
- output = catch_stdout( actual )
59
- full_message = build_message(message, "<?> expected in stdout, but was\n<?>.\n", expected, output)
60
- assert_block( full_message ){ expected == output }
61
- else
62
- raise 'no Proc-object given'
63
- full_message = build_message(message, "<?> expected in stdout, but no Proc-object is given to test.\n", expected )
64
- assert_block( full_message ){ false } #force error
65
- end
66
- end
63
+ def assert_stdout( expected, actual, message = nil )
64
+ if actual.respond_to?(:call)
65
+ output = catch_stdout( actual )
66
+ full_message = build_message(message, "<?> expected in stdout, but was\n<?>.\n", expected, output)
67
+ assert_block( full_message ){ expected == output }
68
+ else
69
+ raise 'no Proc-object given'
70
+ full_message = build_message(message, "<?> expected in stdout, but no Proc-object is given to test.\n", expected )
71
+ assert_block( full_message ){ false } #force error
72
+ end
73
+ end
67
74
  =begin rdoc
68
75
  Compare the stdout-output of a given block with your exception.
69
76
 
@@ -75,32 +82,32 @@ Example:
75
82
  end
76
83
  end
77
84
  =end
78
- def assert_stdout_block( expected, message = nil )
79
- previous_stdout = $stdout
80
- previous_STDOUT = STDOUT
81
- if block_given?
82
- $stdout = output = Catch_IO.new #temporary copy
83
- #~ STDOUT.reopen($stdout)
84
- yield
85
- $stdout = previous_stdout
86
- #~ STDOUT.reopen(previous_STDOUT)
87
- full_message = build_message(message, "<?> expected in stdout, but was\n<?>.\n", expected, output)
88
- assert_block( full_message ){ expected == output }
89
- else
90
- raise 'no block given'
91
- full_message = build_message(message, "<?> expected in stdout, but no block to test.\n", expected )
92
- assert_block( full_message ){ false }
93
- end
94
- end
85
+ def assert_stdout_block( expected, message = nil )
86
+ previous_stdout = $stdout
87
+ previous_STDOUT = STDOUT
88
+ if block_given?
89
+ $stdout = output = Catch_IO.new #temporary copy
90
+ #~ STDOUT.reopen($stdout)
91
+ yield
92
+ $stdout = previous_stdout
93
+ #~ STDOUT.reopen(previous_STDOUT)
94
+ full_message = build_message(message, "<?> expected in stdout, but was\n<?>.\n", expected, output)
95
+ assert_block( full_message ){ expected == output }
96
+ else
97
+ raise 'no block given'
98
+ full_message = build_message(message, "<?> expected in stdout, but no block to test.\n", expected )
99
+ assert_block( full_message ){ false }
100
+ end
101
+ end
95
102
  =begin rdoc
96
103
  Catch stderr for a given procedure (Proc-Element).
97
104
  =end
98
- def catch_stderr( procedure )
99
- $stderr = output = Catch_IO.new #temporary copy
100
- procedure.call
101
- $stderr = STDERR
102
- output
103
- end
105
+ def catch_stderr( procedure )
106
+ $stderr = output = Catch_IO.new #temporary copy
107
+ procedure.call
108
+ $stderr = STDERR
109
+ output
110
+ end
104
111
  =begin rdoc
105
112
  Compare the stderr-output with your exception.
106
113
 
@@ -119,17 +126,17 @@ Example:
119
126
  end
120
127
  end
121
128
  =end
122
- def assert_stderr( expected, actual, message = nil )
123
- if actual.respond_to?(:call)
124
- output = catch_stderr( actual )
125
- full_message = build_message(message, "<?> expected in stderr, but was\n<?>.\n", expected, output)
126
- assert_block( full_message ){ expected == output }
127
- else
128
- raise 'no Proc-object given'
129
- full_message = build_message(message, "<?> expected in stderr, but no Proc-object is given to test.\n", expected )
130
- assert_block( full_message ){ false } #force error
131
- end
132
- end
129
+ def assert_stderr( expected, actual, message = nil )
130
+ if actual.respond_to?(:call)
131
+ output = catch_stderr( actual )
132
+ full_message = build_message(message, "<?> expected in stderr, but was\n<?>.\n", expected, output)
133
+ assert_block( full_message ){ expected == output }
134
+ else
135
+ raise 'no Proc-object given'
136
+ full_message = build_message(message, "<?> expected in stderr, but no Proc-object is given to test.\n", expected )
137
+ assert_block( full_message ){ false } #force error
138
+ end
139
+ end
133
140
  =begin rdoc
134
141
  Compare the stderr-output with your exception.
135
142
 
@@ -145,20 +152,21 @@ Example:
145
152
  end
146
153
  end
147
154
  =end
148
- def assert_stderr_block( expected, message = nil )
149
- if block_given?
150
- $stderr = output = Catch_IO.new #temporary copy
151
- yield
152
- $stderr = STDERR
153
- full_message = build_message(message, "<?> expected in stderr, but was\n<?>.\n", expected, output)
154
- assert_block( full_message ){ expected == output }
155
- else
156
- raise 'no block given'
157
- full_message = build_message(message, "<?> expected in stderr, but no block to test.\n", expected )
158
- assert_block( full_message ){ false }
159
- end
160
- end
161
- end #class TestCase
155
+ def assert_stderr_block( expected, message = nil )
156
+ if block_given?
157
+ $stderr = output = Catch_IO.new #temporary copy
158
+ yield
159
+ $stderr = STDERR
160
+ full_message = build_message(message, "<?> expected in stderr, but was\n<?>.\n", expected, output)
161
+ assert_block( full_message ){ expected == output }
162
+ else
163
+ raise 'no block given'
164
+ full_message = build_message(message, "<?> expected in stderr, but no block to test.\n", expected )
165
+ assert_block( full_message ){ false }
166
+ end
167
+ end
168
+ end #class TestCase
169
+ end #module Unit
162
170
  end #module Test::Unit
163
171
 
164
172
  __END__
data/readme ADDED
@@ -0,0 +1,53 @@
1
+ =Extend test/unit
2
+ The more_unit_test-package extends test/unit with some additional tests
3
+ to handle stdout/stderr and big strings.
4
+
5
+ ==more_unit_test/assert_equal_filecontent.rb
6
+
7
+ Compare expected result with file content
8
+
9
+ Usefull, if you compare long strings in your tests.
10
+
11
+ Details see Test::Unit::TestCase#assert_equal_filecontent
12
+
13
+ ==more_unit_test/assert_stdout.rb
14
+ Test for stdout/stderr.
15
+
16
+ Details see
17
+ * Test::Unit::TestCase#assert_stdout
18
+ * Test::Unit::TestCase#assert_stdout_block
19
+ * Test::Unit::TestCase#assert_stderr
20
+ * Test::Unit::TestCase#assert_stderr_block
21
+
22
+
23
+
24
+ =Version history:
25
+ 0.0.1:
26
+ * Initial version.
27
+
28
+ 0.0.2:
29
+ * modified folder structure
30
+ * more documentation.
31
+ * published at gemcutter
32
+
33
+ 0.1.0 2010-02-07
34
+ * Restructured lib-directory
35
+ * Restructured the tests
36
+ * removed catch_output (is available in knut_tools.gem)
37
+
38
+ 0.1.1 2010-05-03
39
+ * first steps to Ruby 1.9
40
+
41
+ 0.1.2 2011-02-17
42
+ * Add Test::Unit::TestCase#readoption= for read options of expected-file
43
+
44
+ 0.1.3
45
+ * Correction ruby 1.9-specialities (was there a problem with 1.9.1?)
46
+
47
+ 0.2.0 2015-02-02
48
+ * Remove _parameter folder_for_failure_ from Test::Unit::TestCase#assert_equal_filecontent
49
+ * Advantage: interface is same as _assert_equal_
50
+ * folder_for_failure can be set with Test::Unit::TestCase#folder_for_failure=
51
+ * Use encoding of test-result to write to failure-file.
52
+ * Test::Unit::TestCase#assert_equal_filecontent: use assert_equal to layout failure message
53
+ * Enable Test::Unit::TestCase#assert_equal_filecontent to define dynamic filenames, based on test method name.
@@ -1,13 +1,8 @@
1
1
  #~ #encoding: utf-8
2
2
  gem 'test-unit', '>= 2.1.1' #defines omit, pend...
3
3
  require 'test/unit'
4
- if $0 == __FILE__
5
- if RUBY_VERSION == '1.9.1'
6
- $:.unshift("../lib")
7
- else
8
- $: << "../lib"
9
- end
10
- end
4
+
5
+ $:.unshift("../lib") if $0 == __FILE__
11
6
  require "more_unit_test/assert_equal_filecontent.rb"
12
7
 
13
8
  #Some content to be tested.
@@ -36,7 +31,33 @@ $folder_for_failure = File.dirname(__FILE__) + '/tmp_failure'
36
31
  #~ require 'test/testunit/test_assertions'
37
32
 
38
33
  #
39
- class MyTest < Test::Unit::TestCase
34
+ class Test_equal_filecontent_filename < Test::Unit::TestCase
35
+ def test_normal
36
+ assert_equal('x', build_filename('x'))
37
+ end
38
+ def test_c
39
+ assert_equal(self.class.to_s, build_filename('<c>'))
40
+ end
41
+ def test_m
42
+ assert_equal(__method__.to_s, build_filename('<m>',0))
43
+ end
44
+ def test_cm
45
+ assert_equal("#{self.class}-#{__method__}", build_filename('<cm>',0))
46
+ end
47
+
48
+ def test_m_cascaded
49
+ assert_nothing_raised{
50
+ assert_equal(__method__.to_s, build_filename('<m>',0))
51
+ }
52
+ assert_nothing_raised{
53
+ assert_nothing_raised{
54
+ assert_equal(__method__.to_s, build_filename('<m>',0))
55
+ }
56
+ }
57
+ end
58
+ end #Test_equal_filecontent_filename
59
+
60
+ class Test_equal_filecontent < Test::Unit::TestCase
40
61
 
41
62
  #Machte Probleme ohne gem laden
42
63
  #~ case RUBY_VERSION
@@ -49,61 +70,132 @@ class MyTest < Test::Unit::TestCase
49
70
  #~ AssertionFailedError = Test::Unit::AssertionFailedError
50
71
  #~ end
51
72
  AssertionFailedError = Test::Unit::AssertionFailedError
52
-
53
- def test_ok()
54
- #Build reference data
55
- self.readoption = 'r:cp1252' unless RUBY_VERSION <= '1.8'
73
+
74
+ #Build reference data
75
+ def self.startup()
56
76
  FileUtils.makedirs($expected)
57
77
  File.open("#{$expected}/test.txt", 'w'){|f| f << DUMMYTEXT }
78
+ File.open("#{$expected}/test_utf.txt", 'w:utf-8'){|f| f << DUMMYTEXT_utf }
79
+ File.open("#{$expected}/test_build.txt", 'w'){|f| f << DUMMYTEXT*2 }
80
+ end
81
+ def self.shutdown()
82
+ #~ File.delete("#{$expected}/test.txt")
83
+ #~ File.delete("#{$expected}/test_utf.txt")
84
+ #~ File.delete("#{$expected}/test_build.txt")
85
+ #~ Dir.delete("#{$expected}")
86
+
87
+ FileUtils.rmtree($expected)
88
+ FileUtils.rmtree($folder_for_failure)
89
+ FileUtils.rmtree(FOLDER_FOR_FAILURE)
90
+ end
91
+
92
+ def test_ok()
93
+ #Build reference data
94
+ self.read_encoding = 'cp1252' unless RUBY_VERSION <= '1.8'
58
95
  #Make test
59
96
  assert_equal_filecontent( "#{$expected}/test.txt", DUMMYTEXT )
60
97
  end
61
98
 
62
99
  def test_utf()
63
100
  omit_if(RUBY_VERSION <= '1.8', "No encoding check for ruby #{RUBY_VERSION}")
64
- #Build reference data
65
- FileUtils.makedirs($expected)
66
- File.open("#{$expected}/test_utf.txt", 'w:utf-8'){|f| f << DUMMYTEXT_utf }
67
101
  #Make test
68
- self.readoption = 'r:utf-8'
102
+ self.read_encoding = 'utf-8' #default, not necessary
69
103
  assert_equal_filecontent( "#{$expected}/test_utf.txt", DUMMYTEXT_utf )
70
104
  end
71
105
 
72
106
  #Check error
73
107
  def test_no_reference_file()
74
108
 
109
+ self.folder_for_failure = false #inactivate error/reference file creation.
75
110
  #Check exception and get the message
76
111
  msg = assert_raise( AssertionFailedError ){
77
- assert_equal_filecontent( "#{$expected}/not_available.txt", DUMMYTEXT, nil )
112
+ assert_equal_filecontent( "#{$expected}/not_available.txt", DUMMYTEXT )
78
113
  }
79
- #fixme 1.9 assert_block ändert wert
80
- case RUBY_VERSION
81
- when /1.9/
82
- pend("Check for Ruby-Version #{RUBY_VERSION }")
83
- assert_equal( "Reference file <#{$expected}/not_available.txt> missing.\nExpected block to return true value.", msg.to_s)
84
- when /1.8/
85
- assert_equal( "Reference file <#{$expected}/not_available.txt> missing", msg.to_s)
86
- else
87
- notify("Ruby-Version #{RUBY_VERSION } undefined")
88
- end
114
+ assert_instance_of(Test::Unit::AssertionFailedError, msg)
115
+ assert_equal( "Reference file <#{$expected}/not_available.txt> missing", msg.to_s)
89
116
  end
90
117
  #Check, if "Failure" is created.
91
- def test_build_reference_file()
92
- #Initial expected file
93
- FileUtils.makedirs($expected)
94
- File.open("#{$expected}/test_build.txt", 'w'){|f| f << DUMMYTEXT*2 }
95
- #
118
+ def test_build_reference_file_default_path()
119
+
120
+ #First check. There is a difference, in failure we get the correct result
121
+ msg = assert_raise( AssertionFailedError ){
122
+ assert_equal_filecontent( "#{$expected}/test_build.txt", DUMMYTEXT )
123
+ }
124
+ assert_match( %r{Result differs to file content #{$expected}/test_build.txt\n\t-> Build <#{FOLDER_FOR_FAILURE}/test_build.txt}m,
125
+ msg.to_s )
126
+
127
+ #Check for file with correkt result
128
+ assert_true(File.exist?("#{FOLDER_FOR_FAILURE}/test_build.txt" ))
129
+ #Check with new file (normally you would copy the file to $expected
130
+ assert_equal_filecontent( "#{FOLDER_FOR_FAILURE}/test_build.txt", DUMMYTEXT, nil )
131
+ end
132
+
133
+ #Check, if "Failure" is created.
134
+ def test_build_reference_file_with_path()
96
135
 
136
+ self.folder_for_failure = $folder_for_failure #set other failure folder for assertion in this test
97
137
  #First check. There is a difference, in failure we get the correct result
98
138
  msg = assert_raise( AssertionFailedError ){
99
- assert_equal_filecontent( "#{$expected}/test_build.txt", DUMMYTEXT, $folder_for_failure )
139
+ assert_equal_filecontent( "#{$expected}/test_build.txt", DUMMYTEXT )
100
140
  }
101
- assert_match( %r{.*expected \(#{$expected}/test_build.txt\) but was.*-> Build <#{$folder_for_failure}/test_build.txt}m,
141
+ assert_match( %r{Result differs to file content #{$expected}/test_build.txt\n\t-> Build <#{$folder_for_failure}/test_build.txt}m,
102
142
  msg.to_s )
103
143
 
104
144
  #Check for file with correkt result
105
- assert_equal(true, File.exist?("#{$folder_for_failure}/test_build.txt" ))
145
+ assert_true(File.exist?("#{$folder_for_failure}/test_build.txt" ))
106
146
  #Check with new file (normally you would copy the file to $expected
107
147
  assert_equal_filecontent( "#{$folder_for_failure}/test_build.txt", DUMMYTEXT, nil )
108
148
  end
109
- end #class MyTest
149
+ def test_build_reference_file_parameter_error()
150
+ #First check. There is a difference, in failure we get the correct result
151
+ msg = assert_raise( ArgumentError ){
152
+ assert_equal_filecontent( "<??>.txt", DUMMYTEXT )
153
+ }
154
+ end
155
+ def test_build_reference_file_parameter_c()
156
+ filename = self.class.name
157
+ #First check. There is a difference, in failure we get the correct result
158
+ msg = assert_raise( AssertionFailedError ){
159
+ assert_equal_filecontent( "#{$expected}/<c>.txt", DUMMYTEXT )
160
+ }
161
+ assert_match( %r{Reference file <#{$expected}/#{filename}.txt> missing.*-> Build <#{FOLDER_FOR_FAILURE}/#{filename}.txt}m,
162
+ msg.to_s )
163
+
164
+ #Check for file with correkt result
165
+ assert_true(File.exist?("#{FOLDER_FOR_FAILURE}/#{filename}.txt" ))
166
+ #Check with new file (normally you would copy the file to $expected
167
+ assert_equal_filecontent( "#{FOLDER_FOR_FAILURE}/#{filename}.txt", DUMMYTEXT, nil )
168
+ end
169
+ def test_build_reference_file_parameter_m()
170
+ #~ pend "filename <m>"
171
+ filename = __method__
172
+ #First check. There is a difference, in failure we get the correct result
173
+ msg = assert_raise( AssertionFailedError ){
174
+ assert_equal_filecontent( "#{$expected}/<m>.txt", DUMMYTEXT )
175
+ }
176
+ assert_match( %r{Reference file <#{$expected}/#{filename}.txt> missing.*-> Build <#{FOLDER_FOR_FAILURE}/#{filename}.txt}m,
177
+ msg.to_s )
178
+
179
+
180
+ #Check for file with correkt result
181
+ assert_true(File.exist?("#{FOLDER_FOR_FAILURE}/#{filename}.txt" ))
182
+ #Check with new file (normally you would copy the file to $expected
183
+ assert_equal_filecontent( "#{FOLDER_FOR_FAILURE}/#{filename}.txt", DUMMYTEXT, nil )
184
+ end
185
+ #~ def test_build_reference_file_parameter_cm()
186
+ #~ pend "filename <cm>"
187
+ #~ filename = "#{self.class.name}-#{__method__}"
188
+ #~ #First check. There is a difference, in failure we get the correct result
189
+ #~ msg = assert_raise( AssertionFailedError ){
190
+ #~ assert_equal_filecontent( "#{$expected}/<cm>.txt", DUMMYTEXT )
191
+ #~ }
192
+ #~ assert_match( %r{Reference file <#{$expected}/#{filename}.txt> missing.*-> Build <#{FOLDER_FOR_FAILURE}/#{filename}.txt}m,
193
+ #~ msg.to_s )
194
+
195
+ #~ #Check for file with correkt result
196
+ #~ assert_true(File.exist?("#{FOLDER_FOR_FAILURE}/#{filename}.txt" ))
197
+ #~ #Check with new file (normally you would copy the file to $expected
198
+ #~ assert_equal_filecontent( "#{FOLDER_FOR_FAILURE}/#{filename}.txt", DUMMYTEXT, nil )
199
+ #~ end
200
+
201
+ end #Test_equal_filecontent
@@ -63,9 +63,9 @@ class Log4rTest < Test::Unit::TestCase
63
63
  def test_alternative()
64
64
  log = Log4r::Logger.new('testlog')
65
65
  begin
66
- io = Tempfile.new(self.object_id)
66
+ io = Tempfile.new(self.object_id.to_s)
67
67
  rescue ArgumentError
68
- omit("Tempfile error (ruby 1.9.2)")
68
+ omit("Tempfile error")
69
69
  end
70
70
  log.outputters << Log4r::IOOutputter.new('log_stdout', io)
71
71
  log.info('a')
metadata CHANGED
@@ -1,105 +1,102 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: more_unit_test
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Knut Lickert
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-02-17 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: test-unit
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
33
20
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: knut_tools
37
21
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: knut-gempackager
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
47
34
  type: :development
48
- version_requirements: *id002
49
- description: |
50
- The more_unit_test-package extends test/unit with some additional tests:
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: knut-testtask
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ description: ! 'The more_unit_test-package extends test/unit with some additional
56
+ tests:
57
+
51
58
  - assert_equal_filecontent.rb: Compare expected result with file content
59
+
52
60
  - assert_stdout.rb: test for stdout/stderr
53
61
 
62
+ '
54
63
  email: knut@lickert.net
55
64
  executables: []
56
-
57
65
  extensions: []
58
-
59
- extra_rdoc_files:
60
- - readme.rd
61
- files:
62
- - readme.rd
66
+ extra_rdoc_files:
67
+ - readme
68
+ files:
63
69
  - lib/more_unit_test.rb
64
70
  - lib/more_unit_test/assert_equal_filecontent.rb
65
71
  - lib/more_unit_test/assert_stdout.rb
66
- - unittest/test_assert_stdout.rb
72
+ - readme
67
73
  - unittest/test_assert_equal_filecontent.rb
68
- has_rdoc: true
74
+ - unittest/test_assert_stdout.rb
69
75
  homepage: http://gems.rubypla.net/more_unit_test/
70
76
  licenses: []
71
-
77
+ metadata: {}
72
78
  post_install_message:
73
- rdoc_options:
79
+ rdoc_options:
74
80
  - --main
75
- - readme.rd
76
- require_paths:
81
+ - readme
82
+ require_paths:
77
83
  - lib
78
- required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- hash: 3
84
- segments:
85
- - 0
86
- version: "0"
87
- required_rubygems_version: !ruby/object:Gem::Requirement
88
- none: false
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
- version: "0"
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
96
94
  requirements: []
97
-
98
95
  rubyforge_project: more_unit_test
99
- rubygems_version: 1.3.7
96
+ rubygems_version: 2.2.2
100
97
  signing_key:
101
- specification_version: 3
98
+ specification_version: 4
102
99
  summary: Additional assertions for big text results.
103
- test_files:
100
+ test_files:
104
101
  - unittest/test_assert_stdout.rb
105
102
  - unittest/test_assert_equal_filecontent.rb
data/readme.rd DELETED
@@ -1,32 +0,0 @@
1
- =Extend test/unit
2
- The more_unit_test-package extends test/unit with some additional tests
3
- to hande staou/stderr
4
-
5
- ==more_unit_test/assert_equal_filecontent.rb
6
-
7
- Compare expected result with file content
8
- ==more_unit_test/assert_stdout.rb
9
- Test for stdout/stderr
10
-
11
-
12
-
13
- =Version history:
14
- 0.0.1:
15
- * Initial version.
16
-
17
- 0.0.2:
18
- * modified folder structure
19
- * more documentation.
20
- * published at gemcutter
21
-
22
- 0.1.0 2010-02-07
23
- * Restructured lib-directory
24
- * Restructured the tests (using knut_tools/rake/testtask.rb)
25
- * removed catch_output (is available in knut_tools.gem)
26
-
27
- 0.1.1 2010-05-03
28
- * first steps to Ruby 1.9
29
-
30
- 0.1.2 2011-02-17
31
- * Add readoption for read options of expected-file
32
-