more_unit_test 0.0.2 → 0.1.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,13 @@
1
+ =begin rdoc
2
+ ==Extend test/unit
3
+ The more_unit_test-package extends test/unit with some additional tests
4
+ to hande staou/stderr
5
+
6
+ ===more_unit_test/assert_equal_filecontent.rb
7
+
8
+ Compare expected result with file content
9
+
10
+ ===more_unit_test/assert_stdout.rb
11
+ Test for stdout/stderr
12
+
13
+ =end
data/readme.html CHANGED
@@ -1,29 +1,28 @@
1
1
  <!--
2
2
 
3
- Build by C:/Program Files/ruby/lib/ruby/gems/1.8/gems/docgenerator-1.2.0/./lib/docgenerator/document.rb
3
+ Build by C:/Program Files/ruby/lib/ruby/gems/1.8/gems/docgenerator-1.2.0/lib/docgenerator/document.rb
4
4
  Dir: C:/usr/Script/more_unit_test
5
- Creator: rakefile.rb
5
+ Creator: rakefile_more_unit_test.rb
6
6
  Target: readme.html
7
- 2010/01/02 01:00:41
7
+ 2010/02/06 20:03:43
8
8
 
9
9
  Generation-Info-End
10
10
  -->
11
11
  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
12
12
  <html>
13
13
  <head ></head>
14
- <body ><p >
15
- The more_unit_test-package extends test/unit with some additional tests:
14
+ <body ><h1 >Extend test/unit</h1>
15
+ <p >
16
+ The more_unit_test-package extends test/unit with some additional tests to hande staou/stderr
16
17
  </p>
17
- <ul >
18
- <li > assert_equal_filecontent.rb: Compare expected result with file content </li>
19
- <li > assert_stdout.rb: test for stdout/stderr Test cases are added to the files directly. </li>
20
- </ul>
18
+ <h2 >more_unit_test/assert_equal_filecontent.rb</h2>
21
19
  <p >
22
- In addition you get a function to catch outputs on stdout and stderr:
20
+ Compare expected result with file content
21
+ </p>
22
+ <h2 >more_unit_test/assert_stdout.rb</h2>
23
+ <p >
24
+ Test for stdout/stderr
23
25
  </p>
24
- <ul >
25
- <li > catch_output.rb </li>
26
- </ul>
27
26
  <h1 >Version history:</h1>
28
27
  <p >
29
28
  0.0.1: Initial version.
@@ -36,5 +35,14 @@ In addition you get a function to catch outputs on stdout and stderr:
36
35
  <li > more documentation. </li>
37
36
  <li > published at gemcutter </li>
38
37
  </ul>
38
+ <p >
39
+ 0.1.0
40
+ </p>
41
+ <ul >
42
+ <li > Restructured lib-directory </li>
43
+ <li > Restructured the tests (using knut_tools/rake/testtask.rb) </li>
44
+ <li > removed catch_output (is available in knut_tools.gem) </li>
45
+ <li > added testtask.rb </li>
46
+ </ul>
39
47
  </body>
40
48
  </html>
data/readme.txt CHANGED
@@ -1,11 +1,19 @@
1
1
 
2
2
 
3
- The more_unit_test-package extends test/unit with some additional tests:
4
- - assert_equal_filecontent.rb: Compare expected result with file content
5
- - assert_stdout.rb: test for stdout/stderr Test cases are added to the files directly.
3
+ Extend test/unit
4
+ ------------------------------
5
+
6
+ The more_unit_test-package extends test/unit with some additional tests to hande staou/stderr
7
+
8
+ more_unit_test/assert_equal_filecontent.rb
9
+ ------------------------------
6
10
 
7
- In addition you get a function to catch outputs on stdout and stderr:
8
- - catch_output.rb
11
+ Compare expected result with file content
12
+
13
+ more_unit_test/assert_stdout.rb
14
+ ------------------------------
15
+
16
+ Test for stdout/stderr
9
17
 
10
18
  Version history:
11
19
  ------------------------------
@@ -17,3 +25,9 @@ Version history:
17
25
  - more documentation.
18
26
  - published at gemcutter
19
27
 
28
+ 0.1.0
29
+ - Restructured lib-directory
30
+ - Restructured the tests (using knut_tools/rake/testtask.rb)
31
+ - removed catch_output (is available in knut_tools.gem)
32
+ - added testtask.rb
33
+
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require "../lib/assert_equal_filecontent.rb"
2
+ require "more_unit_test/assert_equal_filecontent.rb"
3
3
 
4
4
  #Some content to be tested.
5
5
  DUMMYTEXT = <<dummytext
