assertor 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +38 -0
- data/Rakefile +16 -0
- data/VERSION +1 -0
- data/assertor.gemspec +59 -0
- data/lib/assertor.rb +2 -0
- data/lib/assertor/assert_failed_exception.rb +4 -0
- data/lib/assertor/case.rb +85 -0
- data/lib/assertor/reporter.rb +60 -0
- data/run_tests.rb +6 -0
- data/test/case_tests/assertions/assert_equals_test.rb +23 -0
- data/test/case_tests/assertions/assert_not_test.rb +32 -0
- data/test/case_tests/assertions/assert_raises_test.rb +69 -0
- data/test/case_tests/assertions/assert_test.rb +34 -0
- data/test/case_tests/class_methods/all_test.rb +19 -0
- data/test/case_tests/class_methods/ignore_test.rb +18 -0
- data/test/case_tests/class_methods/run_all_test.rb +37 -0
- data/test/case_tests/class_methods/run_test.rb +50 -0
- data/test/case_tests/class_methods/tests_test.rb +24 -0
- data/test/helper.rb +19 -0
- data/test/reporter_tests/defaults_test.rb +13 -0
- data/test/reporter_tests/run_test.rb +66 -0
- metadata +79 -0
data/.document
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Enrique García Cota
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= assertor
|
2
|
+
|
3
|
+
A very minimal gem for unit testing.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
class ArrayTest < Assertor::Case
|
8
|
+
|
9
|
+
def should_be_empty_after_being_created
|
10
|
+
array = []
|
11
|
+
assert(array.empty?, 'The array should be empty')
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
There's no setup and no teardown. If you need them, use initialize and destroy (the instance is re-created for each test).
|
17
|
+
|
18
|
+
== Running:
|
19
|
+
|
20
|
+
TBD
|
21
|
+
|
22
|
+
== Contributing to assertor
|
23
|
+
|
24
|
+
If you wanted, you could. There is certainly room for improvement.
|
25
|
+
|
26
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
27
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
28
|
+
* Fork the project
|
29
|
+
* Start a feature/bugfix branch
|
30
|
+
* Commit and push until you are happy with your contribution
|
31
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
32
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
33
|
+
|
34
|
+
== Copyright
|
35
|
+
|
36
|
+
Copyright (c) 2011 Enrique García Cota. See LICENSE.txt for
|
37
|
+
further details.
|
38
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
8
|
+
gem.name = "assertor"
|
9
|
+
gem.homepage = "http://github.com/kikito/assertor"
|
10
|
+
gem.license = "MIT"
|
11
|
+
gem.summary = %Q{Very minimal unit test lib for ruby.}
|
12
|
+
gem.description = %Q{Very minimal unit test lib for ruby.}
|
13
|
+
gem.email = "kikito@gmail.com"
|
14
|
+
gem.authors = ["Enrique García Cota"]
|
15
|
+
end
|
16
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/assertor.gemspec
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{assertor}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Enrique García Cota"]
|
12
|
+
s.date = %q{2011-05-24}
|
13
|
+
s.description = %q{Very minimal unit test lib for ruby.}
|
14
|
+
s.email = %q{kikito@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"LICENSE.txt",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"assertor.gemspec",
|
26
|
+
"lib/assertor.rb",
|
27
|
+
"lib/assertor/assert_failed_exception.rb",
|
28
|
+
"lib/assertor/case.rb",
|
29
|
+
"lib/assertor/reporter.rb",
|
30
|
+
"run_tests.rb",
|
31
|
+
"test/case_tests/assertions/assert_equals_test.rb",
|
32
|
+
"test/case_tests/assertions/assert_not_test.rb",
|
33
|
+
"test/case_tests/assertions/assert_raises_test.rb",
|
34
|
+
"test/case_tests/assertions/assert_test.rb",
|
35
|
+
"test/case_tests/class_methods/all_test.rb",
|
36
|
+
"test/case_tests/class_methods/ignore_test.rb",
|
37
|
+
"test/case_tests/class_methods/run_all_test.rb",
|
38
|
+
"test/case_tests/class_methods/run_test.rb",
|
39
|
+
"test/case_tests/class_methods/tests_test.rb",
|
40
|
+
"test/helper.rb",
|
41
|
+
"test/reporter_tests/defaults_test.rb",
|
42
|
+
"test/reporter_tests/run_test.rb"
|
43
|
+
]
|
44
|
+
s.homepage = %q{http://github.com/kikito/assertor}
|
45
|
+
s.licenses = ["MIT"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = %q{1.6.2}
|
48
|
+
s.summary = %q{Very minimal unit test lib for ruby.}
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
s.specification_version = 3
|
52
|
+
|
53
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
+
else
|
55
|
+
end
|
56
|
+
else
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/lib/assertor.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'assertor/assert_failed_exception'
|
2
|
+
|
3
|
+
module Assertor
|
4
|
+
|
5
|
+
class Case
|
6
|
+
|
7
|
+
@@all = []
|
8
|
+
|
9
|
+
def self.all
|
10
|
+
@@all
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.inherited(klass)
|
14
|
+
@@all << klass if klass.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.tests
|
18
|
+
instance_methods(false)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.run
|
22
|
+
passed, failed, errors, exceptions = [], [], [], {}
|
23
|
+
tests.each{ |test| run_single_test(test, passed, failed, errors, exceptions) }
|
24
|
+
{:passed => passed.sort, :failed => failed.sort, :errors => errors.sort, :exceptions => exceptions}
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.run_all(case_list)
|
28
|
+
result = {}
|
29
|
+
case_list.each do |c|
|
30
|
+
raise ArgumentError.new('Unnamed cases are not accepted in run_all') unless c.name
|
31
|
+
result[c.name] = c.run
|
32
|
+
end
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.ignore(aCase)
|
37
|
+
@@all.delete aCase
|
38
|
+
end
|
39
|
+
|
40
|
+
def assert(condition, msg='')
|
41
|
+
raise_failure(msg) unless condition
|
42
|
+
end
|
43
|
+
|
44
|
+
def assert_not(condition, msg='')
|
45
|
+
assert(!condition, msg)
|
46
|
+
end
|
47
|
+
|
48
|
+
def assert_equals(a, b)
|
49
|
+
assert(a==b, "Expected #{a} to be equal to #{b}")
|
50
|
+
end
|
51
|
+
|
52
|
+
def assert_raises(klass = Exception, msg=nil)
|
53
|
+
raise_failure('Block expected') unless block_given?
|
54
|
+
begin
|
55
|
+
yield
|
56
|
+
rescue Exception => e
|
57
|
+
raise_failure("Expected #{klass} to be raised, got #{e.class}") unless e.is_a? klass
|
58
|
+
raise_failure("Expected message to be '#{msg}', got '#{e.message}'") unless msg.nil? or e.message == msg
|
59
|
+
return
|
60
|
+
end
|
61
|
+
raise_failure('Exception expected')
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def self.run_single_test(test, passed, failed, errors, exceptions)
|
67
|
+
begin
|
68
|
+
new.send test
|
69
|
+
passed << test.to_s
|
70
|
+
rescue Assertor::AssertFailedException => e
|
71
|
+
failed << test.to_s
|
72
|
+
exceptions[test.to_s] = e
|
73
|
+
rescue Exception => e
|
74
|
+
errors << test.to_s
|
75
|
+
exceptions[test.to_s] = e
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def raise_failure(msg)
|
80
|
+
raise Assertor::AssertFailedException.new(msg)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Assertor
|
2
|
+
|
3
|
+
class Reporter
|
4
|
+
|
5
|
+
attr_reader :io, :case_list
|
6
|
+
|
7
|
+
def initialize(io=$stdout, case_list=Assertor::Case.all)
|
8
|
+
@io = io
|
9
|
+
@case_list = case_list
|
10
|
+
|
11
|
+
@passed, @failed, @errors, @exceptions = [],[],[],{}
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
calculate_results
|
16
|
+
print_counters
|
17
|
+
print_tests_with_exceptions(@failed, 'Failed')
|
18
|
+
print_tests_with_exceptions(@errors, 'Error')
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
private
|
23
|
+
def calculate_results
|
24
|
+
Assertor::Case.run_all(@case_list).each do |test_case, results|
|
25
|
+
add_test_results(test_case, results)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_test_results(test_case, results)
|
30
|
+
@passed += add_case_name_to_tests(test_case, results[:passed])
|
31
|
+
@failed += add_case_name_to_tests(test_case, results[:failed])
|
32
|
+
@errors += add_case_name_to_tests(test_case, results[:errors])
|
33
|
+
results[:exceptions].each do |test, exception|
|
34
|
+
@exceptions["#{test_case}.#{test}"] = exception
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_case_name_to_tests(test_case, tests)
|
39
|
+
tests.collect{ |test| "#{test_case}.#{test}" }
|
40
|
+
end
|
41
|
+
|
42
|
+
def print_counters
|
43
|
+
@io.puts("passed: #{@passed.size} failed: #{@failed.size} errors: #{@errors.size}")
|
44
|
+
end
|
45
|
+
|
46
|
+
def print_tests_with_exceptions(tests, type)
|
47
|
+
tests.each do |t|
|
48
|
+
exception = @exceptions[t]
|
49
|
+
@io.puts
|
50
|
+
@io.puts "#{type}: #{t}"
|
51
|
+
@io.puts " #{exception.inspect}"
|
52
|
+
@io.print " "
|
53
|
+
@io.puts exception.backtrace.join("\n ")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/run_tests.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CaseTests
|
4
|
+
|
5
|
+
module Assertions
|
6
|
+
|
7
|
+
class AssertEqualsTest < Assertor::Case
|
8
|
+
|
9
|
+
def test_with_equal_values
|
10
|
+
assert_equals(1,1)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_with_different_values
|
14
|
+
assert_raises Assertor::AssertFailedException, "Expected 1 to be equal to 2" do
|
15
|
+
assert_equals(1,2)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CaseTests
|
4
|
+
|
5
|
+
module Assertions
|
6
|
+
|
7
|
+
class AssertNotTest < Assertor::Case
|
8
|
+
|
9
|
+
def test_empty_assert
|
10
|
+
assert_not(false)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_empty_invalid_assert
|
14
|
+
assert_raises Assertor::AssertFailedException do
|
15
|
+
assert_not(true)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_assert_with_message
|
20
|
+
assert_not(false, "assert_not(false)")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_invalid_assert_with_message
|
24
|
+
msg = "Expected message"
|
25
|
+
assert_raises Assertor::AssertFailedException, msg do
|
26
|
+
assert_not(true, msg)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CaseTests
|
4
|
+
|
5
|
+
module Assertions
|
6
|
+
|
7
|
+
class AssertRaisesTest < Assertor::Case
|
8
|
+
|
9
|
+
def test_assert_raises_with_raising_block
|
10
|
+
assert_raises do
|
11
|
+
raise 'This test should initially fail'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_works_with_block_raising_correct_message
|
16
|
+
assert_raises(ArgumentError, 'foo') do
|
17
|
+
raise ArgumentError.new('foo')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_raises_error_without_block
|
22
|
+
begin
|
23
|
+
assert_raises
|
24
|
+
rescue Assertor::AssertFailedException
|
25
|
+
return
|
26
|
+
end
|
27
|
+
raise 'This test should initially fail'
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_raises_error_with_non_raising_block
|
31
|
+
begin
|
32
|
+
assert_raises do
|
33
|
+
end
|
34
|
+
rescue Assertor::AssertFailedException => e
|
35
|
+
raise "Erroneous message: #{e.message}" unless e.message == 'Exception expected'
|
36
|
+
return
|
37
|
+
end
|
38
|
+
raise 'This test should initially fail'
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_raises_error_with_block_raising_a_different_exception
|
42
|
+
begin
|
43
|
+
assert_raises(ArgumentError) do
|
44
|
+
raise "an unexpected error"
|
45
|
+
end
|
46
|
+
rescue Assertor::AssertFailedException => e
|
47
|
+
raise "Erroneous message: #{e.message}" unless e.message == 'Expected ArgumentError to be raised, got RuntimeError'
|
48
|
+
return
|
49
|
+
end
|
50
|
+
raise 'This test should initially fail'
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_raises_error_with_block_raising_a_different_message
|
54
|
+
begin
|
55
|
+
assert_raises(ArgumentError, 'foo') do
|
56
|
+
raise ArgumentError.new('bar')
|
57
|
+
end
|
58
|
+
rescue Assertor::AssertFailedException => e
|
59
|
+
raise "Erroneous message: #{e.message}" unless e.message == "Expected message to be 'foo', got 'bar'"
|
60
|
+
return
|
61
|
+
end
|
62
|
+
raise 'This test should initially fail'
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CaseTests
|
4
|
+
|
5
|
+
module Assertions
|
6
|
+
|
7
|
+
class AssertTest < Assertor::Case
|
8
|
+
|
9
|
+
def test_empty_assert
|
10
|
+
assert(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_empty_invalid_assert
|
14
|
+
assert_raises Assertor::AssertFailedException do
|
15
|
+
assert(false)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_assert_with_message
|
20
|
+
assert(true, "assert(true)")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_invalid_assert_with_message
|
24
|
+
msg = "Expected message"
|
25
|
+
assert_raises Assertor::AssertFailedException, msg do
|
26
|
+
assert(false, msg)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CaseTests
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
class AllTest < Assertor::Case
|
8
|
+
def should_not_include_anonymous_classes
|
9
|
+
assert_not Assertor::Case.all.include? make_unnamed_case
|
10
|
+
end
|
11
|
+
|
12
|
+
def should_include_classes_with_name
|
13
|
+
assert Assertor::Case.all.include? AllTest
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CaseTests
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
class IgnoreTest < Assertor::Case
|
8
|
+
|
9
|
+
def test_with_empty_list_of_cases
|
10
|
+
make_named_and_ignored_case(self, :IgnoredCase)
|
11
|
+
assert_not(Assertor::Case.all.include?(IgnoredCase))
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CaseTests
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
class RunAllTest < Assertor::Case
|
8
|
+
|
9
|
+
def test_with_empty_list_of_cases
|
10
|
+
assert(Assertor::Case.run_all([]) == {})
|
11
|
+
end
|
12
|
+
|
13
|
+
def raises_exception_with_unnamed_cases
|
14
|
+
assert_raises(ArgumentError) do
|
15
|
+
Assertor::Case.run_all([make_unnamed_case])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_with_list_of_empty_cases
|
20
|
+
make_named_and_ignored_case(self, :Foo)
|
21
|
+
assert_equals(Assertor::Case.run_all([Foo]), {Foo.name => Foo.run})
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_with_list_of_normal_cases
|
25
|
+
e = RuntimeError.new 'some error'
|
26
|
+
make_named_and_ignored_case(self, :Bar)
|
27
|
+
make_named_and_ignored_case(self, :Baz)
|
28
|
+
Bar.send :define_method, :foo do end
|
29
|
+
Baz.send :define_method, :bar do raise e end
|
30
|
+
assert_equals(Assertor::Case.run_all([Bar, Baz]), {Bar.name => Bar.run, Baz.name => Baz.run})
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CaseTests
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
class RunTest < Assertor::Case
|
8
|
+
|
9
|
+
def should_do_nothing_on_empty_cases
|
10
|
+
assert(make_unnamed_case.run == {:passed => [], :failed => [], :errors => [], :exceptions => {}})
|
11
|
+
end
|
12
|
+
|
13
|
+
def should_include_passing_tests
|
14
|
+
c = make_unnamed_case
|
15
|
+
c.send :define_method, :foo do end
|
16
|
+
c.send :define_method, :bar do end
|
17
|
+
assert_equals(c.run, {:passed => ['bar', 'foo'], :failed => [], :errors => [], :exceptions => {}})
|
18
|
+
end
|
19
|
+
|
20
|
+
def should_include_failing_tests
|
21
|
+
c = make_unnamed_case
|
22
|
+
e = Assertor::AssertFailedException.new('foo')
|
23
|
+
c.send :define_method, :foo do raise e end
|
24
|
+
c.send :define_method, :bar do raise e end
|
25
|
+
assert_equals(c.run, {
|
26
|
+
:passed => [],
|
27
|
+
:failed => ['bar', 'foo'],
|
28
|
+
:errors => [],
|
29
|
+
:exceptions => {'foo' => e, 'bar' => e}
|
30
|
+
})
|
31
|
+
end
|
32
|
+
|
33
|
+
def should_include_erroring_tests
|
34
|
+
c = make_unnamed_case
|
35
|
+
e = RuntimeError.new('foo')
|
36
|
+
c.send :define_method, :foo do raise e end
|
37
|
+
c.send :define_method, :bar do raise e end
|
38
|
+
assert_equals(c.run, {
|
39
|
+
:passed => [],
|
40
|
+
:failed => [],
|
41
|
+
:errors => ['bar', 'foo'],
|
42
|
+
:exceptions => {'foo' => e, 'bar' => e}
|
43
|
+
})
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CaseTests
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
class TestsTest < Assertor::Case
|
8
|
+
def empty_testcase_should_return_no_tests
|
9
|
+
assert_equals(make_unnamed_case.tests, [])
|
10
|
+
end
|
11
|
+
|
12
|
+
def should_return_public_instance_methods
|
13
|
+
c = make_unnamed_case
|
14
|
+
c.send :define_method, :foo do end
|
15
|
+
c.send :define_method, :bar do end
|
16
|
+
c.send :define_method, :baz do end
|
17
|
+
c.send :private, :baz
|
18
|
+
assert_equals(c.tests.sort, [:bar, :foo])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'assertor'
|
4
|
+
|
5
|
+
def make_unnamed_case
|
6
|
+
Class.new Assertor::Case
|
7
|
+
end
|
8
|
+
|
9
|
+
def make_named_case(context, name)
|
10
|
+
c = make_unnamed_case
|
11
|
+
context.class.const_set(name, c)
|
12
|
+
c
|
13
|
+
end
|
14
|
+
|
15
|
+
def make_named_and_ignored_case(context, name)
|
16
|
+
c = make_named_case(context, name)
|
17
|
+
Assertor::Case.ignore c
|
18
|
+
c
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module ReporterTests
|
4
|
+
|
5
|
+
class Defaults < Assertor::Case
|
6
|
+
def should_use_standard_io_and_all_tests_by_default
|
7
|
+
reporter = Assertor::Reporter.new
|
8
|
+
assert_equals(reporter.io, $stdout)
|
9
|
+
assert_equals(reporter.case_list, Assertor::Case.all)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
module ReporterTests
|
5
|
+
|
6
|
+
class RunTest < Assertor::Case
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@io = StringIO.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def should_return_000_with_empty_list
|
13
|
+
reporter = Assertor::Reporter.new(@io, [])
|
14
|
+
reporter.run
|
15
|
+
assert_equals(@io.string, "passed: 0 failed: 0 errors: 0\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
def should_return_000_with_empty_case
|
19
|
+
reporter = Assertor::Reporter.new(@io, [make_named_and_ignored_case(self, :Empty)])
|
20
|
+
reporter.run
|
21
|
+
assert_equals(@io.string, "passed: 0 failed: 0 errors: 0\n")
|
22
|
+
end
|
23
|
+
|
24
|
+
def should_return_100_with_passing_case
|
25
|
+
c = make_named_and_ignored_case(self, :Passing)
|
26
|
+
c.send :define_method, :test do end
|
27
|
+
reporter = Assertor::Reporter.new(@io, [c])
|
28
|
+
reporter.run
|
29
|
+
assert_equals(@io.string, "passed: 1 failed: 0 errors: 0\n")
|
30
|
+
end
|
31
|
+
|
32
|
+
def should_return_010_with_failing_case
|
33
|
+
e = Assertor::AssertFailedException.new
|
34
|
+
c = make_named_and_ignored_case(self, :Failing)
|
35
|
+
c.send :define_method, :test do raise e end
|
36
|
+
reporter = Assertor::Reporter.new(@io, [c])
|
37
|
+
reporter.run
|
38
|
+
expected_string = <<-eos
|
39
|
+
passed: 0 failed: 1 errors: 0
|
40
|
+
|
41
|
+
Failed: #{Failing}.test
|
42
|
+
#{e.inspect}
|
43
|
+
#{e.backtrace.join("\n ")}
|
44
|
+
eos
|
45
|
+
assert_equals(@io.string, expected_string)
|
46
|
+
end
|
47
|
+
|
48
|
+
def should_return_001_with_erroring_case
|
49
|
+
e = RuntimeError.new 'an error'
|
50
|
+
c = make_named_and_ignored_case(self, :Error)
|
51
|
+
c.send :define_method, :test do raise e end
|
52
|
+
reporter = Assertor::Reporter.new(@io, [c])
|
53
|
+
reporter.run
|
54
|
+
expected_string = <<-eos
|
55
|
+
passed: 0 failed: 0 errors: 1
|
56
|
+
|
57
|
+
Error: #{Error}.test
|
58
|
+
#{e.inspect}
|
59
|
+
#{e.backtrace.join("\n ")}
|
60
|
+
eos
|
61
|
+
assert_equals(@io.string, expected_string)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: assertor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- "Enrique Garc\xC3\xADa Cota"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-24 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Very minimal unit test lib for ruby.
|
18
|
+
email: kikito@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.rdoc
|
26
|
+
files:
|
27
|
+
- .document
|
28
|
+
- LICENSE.txt
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- assertor.gemspec
|
33
|
+
- lib/assertor.rb
|
34
|
+
- lib/assertor/assert_failed_exception.rb
|
35
|
+
- lib/assertor/case.rb
|
36
|
+
- lib/assertor/reporter.rb
|
37
|
+
- run_tests.rb
|
38
|
+
- test/case_tests/assertions/assert_equals_test.rb
|
39
|
+
- test/case_tests/assertions/assert_not_test.rb
|
40
|
+
- test/case_tests/assertions/assert_raises_test.rb
|
41
|
+
- test/case_tests/assertions/assert_test.rb
|
42
|
+
- test/case_tests/class_methods/all_test.rb
|
43
|
+
- test/case_tests/class_methods/ignore_test.rb
|
44
|
+
- test/case_tests/class_methods/run_all_test.rb
|
45
|
+
- test/case_tests/class_methods/run_test.rb
|
46
|
+
- test/case_tests/class_methods/tests_test.rb
|
47
|
+
- test/helper.rb
|
48
|
+
- test/reporter_tests/defaults_test.rb
|
49
|
+
- test/reporter_tests/run_test.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/kikito/assertor
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.6.2
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Very minimal unit test lib for ruby.
|
78
|
+
test_files: []
|
79
|
+
|