test_extensions 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme +56 -0
- data/lib/test_extensions/test_colorizer.rb +109 -0
- data/lib/test_extensions.rb +12 -0
- metadata +69 -0
data/Readme
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= QualitySmith Test Extensions
|
2
|
+
|
3
|
+
[<b>Home page</b>:] http://qualitysmithext.rubyforge.org/ , soon: http://test_extensions.rubyforge.org/
|
4
|
+
[<b>Project site</b>:] http://rubyforge.org/projects/qualitysmithext, soon: http://rubyforge.org/projects/test_extensions
|
5
|
+
[<b>Wiki</b>:] http://wiki.qualitysmith.com/
|
6
|
+
[<b>Author</b>:] Tyler Rick, and others
|
7
|
+
[<b>Copyright</b>:] 2007 QualitySmith, Inc.
|
8
|
+
[<b>License</b>:] {GNU General Public License}[http://www.gnu.org/copyleft/gpl.html]
|
9
|
+
|
10
|
+
== Introduction
|
11
|
+
|
12
|
+
This is a collection of methods and features for Test::Unit that are missing from the standard distribution.
|
13
|
+
|
14
|
+
== Features
|
15
|
+
|
16
|
+
=== Color!
|
17
|
+
|
18
|
+
<b>test_colorizer.rb</b> causes the overall output output generated by Test::Unit to be nice and colorized. The failure "F"s and "E"s will now be in color as well as the totals showing how many tests passed (green) and how many failed (you guessed it -- red).
|
19
|
+
|
20
|
+
<b>difference_highlighting.rb</b> causes assert_equal to be colorized when comparing strings -- _very_ helpful for tracking down subtle differences between two large strings.
|
21
|
+
|
22
|
+
=== Useful assertion methods
|
23
|
+
|
24
|
+
* assert_exception
|
25
|
+
* assert_changed
|
26
|
+
* assert_includes / assert_contains
|
27
|
+
|
28
|
+
See the documentation for each method for details. (These methods are currently part of http://qualitysmithext.rubyforge.org/)
|
29
|
+
|
30
|
+
Rails-specific:
|
31
|
+
* assert_user_error
|
32
|
+
|
33
|
+
=== For testing command-line programs
|
34
|
+
|
35
|
+
* <tt>capture_output</tt> -- captures the standard output/error from the method under test (rather than letting it print to the screen) so that you can make assertions about it.
|
36
|
+
* <tt>simulate_input</tt> -- if your application is expecting some kind of user input on stdin, this method can be used to simulate the input, so that your test is completely automated and self-contained.
|
37
|
+
|
38
|
+
== Requirements
|
39
|
+
|
40
|
+
Gems:
|
41
|
+
* colored
|
42
|
+
* facets
|
43
|
+
* qualitysmith_extensions
|
44
|
+
|
45
|
+
== Installation
|
46
|
+
|
47
|
+
sudo gem install test_extensions
|
48
|
+
|
49
|
+
Then throw this in your <tt>test_helper.rb</tt>:
|
50
|
+
|
51
|
+
require 'rubygems'
|
52
|
+
gem 'test_extensions'
|
53
|
+
require 'test_extensions'
|
54
|
+
|
55
|
+
... and you're set! All extensions will automatically be loaded.
|
56
|
+
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'colored'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'colored'
|
5
|
+
|
6
|
+
module Test::Unit
|
7
|
+
|
8
|
+
class Error
|
9
|
+
# the 'E' that is displayed as the tests are run
|
10
|
+
def single_character_display
|
11
|
+
"E".red.bold
|
12
|
+
end
|
13
|
+
|
14
|
+
# the long message that is displayed after test is run
|
15
|
+
def long_display
|
16
|
+
backtrace = filter_backtrace(@exception.backtrace).join("\n ")
|
17
|
+
[
|
18
|
+
"Error".red.bold,
|
19
|
+
":\n",
|
20
|
+
"#@test_name:".white,
|
21
|
+
"\n", "#{message}".red,
|
22
|
+
"\n #{backtrace}".gsub(/:(\d+):/,":#{'\1'.red}:")
|
23
|
+
].join('')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
class Failure
|
29
|
+
# the 'E' that is displayed as the tests are run
|
30
|
+
def single_character_display
|
31
|
+
"F".yellow.bold
|
32
|
+
end
|
33
|
+
|
34
|
+
# the long message that is displayed after test is run
|
35
|
+
def long_display
|
36
|
+
location_display = if(location.size == 1)
|
37
|
+
location[0].sub(/\A(.+:\d+).*/, ' [\\1]')
|
38
|
+
else
|
39
|
+
"\n [#{location.join("\n ")}]"
|
40
|
+
end
|
41
|
+
[
|
42
|
+
"Failure".yellow.bold,
|
43
|
+
":\n","#@test_name".white,
|
44
|
+
"#{location_display}".gsub(/:(\d+)/, ":#{'\1'.yellow}"),
|
45
|
+
":\n", "#@message".yellow
|
46
|
+
].join('')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# it is necessary to do a class_eval for the TestRunner class
|
51
|
+
# through the AutoRunner class, since the require in the AutoRunner
|
52
|
+
# class will overwrite what we do here otherwise.
|
53
|
+
#
|
54
|
+
# We must do the same thing inside of the TestRunner class
|
55
|
+
# class_eval for the TestResult class. We Modify the
|
56
|
+
# TestRunnerMediator class after the require is called,
|
57
|
+
# which will then modify the TestResult class.
|
58
|
+
#
|
59
|
+
# test_finished is the function that will output the
|
60
|
+
# '.' period during the test runs
|
61
|
+
#
|
62
|
+
# the to_s for TestResult class returns the string
|
63
|
+
# for the final tallied results
|
64
|
+
class AutoRunner
|
65
|
+
RUNNERS[:console] = proc do |r|
|
66
|
+
require 'test/unit/ui/console/testrunner'
|
67
|
+
Test::Unit::UI::Console::TestRunner.class_eval %q{
|
68
|
+
def test_finished(name)
|
69
|
+
output_single('.'.green, 1) unless (@already_outputted)
|
70
|
+
nl(3)
|
71
|
+
@already_outputted = false
|
72
|
+
end
|
73
|
+
|
74
|
+
def create_mediator(suite)
|
75
|
+
require 'test/unit/ui/testrunnermediator'
|
76
|
+
Test::Unit::UI::TestRunnerMediator.class_eval %q{
|
77
|
+
def create_result
|
78
|
+
Test::Unit::TestResult.class_eval %q{
|
79
|
+
def to_s
|
80
|
+
rc = [
|
81
|
+
"#{run_count}".white.bold,
|
82
|
+
"tests".white
|
83
|
+
].join(' ')
|
84
|
+
ac = [
|
85
|
+
"#{assertion_count}".white.bold,
|
86
|
+
"assertions".white
|
87
|
+
].join(' ')
|
88
|
+
fc = [
|
89
|
+
"#{failure_count}".yellow.bold,
|
90
|
+
"failures".yellow
|
91
|
+
].join(' ')
|
92
|
+
ec = [
|
93
|
+
"#{error_count}".red.bold,
|
94
|
+
"errors".red
|
95
|
+
].join(' ')
|
96
|
+
[rc, ac, fc, ec].join(', ')
|
97
|
+
end
|
98
|
+
}
|
99
|
+
TestResult.new
|
100
|
+
end
|
101
|
+
}
|
102
|
+
return Test::Unit::UI::TestRunnerMediator.new(suite)
|
103
|
+
end
|
104
|
+
}
|
105
|
+
Test::Unit::UI::Console::TestRunner
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
gem 'facets'
|
5
|
+
require 'facets/core/kernel/require_local'
|
6
|
+
require_local 'test_extensions/test_colorizer'
|
7
|
+
|
8
|
+
gem 'qualitysmith_extensions'
|
9
|
+
require 'qualitysmith_extensions/kernel/capture_output.rb'
|
10
|
+
require 'qualitysmith_extensions/kernel/simulate_input.rb'
|
11
|
+
|
12
|
+
require 'qualitysmith_extensions/test/all'
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: test_extensions
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-04-30 00:00:00 -07:00
|
8
|
+
summary: ...
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email:
|
12
|
+
homepage: http://test_extensions.rubyforge.org
|
13
|
+
rubyforge_project: test_extensions
|
14
|
+
description: ...
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- ...
|
31
|
+
files:
|
32
|
+
- lib/test_extensions.rb
|
33
|
+
- lib/test_extensions/test_colorizer.rb
|
34
|
+
- Readme
|
35
|
+
test_files: []
|
36
|
+
|
37
|
+
rdoc_options:
|
38
|
+
- --title
|
39
|
+
- test_extensions
|
40
|
+
- --main
|
41
|
+
- Readme
|
42
|
+
- --line-numbers
|
43
|
+
extra_rdoc_files:
|
44
|
+
- Readme
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
dependencies:
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: facets
|
54
|
+
version_requirement:
|
55
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.0.0
|
60
|
+
version:
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: qualitysmith_extensions
|
63
|
+
version_requirement:
|
64
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.0
|
69
|
+
version:
|