@@ -7,41 +7,54 @@ Some text to be tested.
7
7
  More text.
8
8
  dummytext
9
9
 
10
+ #
11
+ #This two directories will be created.
12
+ #
13
+ $expected = File.dirname(__FILE__) + '/tmp_expected'
14
+ $folder_for_failure = File.dirname(__FILE__) + '/tmp_failure'
15
+
10
16
  #
11
17
  #This is a test in the test -> we need test_assertions.rb, not only test/unit
12
18
  #test_assertions.rb is not in path of tests -> full path, please adapt for your installation.
13
- require "C:/Program Files/ruby/doc/ruby/ruby-1.8.6/test/testunit/test_assertions.rb"
19
+ #~ require "C:/Program Files/ruby/doc/ruby/ruby-1.8.6/test/testunit/test_assertions.rb"
14
20
  #~ require 'test/testunit/test_assertions'
15
21
 
16
22
  #
17
- class MyTest < Test::Unit::TC_Assertions
23
+ class MyTest < Test::Unit::TestCase
24
+ #~ class MyTest < Test::Unit::TC_Assertions #-> get check fails
18
25
  def test_ok()
19
26
  #Build reference data
20
- File.makedirs('expected')
21
- File.open('expected/test.txt', 'w'){|f| f << DUMMYTEXT }
27
+ File.makedirs($expected)
28
+ File.open("#{$expected}/test.txt", 'w'){|f| f << DUMMYTEXT }
22
29
  #Make test
23
- assert_equal_filecontent( 'expected/test.txt', DUMMYTEXT )
24
- end
30
+ assert_equal_filecontent( "#{$expected}/test.txt", DUMMYTEXT )
31
+ end
32
+ #Check error
25
33
  def test_no_reference_file()
26
- check_fails(%r{Reference file <expected/not_available.txt> missing}){
27
- assert_equal_filecontent( 'expected/not_available.txt', DUMMYTEXT, nil )
28
- }
34
+
35
+ #Check exception and get the message
36
+ msg = assert_raise( Test::Unit::AssertionFailedError ){
37
+ assert_equal_filecontent( "#{$expected}/not_available.txt", DUMMYTEXT, nil )
38
+ }
39
+ assert_equal( "Reference file <#{$expected}/not_available.txt> missing", msg.to_s)
29
40
  end
41
+ #Check, if "Failure" is created.
30
42
  def test_build_reference_file()
31
43
  #Initial expected file
32
- File.makedirs('expected')
33
- File.open('expected/test_build.txt', 'w'){|f| f << DUMMYTEXT*2 }
44
+ File.makedirs($expected)
45
+ File.open("#{$expected}/test_build.txt", 'w'){|f| f << DUMMYTEXT*2 }
34
46
  #
35
- folder_for_failure = 'failure'
36
- #~ assert_equal(false, File.exist?("#{folder_for_failure}/test.txt" ))
37
47
 
38
48
  #First check. There is a difference, in failure we get the correct result
