assert_repeated 1.0.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.
- data/.document +5 -0
- data/.gitignore +23 -0
- data/LICENSE +6 -0
- data/README.rdoc +39 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/assert_repeated.rb +59 -0
- data/test/helper.rb +9 -0
- data/test/test_assert_repeated.rb +77 -0
- metadata +66 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
data/README.rdoc
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
= assert_repeated
|
|
2
|
+
|
|
3
|
+
Assertions that run multiple times, used to smoke-test or
|
|
4
|
+
randomly probe a function with a large domain.
|
|
5
|
+
|
|
6
|
+
assert_repeatedly_true(1000) do
|
|
7
|
+
expected = rand(100)
|
|
8
|
+
actual = decrypt(encrypt(expected))
|
|
9
|
+
expected == actual
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
assert_repeatedly_false(10) do
|
|
13
|
+
!she_loves_me
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
assert_repeatedly(100_000, /awesome/) do
|
|
17
|
+
"writing tests is awesome!"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
This is way better than running assert in a loop because it doesn't
|
|
21
|
+
blow up the assertion counter:
|
|
22
|
+
|
|
23
|
+
45 tests, 1089 assertions, 0 failures, 0 errors
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
== Note on Patches/Pull Requests
|
|
27
|
+
|
|
28
|
+
* Fork the project.
|
|
29
|
+
* Add tests for your feature addition or bug fix.
|
|
30
|
+
* Commit.
|
|
31
|
+
* Make the tests pass.
|
|
32
|
+
* Commit.
|
|
33
|
+
* Send me a pull request.
|
|
34
|
+
|
|
35
|
+
== Copyright
|
|
36
|
+
|
|
37
|
+
Copyright (c) 2009 Bryce Kerley and Todd Willey.
|
|
38
|
+
|
|
39
|
+
DO WHATEVER YOU WANT WITH THIS SOFTWARE; see LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "assert_repeated"
|
|
8
|
+
gem.summary = "Assertions that run multiple times"
|
|
9
|
+
gem.description = "Assertions that run multiple times for testing functions with large domains"
|
|
10
|
+
gem.email = "bkerley@brycekerley.net"
|
|
11
|
+
gem.homepage = "http://github.com/bkerley/assert_repeated"
|
|
12
|
+
gem.authors = ["Bryce Kerley", "Todd Willey"]
|
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
14
|
+
end
|
|
15
|
+
Jeweler::GemcutterTasks.new
|
|
16
|
+
rescue LoadError
|
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
require 'rake/testtask'
|
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
|
22
|
+
test.libs << 'lib' << 'test'
|
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
|
24
|
+
test.verbose = true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
begin
|
|
28
|
+
require 'rcov/rcovtask'
|
|
29
|
+
Rcov::RcovTask.new do |test|
|
|
30
|
+
test.libs << 'test'
|
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
|
32
|
+
test.verbose = true
|
|
33
|
+
end
|
|
34
|
+
rescue LoadError
|
|
35
|
+
task :rcov do
|
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
task :test => :check_dependencies
|
|
41
|
+
|
|
42
|
+
task :default => :test
|
|
43
|
+
|
|
44
|
+
begin
|
|
45
|
+
require 'yard'
|
|
46
|
+
YARD::Rake::YardocTask.new
|
|
47
|
+
rescue LoadError
|
|
48
|
+
task :yardoc do
|
|
49
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
|
50
|
+
end
|
|
51
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.0
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module AssertRepeated
|
|
2
|
+
# Assertions that run multiple times, used to smoke-test or
|
|
3
|
+
# randomly probe a function with a large domain.
|
|
4
|
+
#
|
|
5
|
+
# == Usage
|
|
6
|
+
#
|
|
7
|
+
# assert_repeatedly_true(1000) do
|
|
8
|
+
# expected = rand(100)
|
|
9
|
+
# actual = decrypt(encrypt(expected))
|
|
10
|
+
# expected == actual
|
|
11
|
+
# end
|
|
12
|
+
|
|
13
|
+
# Check that the block returns +true+ +count+ times.
|
|
14
|
+
#
|
|
15
|
+
# == Arguments
|
|
16
|
+
# [+count+] number of times to run the block
|
|
17
|
+
# [+message+] optional message to return when the assertion fails
|
|
18
|
+
# [+block+] block that runs for the assertion; expected to evaluate to +true+
|
|
19
|
+
def assert_repeatedly_true(count, message=nil, &block)
|
|
20
|
+
assert_repeatedly count, true, message, &block
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Check that the block returns +false+ +count+ times.
|
|
24
|
+
#
|
|
25
|
+
# == Arguments
|
|
26
|
+
# [+count+] number of times to run the block
|
|
27
|
+
# [+message+] optional message to return when the assertion fails
|
|
28
|
+
# [+block+] block that runs for the assertion; expected to evaluate to +false+
|
|
29
|
+
def assert_repeatedly_false(count, message=nil, &block)
|
|
30
|
+
assert_repeatedly count, false, message, &block
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Check that the block returns +matcher+ +count+ times
|
|
34
|
+
#
|
|
35
|
+
# == Usage
|
|
36
|
+
#
|
|
37
|
+
# assert_repeatedly(100, /awesome/) { "tests are awesome" }
|
|
38
|
+
#
|
|
39
|
+
# == Arguments
|
|
40
|
+
# [+count+] number of times to run the block
|
|
41
|
+
# [+matcher+] what to compare against the block's result (using +#===+ )
|
|
42
|
+
# [+message+] optional message to return when the assertion fails
|
|
43
|
+
def assert_repeatedly(count, matcher=true, message=nil)
|
|
44
|
+
count.times do
|
|
45
|
+
result = yield
|
|
46
|
+
assert_block(build_message(message, "<?> is not ?.", result, matcher)){ false } unless matcher === result
|
|
47
|
+
end
|
|
48
|
+
# increment the count
|
|
49
|
+
assert true
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
module Test #:nodoc:
|
|
54
|
+
module Unit #:nodoc:
|
|
55
|
+
class TestCase #:nodoc:
|
|
56
|
+
include AssertRepeated
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
data/test/helper.rb
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
|
|
3
|
+
class TestAssertRepeated < Test::Unit::TestCase
|
|
4
|
+
def test_repeatedly_true
|
|
5
|
+
count = 0
|
|
6
|
+
assert_nothing_raised do
|
|
7
|
+
assert_repeatedly_true 100 do
|
|
8
|
+
count = count + 1
|
|
9
|
+
true
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
assert_equal 100, count
|
|
14
|
+
|
|
15
|
+
count = 0
|
|
16
|
+
|
|
17
|
+
assert_assertion_failure_raised_with_message "<false> is not true." do
|
|
18
|
+
assert_repeatedly_true 100 do
|
|
19
|
+
count = count + 1
|
|
20
|
+
false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
assert_equal 1, count
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_repeatedly_false
|
|
28
|
+
count = 0
|
|
29
|
+
assert_nothing_raised do
|
|
30
|
+
assert_repeatedly_false 100 do
|
|
31
|
+
count = count + 1
|
|
32
|
+
false
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
assert_equal 100, count
|
|
37
|
+
|
|
38
|
+
count = 0
|
|
39
|
+
|
|
40
|
+
assert_assertion_failure_raised_with_message "<true> is not false." do
|
|
41
|
+
assert_repeatedly_false 100 do
|
|
42
|
+
count = count + 1
|
|
43
|
+
true
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
assert_equal 1, count
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_assert_repeatedly_base
|
|
51
|
+
assert_nothing_raised do
|
|
52
|
+
assert_repeatedly(1, 7) { 7 }
|
|
53
|
+
assert_repeatedly(1, /x/) { 'x' }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
assert_assertion_failure_raised_with_message "<8> is not 7." do
|
|
57
|
+
assert_repeatedly(1, 7) { 8 }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
assert_assertion_failure_raised_with_message "<\"f\"> is not /x/." do
|
|
61
|
+
assert_repeatedly(1, /x/) { 'f' }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
# bonus secret assertion
|
|
67
|
+
def assert_assertion_failure_raised_with_message(message)
|
|
68
|
+
begin
|
|
69
|
+
yield
|
|
70
|
+
assert false, "No exception raised"
|
|
71
|
+
rescue Test::Unit::AssertionFailedError => e
|
|
72
|
+
assert_equal message, e.message
|
|
73
|
+
rescue Exception => e
|
|
74
|
+
assert false, "Unexpected exception <e> raised"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: assert_repeated
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bryce Kerley
|
|
8
|
+
- Todd Willey
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
|
|
13
|
+
date: 2009-11-22 00:00:00 -06:00
|
|
14
|
+
default_executable:
|
|
15
|
+
dependencies: []
|
|
16
|
+
|
|
17
|
+
description: Assertions that run multiple times for testing functions with large domains
|
|
18
|
+
email: bkerley@brycekerley.net
|
|
19
|
+
executables: []
|
|
20
|
+
|
|
21
|
+
extensions: []
|
|
22
|
+
|
|
23
|
+
extra_rdoc_files:
|
|
24
|
+
- LICENSE
|
|
25
|
+
- README.rdoc
|
|
26
|
+
files:
|
|
27
|
+
- .document
|
|
28
|
+
- .gitignore
|
|
29
|
+
- LICENSE
|
|
30
|
+
- README.rdoc
|
|
31
|
+
- Rakefile
|
|
32
|
+
- VERSION
|
|
33
|
+
- lib/assert_repeated.rb
|
|
34
|
+
- test/helper.rb
|
|
35
|
+
- test/test_assert_repeated.rb
|
|
36
|
+
has_rdoc: true
|
|
37
|
+
homepage: http://github.com/bkerley/assert_repeated
|
|
38
|
+
licenses: []
|
|
39
|
+
|
|
40
|
+
post_install_message:
|
|
41
|
+
rdoc_options:
|
|
42
|
+
- --charset=UTF-8
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: "0"
|
|
50
|
+
version:
|
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: "0"
|
|
56
|
+
version:
|
|
57
|
+
requirements: []
|
|
58
|
+
|
|
59
|
+
rubyforge_project:
|
|
60
|
+
rubygems_version: 1.3.5
|
|
61
|
+
signing_key:
|
|
62
|
+
specification_version: 3
|
|
63
|
+
summary: Assertions that run multiple times
|
|
64
|
+
test_files:
|
|
65
|
+
- test/helper.rb
|
|
66
|
+
- test/test_assert_repeated.rb
|