cutest 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README.markdown +95 -0
- data/Rakefile +7 -0
- data/cutest.gemspec +11 -0
- data/lib/cutest.rb +69 -0
- data/test/a_test.rb +15 -0
- data/test/b_test.rb +3 -0
- data/test/c_test.rb +7 -0
- metadata +88 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010 Damian Janowski & Michel Martens
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
Cutest
|
2
|
+
=======
|
3
|
+
|
4
|
+
Forking tests.
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Run tests in separate processes to avoid shared state.
|
10
|
+
|
11
|
+
Each test file is loaded in a forked process and inside an anonymous
|
12
|
+
module. Once a failure is found in a file, the rest of the file is
|
13
|
+
skipped and the error is reported. This way, running your test suite
|
14
|
+
feels faster.
|
15
|
+
|
16
|
+
There are no nested contexts, just the `setup` and `test` methods.
|
17
|
+
Unlike other testing tools, the result of evaluating the setup is
|
18
|
+
passed as a parameter to each test. Even if you can still use instance
|
19
|
+
variables, the code in the examples is the suggested way to keep tests
|
20
|
+
from sharing information.
|
21
|
+
|
22
|
+
Usage
|
23
|
+
-----
|
24
|
+
|
25
|
+
In your Rakefile:
|
26
|
+
|
27
|
+
require "cutest"
|
28
|
+
|
29
|
+
task :test do
|
30
|
+
Cutest.run(Dir["test/*"])
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => :test
|
34
|
+
|
35
|
+
In your tests:
|
36
|
+
|
37
|
+
setup do
|
38
|
+
{:a => 23, :b => 43}
|
39
|
+
end
|
40
|
+
|
41
|
+
test "should receive the result of the setup block as a parameter" do |params|
|
42
|
+
assert params == {:a => 23, :b => 43}
|
43
|
+
end
|
44
|
+
|
45
|
+
test "should evaluate the setup block before each test" do |params|
|
46
|
+
params[:a] = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
test "should preserve the original values from the setup" do |params|
|
50
|
+
assert 23 == params[:a]
|
51
|
+
end
|
52
|
+
|
53
|
+
To run the tests:
|
54
|
+
|
55
|
+
$ rake
|
56
|
+
|
57
|
+
If you get an error, the report will look like this:
|
58
|
+
|
59
|
+
=> assert 24 == params[:a]
|
60
|
+
test/a_test.rb:14
|
61
|
+
|
62
|
+
Instead of a description of the error, you get to see the assertion
|
63
|
+
that failed along with the file and line number. Adding a debugger and
|
64
|
+
fixing the bug is left as an exercise for the reader.
|
65
|
+
|
66
|
+
Installation
|
67
|
+
------------
|
68
|
+
|
69
|
+
$ gem install cutest
|
70
|
+
|
71
|
+
License
|
72
|
+
-------
|
73
|
+
|
74
|
+
Copyright (c) 2009 Damian Janowski and Michel Martens
|
75
|
+
|
76
|
+
Permission is hereby granted, free of charge, to any person
|
77
|
+
obtaining a copy of this software and associated documentation
|
78
|
+
files (the "Software"), to deal in the Software without
|
79
|
+
restriction, including without limitation the rights to use,
|
80
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
81
|
+
copies of the Software, and to permit persons to whom the
|
82
|
+
Software is furnished to do so, subject to the following
|
83
|
+
conditions:
|
84
|
+
|
85
|
+
The above copyright notice and this permission notice shall be
|
86
|
+
included in all copies or substantial portions of the Software.
|
87
|
+
|
88
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
89
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
90
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
91
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
92
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
93
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
94
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
95
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/cutest.gemspec
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "cutest"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.summary = "Forking tests."
|
5
|
+
s.description = "Run tests in separate processes to avoid shared state."
|
6
|
+
s.authors = ["Damian Janowski", "Michel Martens"]
|
7
|
+
s.email = ["djanowski@dimaion.com", "michel@soveran.com"]
|
8
|
+
s.homepage = "http://github.com/djanowski/cutest"
|
9
|
+
s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/cutest.rb", "cutest.gemspec", "test/a_test.rb", "test/b_test.rb", "test/c_test.rb"]
|
10
|
+
s.add_dependency "batch", "~> 0.0.1"
|
11
|
+
end
|
data/lib/cutest.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "batch"
|
2
|
+
|
3
|
+
AssertionFailed = Class.new(StandardError)
|
4
|
+
|
5
|
+
def assert(value)
|
6
|
+
return if value
|
7
|
+
|
8
|
+
ex = AssertionFailed.new(@_test)
|
9
|
+
ex.set_backtrace(caller)
|
10
|
+
|
11
|
+
file, line = ex.backtrace.shift.split(":")
|
12
|
+
code = File.readlines(file)[line.to_i - 1]
|
13
|
+
|
14
|
+
ex.message.replace("=> #{code.strip}\n#{file}:#{line}")
|
15
|
+
|
16
|
+
raise ex
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup(&block)
|
20
|
+
@_setup = block if block_given?
|
21
|
+
@_setup
|
22
|
+
end
|
23
|
+
|
24
|
+
def test(name = nil, &block)
|
25
|
+
@_test = name
|
26
|
+
|
27
|
+
block.call(setup && setup.call)
|
28
|
+
end
|
29
|
+
|
30
|
+
class Cutest < Batch
|
31
|
+
VERSION = "0.0.1"
|
32
|
+
|
33
|
+
def report_errors
|
34
|
+
return if @errors.empty?
|
35
|
+
|
36
|
+
$stderr.puts "\nSome errors occured:\n\n"
|
37
|
+
|
38
|
+
@errors.each do |item, error|
|
39
|
+
$stderr.puts error, "\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.run(files)
|
44
|
+
each(files) do |file|
|
45
|
+
read, write = IO.pipe
|
46
|
+
|
47
|
+
fork do
|
48
|
+
read.close
|
49
|
+
|
50
|
+
begin
|
51
|
+
load(file, true)
|
52
|
+
rescue => e
|
53
|
+
error = [e.message] + e.backtrace.take_while { |line| !line.start_with?(__FILE__) }
|
54
|
+
write.write error.join("\n")
|
55
|
+
write.write "\n"
|
56
|
+
write.close
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
write.close
|
61
|
+
|
62
|
+
Process.wait
|
63
|
+
|
64
|
+
output = read.read
|
65
|
+
raise AssertionFailed.new(output) unless output.empty?
|
66
|
+
read.close
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/test/a_test.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
setup do
|
2
|
+
{:a => 23, :b => 43}
|
3
|
+
end
|
4
|
+
|
5
|
+
test "should receive the result of the setup block as a parameter" do |params|
|
6
|
+
assert params == {:a => 23, :b => 43}
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should evaluate the setup block before each test" do |params|
|
10
|
+
params[:a] = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should preserve the original values from the setup" do |params|
|
14
|
+
assert 23 == params[:a]
|
15
|
+
end
|
data/test/b_test.rb
ADDED
data/test/c_test.rb
ADDED
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cutest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Damian Janowski
|
13
|
+
- Michel Martens
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-10 00:00:00 -03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: batch
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- 1
|
33
|
+
version: 0.0.1
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Run tests in separate processes to avoid shared state.
|
37
|
+
email:
|
38
|
+
- djanowski@dimaion.com
|
39
|
+
- michel@soveran.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- LICENSE
|
48
|
+
- README.markdown
|
49
|
+
- Rakefile
|
50
|
+
- lib/cutest.rb
|
51
|
+
- cutest.gemspec
|
52
|
+
- test/a_test.rb
|
53
|
+
- test/b_test.rb
|
54
|
+
- test/c_test.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/djanowski/cutest
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.7
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Forking tests.
|
87
|
+
test_files: []
|
88
|
+
|