39
- check_fails(%r{.*expected \(expected/test_build.txt\) but was.*-> Build <failure/test_build.txt}m){
40
- assert_equal_filecontent( 'expected/test_build.txt', DUMMYTEXT, folder_for_failure )
49
+ msg = assert_raise( Test::Unit::AssertionFailedError ){
50
+ assert_equal_filecontent( "#{$expected}/test_build.txt", DUMMYTEXT, $folder_for_failure )
41
51
  }
52
+ assert_match( %r{.*expected \(#{$expected}/test_build.txt\) but was.*-> Build <#{$folder_for_failure}/test_build.txt}m,
53
+ msg.to_s )
54
+
42
55
  #Check for file with correkt result
43
- assert_equal(true, File.exist?("#{folder_for_failure}/test_build.txt" ))
44
- #Check with new file (normally you would copy the file to 'expected'
45
- assert_equal_filecontent( "#{folder_for_failure}/test_build.txt", DUMMYTEXT, nil )
56
+ assert_equal(true, File.exist?("#{$folder_for_failure}/test_build.txt" ))
57
+ #Check with new file (normally you would copy the file to $expected
58
+ assert_equal_filecontent( "#{$folder_for_failure}/test_build.txt", DUMMYTEXT, nil )
46
59
  end
47
60
  end #class MyTest
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require '../lib/assert_stdout.rb'
2
+ require 'more_unit_test/assert_stdout.rb'
3
3
 
4
4
 
5
5
  class MyTest < Test::Unit::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: more_unit_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Knut Lickert
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-02 00:00:00 +01:00
12
+ date: 2010-02-07 00:00:00 +01:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: knut_tools
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
16
25
  description: |
17
26
  The more_unit_test-package extends test/unit with some additional tests:
18
27
  - assert_equal_filecontent.rb: Compare expected result with file content
@@ -28,16 +37,17 @@ extra_rdoc_files: []
28
37
  files:
29
38
  - readme.txt
30
39
  - readme.html
31
- - lib/assert_equal_filecontent.rb
32
- - lib/assert_stdout.rb
33
- - lib/catch_output.rb
40
+ - lib/more_unit_test.rb
41
+ - lib/more_unit_test/assert_equal_filecontent.rb
42
+ - lib/more_unit_test/assert_stdout.rb
34
43
  has_rdoc: true
35
44
  homepage: http://gems.rubypla.net/
36
45
  licenses: []
37
46
 
38
47
  post_install_message:
39
- rdoc_options: []
40
-
48
+ rdoc_options:
49
+ - --main
50
+ - lib/more_unit_test.rb
41
51
  require_paths:
42
52
  - lib
43
53
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -54,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
64
  version:
55
65
  requirements: []
56
66
 
57
- rubyforge_project:
67
+ rubyforge_project: more_unit_test
58
68
  rubygems_version: 1.3.5
59
69
  signing_key:
60
70
  specification_version: 3
data/lib/catch_output.rb DELETED
@@ -1,105 +0,0 @@
1
- #
2
- #Catch screen output.
3
- #Can be used to avoid messages from programms called by system
4
- #
5
- #Example:
6
- # require 'catch_output'
7
- # include Catch_output
8
- # stdout, stderr = catch_screen_output{
9
- # %x{my_shell_application}
10
- # }
11
- #
12
-
13
-
14
-
15
- #Class Tempfile for temporary redirection of stdout and stderr
16
- require "tempfile"
17
-
18
- #Catch screen output.
19
- #Can be used to avoid messages from programms called by system
20
- module Catch_output
21
- STDOUT_ORIG = STDOUT.clone()
22
- STDERR_ORIG = STDERR.clone()
23
-
24
- #Catch stdout for the given block, but print stderr.
25
- def catch_stdout( &block )
26
- #~ raise 'no block' unless block_given?
27
- raise 'no block' unless block.is_a?(Proc)
28
- stdout, stderr = catch_screen_output( true, false, &block )
29
- return stdout
30
- end #catch_stdout()
31
-
32
- #Catch stderr for the given block, but print stdout.
33
- def catch_stderr( &block )
34
- #~ raise 'no block' unless block_given?
35
- raise 'no block' unless block.is_a?(Proc)
36
- stdout, stderr = catch_screen_output( false, true, &block )
37
- return stderr
38
- end #catch_stderr()
39
-
40
- #Catch the screen output (stdout and stderr) for the given block.
41
- #You can set, which output you want to catch.
42
- #
43
- #Returnvalue is an array with the result of stdout and stderr.
44
- #If any output wasn't catched, the return value in the array is nil.
45
- def catch_screen_output(
46
- catch_stdout = true,
47
- catch_stderr = true,
48
- stdout_orig = STDOUT.clone(),
49
- stderr_orig = STDERR.clone()
50
- )
51
-
52
- raise 'no block' unless block_given?
53
-
54
- if catch_stdout
55
- #Create temporary file for stdout
56
- tmpstdout = Tempfile.new( 'stdout')
57
- #redirect stdout
58
- STDOUT.reopen( tmpstdout )
59
- end
60
- if catch_stderr
61
- #Create temporary file for stdout
62
- tmpstderr = Tempfile.new( 'stderr')
63
- #redirect stdout
64
- STDERR.reopen( tmpstderr )
65
- end
66
-
67
-
68
- yield #Execute the block
69
-
70
- if catch_stdout
71
- #stdout is coming again to the screen.
72
- tmpstdout.close()
73
- STDOUT.reopen( stdout_orig)
74
-
75
- # Get the result of stdout
76
- tmpstdout.open()
77
- stdout = tmpstdout.readlines().join
78
- tmpstdout.close()
79
- end
80
-
81
-
82
- if catch_stderr
83
- #stderr is coming again to the screen.
84
- tmpstderr.close()
85
- STDERR.reopen( stderr_orig)
86
-
87
- # Get the result of stderr
88
- tmpstderr.open()
89
- stderr = tmpstderr.readlines().join
90
- tmpstderr.close()
91
- end
92
- return [ stdout, stderr ]
93
- end
94
- end
95
-
96
-
97
- #Frame to use module Catch_output
98
- #
99
- #Example:
100
- # Frame_catch_output.catch_stdout{ puts 11 }
101
- class Frame_catch_output
102
- class << self
103
- include Catch_output
104
- end
105
- end