fun_with_testing 0.0.4 → 0.0.7
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.
- checksums.yaml +5 -13
- data/CHANGELOG.markdown +27 -0
- data/Gemfile +21 -10
- data/Rakefile +22 -6
- data/VERSION +1 -1
- data/lib/fun_with/testing/assertions/basics.rb +216 -139
- data/lib/fun_with/testing/assertions_test_case.rb +65 -0
- data/lib/fun_with/testing/test_case.rb +9 -57
- data/lib/fun_with/testing/test_mode_methods.rb +32 -0
- data/lib/fun_with/testing/verbosity_methods.rb +43 -0
- data/lib/fun_with_testing.rb +15 -9
- data/test/helper.rb +1 -30
- data/test/test_assertions.rb +578 -14
- data/test/test_fun_with_testing.rb +0 -3
- data/test/test_test_mode.rb +29 -28
- data/test/test_verbosity.rb +2 -1
- metadata +91 -45
- data/lib/fun_with/testing/assertions/active_record.rb +0 -108
- data/lib/fun_with/testing/assertions/fun_with_files.rb +0 -109
@@ -0,0 +1,65 @@
|
|
1
|
+
module FunWith
|
2
|
+
module Testing
|
3
|
+
# Class is designed specifically for testing custom assertions.
|
4
|
+
# See test/test_assertions.rb for how it's supposed to work.
|
5
|
+
class AssertionsTestCase < FunWith::Testing::TestCase
|
6
|
+
# Any subclass of Test::Unit::TestCase seems to automatically hook into the test suite.
|
7
|
+
# Therefore, calling a test to see if it returns false makes the suite fail. Including
|
8
|
+
# to this class instead prevents that.
|
9
|
+
#
|
10
|
+
# I may need to more closely mimic Test::Unit::TestCase
|
11
|
+
# in order to test messages properly.
|
12
|
+
def safe_assert_block( *args, &block )
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
|
16
|
+
def extended_test_case( &block )
|
17
|
+
@case_class = Class.new( FunWith::Testing::AssertionsTestCase )
|
18
|
+
|
19
|
+
@case = @case_class.new( "MockUnitTest" ) # what does name arg do?
|
20
|
+
|
21
|
+
assert @case_class.methods.include?( :_should )
|
22
|
+
assert @case_class.methods.include?( :_context )
|
23
|
+
# assert @case.methods.include?( :in_test_mode? )
|
24
|
+
|
25
|
+
yield if block_given?
|
26
|
+
end
|
27
|
+
|
28
|
+
def must_flunk( &block )
|
29
|
+
assert_raises( Minitest::Assertion ) do
|
30
|
+
if block_given?
|
31
|
+
yield
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def yep( *args, &block )
|
37
|
+
assert @case.send( @current_method_sym, *args, &block )
|
38
|
+
end
|
39
|
+
|
40
|
+
def nope( *args, &block )
|
41
|
+
must_flunk do
|
42
|
+
@case.send( @current_method_sym, *args, &block )
|
43
|
+
|
44
|
+
# shouldn't get here
|
45
|
+
puts "should fail: #{@current_method_sym}( #{ args.map(&:inspect).join(", ")})"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def oops( *args )
|
50
|
+
assert_raises( StandardError ) do
|
51
|
+
@case.send( @current_method_sym, *args, &block )
|
52
|
+
|
53
|
+
# should not get here
|
54
|
+
puts "should cause error: #{@current_method_sym}( #{ args.map(&:inspect).join(", ")})"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def testing_method( m, &block )
|
59
|
+
@current_method_sym = m
|
60
|
+
yield
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -1,57 +1,16 @@
|
|
1
1
|
module FunWith
|
2
2
|
module Testing
|
3
3
|
class TestCase < Minitest::Test
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
# Okay, that was stupid. The point was to allow verbosity to be specified in the gem's code,
|
8
|
-
# not just in the test suite. What would that be... MyGem.test_mode? MyGem.verbose_gem? MyGem.say
|
9
|
-
def self.gem_to_test( gem_const = nil, test_mode = true )
|
10
|
-
if @fwt_gem_to_test
|
11
|
-
return @fwt_gem_to_test
|
12
|
-
elsif self.superclass.respond_to?( :gem_to_test )
|
13
|
-
self.superclass.gem_to_test
|
14
|
-
else
|
15
|
-
nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.gem_to_test=( gem_const )
|
20
|
-
@fwt_gem_to_test = gem_const
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.set_test_mode( mode = true )
|
24
|
-
self.const_set( :FWT_TEST_MODE, mode )
|
25
|
-
end
|
26
|
-
|
27
|
-
# Originally named test_mode?(), but Test::Unit::TestCase picked up on the fact that it started with "test"
|
28
|
-
# and tried to run it as a test in its own right
|
29
|
-
def self.in_test_mode?
|
30
|
-
return self::FWT_TEST_MODE if self.constants.include?( :FWT_TEST_MODE )
|
31
|
-
return self.superclass.in_test_mode? if self.superclass.respond_to?(:in_test_mode?)
|
32
|
-
return false
|
33
|
-
end
|
34
|
-
|
35
|
-
def in_test_mode?
|
36
|
-
self.class.in_test_mode?
|
4
|
+
def self.install_verbosity
|
5
|
+
include VerbosityMethods
|
37
6
|
end
|
38
7
|
|
39
|
-
def self.
|
40
|
-
|
8
|
+
def self.install_test_mode
|
9
|
+
include TestModeMethods
|
41
10
|
end
|
42
11
|
|
43
|
-
def self.
|
44
|
-
|
45
|
-
return self.superclass.verbose? if self.superclass.respond_to?(:verbose)
|
46
|
-
return false
|
47
|
-
end
|
48
|
-
|
49
|
-
def verbose?
|
50
|
-
self.class.verbose?
|
51
|
-
end
|
52
|
-
|
53
|
-
def puts_if_verbose( msg, stream = $stdout )
|
54
|
-
stream.puts( msg ) if self.verbose?
|
12
|
+
def self.install_basic_assertions
|
13
|
+
include Assertions::Basics
|
55
14
|
end
|
56
15
|
|
57
16
|
# Convenience methods for disappearing a set of tests. Useful for focusing on one or two tests.
|
@@ -62,16 +21,9 @@ module FunWith
|
|
62
21
|
def self._should(*args, &block)
|
63
22
|
puts "<<< WARNING >>> IGNORING TEST #{args.inspect}. Remove leading _ from '_should()' to reactivate."
|
64
23
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
assert_equal [], jem.validate_gem
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def build_message( *args )
|
73
|
-
args.map(&:inspect).join(" ")
|
74
|
-
end
|
24
|
+
# def build_message( *args )
|
25
|
+
# args.map(&:inspect).join(" ")
|
26
|
+
# end
|
75
27
|
end
|
76
28
|
end
|
77
29
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module FunWith
|
2
|
+
module Testing
|
3
|
+
# For adding to a TestCase class
|
4
|
+
module TestModeMethods
|
5
|
+
def self.included( base )
|
6
|
+
base.extend( TestModeMethods::ClassMethods )
|
7
|
+
base.send( :include, TestModeMethods::InstanceMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
def ClassMethods
|
11
|
+
def set_test_mode( mode = true )
|
12
|
+
self.const_set( :FWT_TEST_MODE, mode )
|
13
|
+
end
|
14
|
+
|
15
|
+
# Originally named test_mode?(), but Test::Unit::TestCase picked up on the fact that it started with "test"
|
16
|
+
# and tried to run it as a test in its own right
|
17
|
+
def in_test_mode?
|
18
|
+
return self::FWT_TEST_MODE if self.constants.include?( :FWT_TEST_MODE )
|
19
|
+
return self.superclass.in_test_mode? if self.superclass.respond_to?(:in_test_mode?)
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def InstanceMethods
|
25
|
+
def in_test_mode?
|
26
|
+
self.class.in_test_mode?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module FunWith
|
2
|
+
module Testing
|
3
|
+
# For adding to a TestCase class
|
4
|
+
module VerbosityMethods
|
5
|
+
def self.included( base )
|
6
|
+
base.extend( ClassMethods )
|
7
|
+
base.send( :include, InstanceMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def set_verbose( mode = true )
|
12
|
+
self.const_set( :FWT_TEST_VERBOSITY, mode )
|
13
|
+
end
|
14
|
+
|
15
|
+
def verbose?
|
16
|
+
return self::FWT_TEST_VERBOSITY if self.constants.include?( :FWT_TEST_VERBOSITY )
|
17
|
+
return self.superclass.verbose? if self.superclass.respond_to?(:verbose)
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module InstanceMethods
|
23
|
+
def verbose?
|
24
|
+
self.class.verbose?
|
25
|
+
end
|
26
|
+
|
27
|
+
def puts_if_verbose( msg, stream = $stdout )
|
28
|
+
stream.puts( msg ) if self.verbose?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
module FunWith
|
38
|
+
module Testing
|
39
|
+
module VerbosityMethods
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/fun_with_testing.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'bundler'
|
2
|
-
require '
|
2
|
+
require 'byebug'
|
3
3
|
require 'minitest'
|
4
4
|
require 'minitest/autorun'
|
5
5
|
require 'shoulda'
|
6
|
-
require '
|
6
|
+
require 'juwelier'
|
7
7
|
|
8
8
|
begin
|
9
9
|
Bundler.setup(:default, :development)
|
@@ -15,15 +15,21 @@ end
|
|
15
15
|
|
16
16
|
|
17
17
|
files = Dir.glob( File.join( File.dirname(__FILE__), "fun_with", "testing", "**", "*.rb" ) )
|
18
|
+
files.map!{ |f| f.gsub( /\.rb$/, '' ) }
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
20
|
+
# TODO: I don't think this is an ideal way to prevent infinite loops
|
21
|
+
error_messages = []
|
22
22
|
|
23
|
+
while files.length > 0
|
24
|
+
begin
|
25
|
+
file = files.shift
|
26
|
+
require file
|
27
|
+
rescue NameError => e # if the class/module depends on a not-yet-defined class/module
|
28
|
+
warn "#{e.class}: #{e.message}"
|
29
|
+
files << file
|
30
|
+
raise "Too many errors!\n\t" + error_messages.join( "\n\t" ) if error_messages.length >= 100
|
31
|
+
end
|
32
|
+
end
|
23
33
|
|
24
|
-
# FunWith::Testing.extend( FunWith::Testing::FwtExtensions )
|
25
|
-
# FunWith::Testing.assertion_modules << FunWith::Testing::Assertions::ActiveRecord
|
26
|
-
# FunWith::Testing.assertion_modules << FunWith::Testing::Assertions::Basics
|
27
34
|
|
28
35
|
FunWith::Testing.send( :include, FunWith::Testing::Assertions::Basics )
|
29
|
-
FunWith::Testing.send( :include, FunWith::Testing::Assertions::ActiveRecord )
|
data/test/helper.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
# require 'rubygems'
|
2
1
|
require 'bundler'
|
3
|
-
require 'debugger'
|
4
2
|
|
5
3
|
begin
|
6
4
|
Bundler.setup(:default, :development)
|
@@ -20,35 +18,8 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
20
18
|
|
21
19
|
|
22
20
|
require 'fun_with_testing'
|
23
|
-
|
24
|
-
# class Minitest::Test
|
25
|
-
# end
|
26
|
-
|
27
|
-
# Any subclass of Test::Unit::TestCase seems to automatically hook into the test suite.
|
28
|
-
# Therefore, calling a test to see if it returns false makes the suite fail. Including
|
29
|
-
# to this class instead prevents that. I may need to more closely mimic Test::Unit::TestCase
|
30
|
-
# in order to test messages properly.
|
31
|
-
class MockUnitTest < FunWith::Testing::TestCase
|
32
|
-
def build_message( m, m2, obj = nil)
|
33
|
-
"#{m} #{m2} #{obj}"
|
34
|
-
end
|
35
|
-
|
36
|
-
def safe_assert_block( *args, &block )
|
37
|
-
yield
|
38
|
-
end
|
39
|
-
end
|
21
|
+
# require_relative File.join( "classes", "mock_unit_test" )
|
40
22
|
|
41
23
|
class FunWith::Testing::MyTestCase < FunWith::Testing::TestCase
|
42
|
-
def extended_test_case( &block )
|
43
|
-
@case_class = Class.new( MockUnitTest )
|
44
|
-
@case_class.send( :include, FunWith::Testing )
|
45
|
-
@case = @case_class.new( "MockUnitTest" )
|
46
|
-
|
47
|
-
assert @case_class.methods.include?( :_should )
|
48
|
-
assert @case_class.methods.include?( :_context )
|
49
|
-
assert @case.methods.include?( :in_test_mode? )
|
50
|
-
|
51
|
-
yield if block_given?
|
52
|
-
end
|
53
24
|
end
|
54
25
|
|
data/test/test_assertions.rb
CHANGED
@@ -2,31 +2,595 @@ require 'helper'
|
|
2
2
|
|
3
3
|
module FunWith
|
4
4
|
module Testing
|
5
|
-
class TestAssertions < FunWith::Testing::
|
6
|
-
|
5
|
+
class TestAssertions < FunWith::Testing::AssertionsTestCase
|
6
|
+
def modded_object( &block )
|
7
|
+
m = Module.new(&block)
|
8
|
+
o = Object.new
|
9
|
+
o.extend( m )
|
10
|
+
o
|
11
|
+
end
|
12
|
+
|
13
|
+
context "testing assertions" do
|
7
14
|
setup do
|
8
|
-
extended_test_case
|
15
|
+
extended_test_case # sets @case, which is used to access to assertions
|
16
|
+
@case_class.install_basic_assertions # send( :include, FunWith::Testing::Assertions::Basics )
|
17
|
+
end
|
18
|
+
|
19
|
+
context "testing :assert_zero()" do
|
20
|
+
should "accept only zeroes, reject all others" do
|
21
|
+
testing_method :assert_zero do
|
22
|
+
yep 0
|
23
|
+
yep 0.0
|
24
|
+
|
25
|
+
nope 1
|
26
|
+
nope :potato
|
27
|
+
end
|
28
|
+
|
29
|
+
testing_method :refute_zero do
|
30
|
+
yep 1
|
31
|
+
yep 0.4
|
32
|
+
yep( -1 )
|
33
|
+
yep :zero
|
34
|
+
yep "0"
|
35
|
+
yep "zero"
|
36
|
+
yep ""
|
37
|
+
|
38
|
+
nope 0
|
39
|
+
nope "0".to_i
|
40
|
+
nope "0".to_f
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
context "testing :assert_not_zero()" do
|
47
|
+
should "look for non-zeros everywhere" do
|
48
|
+
testing_method :assert_not_zero do
|
49
|
+
yep 1
|
50
|
+
yep( -1 )
|
51
|
+
yep 0.01
|
52
|
+
yep( -0.01 )
|
53
|
+
yep :zero
|
54
|
+
yep []
|
55
|
+
yep( {} )
|
56
|
+
yep ""
|
57
|
+
yep nil
|
58
|
+
nope 0
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "testing :assert_one()" do
|
64
|
+
should "pass all tests" do
|
65
|
+
testing_method :assert_one do
|
66
|
+
yep 1
|
67
|
+
yep 1.0
|
68
|
+
yep 1.to_c # comparison as a complex number
|
69
|
+
nope 2
|
70
|
+
nope( -3 )
|
71
|
+
nope []
|
72
|
+
nope( {} )
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "testing :refute_one()" do
|
78
|
+
should "pass all tests" do
|
79
|
+
testing_method :refute_one do
|
80
|
+
yep 2
|
81
|
+
yep( -3 )
|
82
|
+
yep []
|
83
|
+
yep( {} )
|
84
|
+
nope 1
|
85
|
+
nope 1.0
|
86
|
+
nope 1.to_c # comparison as a complex number
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "testing :assert_positive()" do
|
92
|
+
should "pass all tests" do
|
93
|
+
testing_method :assert_positive do
|
94
|
+
yep 1
|
95
|
+
yep 1000
|
96
|
+
yep 1000.0
|
97
|
+
yep 0.0000000000001
|
98
|
+
yep 5
|
99
|
+
yep 4
|
100
|
+
yep 0.00001
|
101
|
+
yep Math::PI
|
102
|
+
yep 1337
|
103
|
+
yep 91
|
104
|
+
|
105
|
+
nope 0
|
106
|
+
nope( -0.00001 )
|
107
|
+
nope( -50 )
|
108
|
+
nope( -5000 )
|
109
|
+
nope( -50000 )
|
110
|
+
nope 0
|
111
|
+
nope( -0.000000000001 )
|
112
|
+
nope( -1 )
|
113
|
+
nope( -1000 )
|
114
|
+
nope( -1000000 )
|
115
|
+
|
116
|
+
oops true
|
117
|
+
oops false
|
118
|
+
oops 10000.to_c
|
119
|
+
oops "3"
|
120
|
+
oops( {} )
|
121
|
+
oops []
|
122
|
+
oops :symbol
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "testing :refute_positive()" do
|
128
|
+
should "pass all tests" do
|
129
|
+
testing_method :refute_positive do
|
130
|
+
yep 0
|
131
|
+
yep 0.0
|
132
|
+
yep( -1 )
|
133
|
+
yep( -100 )
|
134
|
+
yep( -0.000000000001 )
|
135
|
+
yep( -1 )
|
136
|
+
yep( -1000 )
|
137
|
+
yep( -1000000 )
|
138
|
+
|
139
|
+
nope 1
|
140
|
+
nope 1000
|
141
|
+
nope 1000.0
|
142
|
+
nope 0.0000000000001
|
143
|
+
nope 0.0001
|
144
|
+
nope 1
|
145
|
+
nope 5
|
146
|
+
nope 99999999999999
|
147
|
+
|
148
|
+
oops []
|
149
|
+
oops nil
|
150
|
+
oops 5.to_c
|
151
|
+
oops 10000.to_c
|
152
|
+
oops true
|
153
|
+
oops false
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context "testing :assert_true()" do
|
159
|
+
should "pass all tests" do
|
160
|
+
testing_method :assert_true do
|
161
|
+
yep true
|
162
|
+
|
163
|
+
nope false
|
164
|
+
nope nil
|
165
|
+
nope 5
|
166
|
+
nope "string"
|
167
|
+
nope :symbol
|
168
|
+
nope []
|
169
|
+
nope Hash.new
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "testing :assert_false()" do
|
175
|
+
should "pass all tests" do
|
176
|
+
testing_method :assert_false do
|
177
|
+
yep false
|
178
|
+
|
179
|
+
nope true
|
180
|
+
nope nil
|
181
|
+
nope 5
|
182
|
+
nope "string"
|
183
|
+
nope :symbol
|
184
|
+
nope []
|
185
|
+
nope Hash.new
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "testing :refute_true()" do
|
191
|
+
should "pass all tests" do
|
192
|
+
testing_method :refute_true do
|
193
|
+
yep false
|
194
|
+
yep nil
|
195
|
+
yep 5
|
196
|
+
yep "string"
|
197
|
+
yep :symbol
|
198
|
+
yep []
|
199
|
+
yep Hash.new
|
200
|
+
|
201
|
+
nope true
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "testing :refute_false()" do
|
207
|
+
should "pass all tests" do
|
208
|
+
testing_method :refute_false do
|
209
|
+
yep true
|
210
|
+
yep nil
|
211
|
+
yep 5
|
212
|
+
yep "string"
|
213
|
+
yep :symbol
|
214
|
+
yep []
|
215
|
+
yep Hash.new
|
216
|
+
|
217
|
+
nope false
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "testing :assert_nil()" do
|
223
|
+
should "pass all tests" do
|
224
|
+
testing_method :assert_nil do
|
225
|
+
yep nil
|
226
|
+
|
227
|
+
nope true
|
228
|
+
nope false
|
229
|
+
nope 5
|
230
|
+
nope "string"
|
231
|
+
nope :symbol
|
232
|
+
nope []
|
233
|
+
nope Hash.new
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context "testing :refute_nil()" do
|
239
|
+
should "pass all tests" do
|
240
|
+
testing_method :refute_nil do
|
241
|
+
yep true
|
242
|
+
yep false
|
243
|
+
yep 5
|
244
|
+
yep "string"
|
245
|
+
yep :symbol
|
246
|
+
yep []
|
247
|
+
yep Hash.new # if not given parentheses, seen as a block not a hash.
|
248
|
+
|
249
|
+
nope nil
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
context "testing :assert_blank()" do
|
255
|
+
should "pass all tests" do
|
256
|
+
|
257
|
+
blank_obj = modded_object do
|
258
|
+
def blank?
|
259
|
+
true
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
fwfblank_obj = modded_object do
|
264
|
+
def fwf_blank?
|
265
|
+
true
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
not_blank_obj = modded_object do
|
270
|
+
def blank?
|
271
|
+
false
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
blank_error_obj = modded_object do
|
276
|
+
def fwf_blank?
|
277
|
+
raise StandardError.new("Raises error!")
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
blank_returns_5_obj = modded_object do
|
282
|
+
def fwf_blank?
|
283
|
+
5
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
testing_method :assert_responds_to_blank do
|
288
|
+
nope []
|
289
|
+
nope( {} )
|
290
|
+
nope ""
|
291
|
+
nope Object.new
|
292
|
+
nope Set.new
|
293
|
+
|
294
|
+
yep blank_obj
|
295
|
+
yep fwfblank_obj
|
296
|
+
yep not_blank_obj
|
297
|
+
yep blank_error_obj
|
298
|
+
yep blank_returns_5_obj
|
299
|
+
end
|
300
|
+
|
301
|
+
testing_method :assert_blank do
|
302
|
+
# As implemented, assert_blank first asserts the item responds to blank, causing its own error
|
303
|
+
nope []
|
304
|
+
nope( {} )
|
305
|
+
nope Set.new
|
306
|
+
nope ""
|
307
|
+
|
308
|
+
yep blank_obj
|
309
|
+
yep fwfblank_obj
|
310
|
+
|
311
|
+
nope not_blank_obj
|
312
|
+
|
313
|
+
oops blank_error_obj
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
context "testing :assert_matches()" do
|
319
|
+
should "pass all tests" do
|
320
|
+
testing_method :assert_matches do
|
321
|
+
yep "Why hello there!", /hello/
|
322
|
+
nope "Why HELLO there!", /hello/
|
323
|
+
yep "Why HELLO there!", /hello/i
|
324
|
+
|
325
|
+
yep "Why HELLO there!", "HELLO"
|
326
|
+
nope "Why HELLO there!", "hello"
|
327
|
+
|
328
|
+
oops 5, /oopsie/
|
329
|
+
oops "oops", :symbol
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
context "testing :refute_matches()" do
|
335
|
+
should "pass all tests" do
|
336
|
+
testing_method :refute_matches do
|
337
|
+
nope "Why hello there!", /hello/
|
338
|
+
yep "Why HELLO there!", /hello/
|
339
|
+
nope "Why HELLO there!", /hello/i
|
340
|
+
|
341
|
+
nope "Why HELLO there!", "HELLO"
|
342
|
+
yep "Why HELLO there!", "hello"
|
343
|
+
|
344
|
+
oops 5, /oopsie/
|
345
|
+
oops "oops", :symbol
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
context "testing :assert_greater_than()" do
|
351
|
+
should "pass all tests" do
|
352
|
+
testing_method :assert_greater_than do
|
353
|
+
yep 5, 5.1
|
354
|
+
yep( -4, -3 )
|
355
|
+
yep "a", "b"
|
356
|
+
nope 0, 0
|
357
|
+
nope 0, 0.0
|
358
|
+
nope 5.1, 5.0
|
359
|
+
nope( -4, -5 )
|
360
|
+
|
361
|
+
oops 5, nil
|
362
|
+
oops 6, []
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
context "testing :assert_less_than()" do
|
368
|
+
should "pass all tests" do
|
369
|
+
testing_method( :assert_less_than ) do
|
370
|
+
yep 5, 4
|
371
|
+
yep "b", "a"
|
372
|
+
yep 100, 7.1
|
373
|
+
yep 0.0, -1
|
374
|
+
yep 0.999, 0.998
|
375
|
+
|
376
|
+
nope 0, 0
|
377
|
+
nope 0.0, 0
|
378
|
+
nope "a", "a"
|
379
|
+
nope( -1000, -100 )
|
380
|
+
nope 5, 6
|
381
|
+
|
382
|
+
oops 1000, "a"
|
383
|
+
oops "a", nil
|
384
|
+
end
|
385
|
+
end
|
9
386
|
end
|
10
387
|
|
11
|
-
|
12
|
-
|
388
|
+
context "testing :assert_at_most()" do
|
389
|
+
should "pass all tests" do
|
390
|
+
testing_method :assert_at_most do
|
391
|
+
yep 0, 0
|
392
|
+
yep 0, 0.0
|
393
|
+
yep 0.0, 0.0
|
394
|
+
yep 5, 3
|
395
|
+
yep 5, 1.4
|
396
|
+
|
397
|
+
nope 2, 6
|
398
|
+
nope( -12, -4 )
|
399
|
+
|
400
|
+
oops 5, []
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
context "testing :assert_at_least()" do
|
406
|
+
should "pass all tests" do
|
407
|
+
testing_method :assert_at_least do
|
408
|
+
yep 0, 0
|
409
|
+
yep 0, 0.0
|
410
|
+
yep 0.0, 0.0
|
411
|
+
yep 3, 5
|
412
|
+
yep 1.4, 5
|
413
|
+
|
414
|
+
nope 6, 2
|
415
|
+
nope( -4, -14 )
|
416
|
+
|
417
|
+
oops 5, []
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
context "testing :assert_times_are_close()" do
|
423
|
+
should "pass all tests" do
|
424
|
+
@ref_time = Time.now
|
425
|
+
|
426
|
+
testing_method( :assert_times_are_close ) do
|
427
|
+
yep @ref_time, @ref_time + 1
|
428
|
+
yep @ref_time, @ref_time + 0.3
|
429
|
+
yep @ref_time, @ref_time
|
430
|
+
yep @ref_time, @ref_time - 5, 20 # 20-second window given
|
431
|
+
|
432
|
+
nope @ref_time, @ref_time + 0.1, 0.01
|
433
|
+
nope @ref_time, @ref_time + 1.1
|
434
|
+
nope @ref_time, @ref_time - 1.1
|
435
|
+
nope @ref_time, @ref_time - 100
|
436
|
+
nope @ref_time, @ref_time - 100, 99
|
437
|
+
|
438
|
+
oops @ref_time, nil
|
439
|
+
oops @ref_time, []
|
440
|
+
end
|
441
|
+
end
|
13
442
|
end
|
14
443
|
|
15
|
-
|
16
|
-
|
444
|
+
context "testing :assert_equal_length()" do
|
445
|
+
should "pass all tests" do
|
446
|
+
testing_method( :assert_equal_length ) do
|
447
|
+
yep [], []
|
448
|
+
yep [], {}
|
449
|
+
yep [1,2,3,4,5], { 1 => :one, 2 => :two, 3 => :three, 4 => :four, 5 => :five}
|
450
|
+
yep Set.new, {}
|
451
|
+
yep [1,2,3,4,5], :hello
|
452
|
+
|
453
|
+
nope :hello, "goodbye"
|
454
|
+
nope [], { 1 => :one }
|
455
|
+
nope Set.new( [1,2,3] ), Set.new( [4,5,6,7] )
|
456
|
+
end
|
457
|
+
end
|
17
458
|
end
|
18
459
|
|
19
|
-
|
20
|
-
|
460
|
+
context "testing :assert_length()" do
|
461
|
+
should "pass all tests" do
|
462
|
+
testing_method :assert_length do
|
463
|
+
yep 0, ""
|
464
|
+
yep 0, :""
|
465
|
+
yep 1, [ :one ]
|
466
|
+
yep 0..5, { 1 => :one, 2 => :two, 3 => :three }
|
467
|
+
yep 0..140, "This string is tweetable!"
|
468
|
+
yep 1..3, "two"
|
469
|
+
yep 4, "four"
|
470
|
+
|
471
|
+
nope 0, "hi"
|
472
|
+
nope 0, [ 1 ]
|
473
|
+
nope 5, "five"
|
474
|
+
nope 1..3, [1, 2, 3, 4]
|
475
|
+
nope 3..5, nil
|
476
|
+
end
|
477
|
+
end
|
21
478
|
end
|
22
479
|
|
23
|
-
|
24
|
-
|
480
|
+
context "testing :assert_equality_of_methods()" do
|
481
|
+
should "pass all tests" do
|
482
|
+
testing_method :assert_equality_of_methods do
|
483
|
+
yep 7, 7, :to_s, :hash, :to_f
|
484
|
+
nope 3, 4, :to_s, :hash, :to_f
|
485
|
+
nope [], {}, :last # hash doesn't respond to last
|
486
|
+
nope 3, 4, :times
|
487
|
+
nope 3, 4, :respond_to? # ArgumentError for both
|
488
|
+
end
|
489
|
+
end
|
25
490
|
end
|
26
491
|
|
27
|
-
|
28
|
-
|
29
|
-
|
492
|
+
context "testing :assert_nothing_raised()" do
|
493
|
+
should "pass all tests" do
|
494
|
+
testing_method :assert_nothing_raised do
|
495
|
+
yep do
|
496
|
+
5 + 6
|
497
|
+
end
|
498
|
+
|
499
|
+
yep do
|
500
|
+
nil
|
501
|
+
end
|
502
|
+
|
503
|
+
nope do
|
504
|
+
raise StandardError.new( "whoops" )
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
# context "testing :555()" do
|
511
|
+
# should "pass all tests" do
|
512
|
+
# testing_method : do
|
513
|
+
# yep
|
514
|
+
# yep
|
515
|
+
# yep
|
516
|
+
# yep
|
517
|
+
# yep
|
518
|
+
# yep
|
519
|
+
|
520
|
+
# nope
|
521
|
+
# nope
|
522
|
+
# nope
|
523
|
+
# nope
|
524
|
+
# nope
|
525
|
+
# nope
|
526
|
+
|
527
|
+
# oops
|
528
|
+
# end
|
529
|
+
# end
|
530
|
+
# context "testing :555()" do
|
531
|
+
# should "pass all tests" do
|
532
|
+
# testing_method : do
|
533
|
+
# yep
|
534
|
+
# yep
|
535
|
+
# yep
|
536
|
+
# yep
|
537
|
+
# yep
|
538
|
+
# yep
|
539
|
+
|
540
|
+
# nope
|
541
|
+
# nope
|
542
|
+
# nope
|
543
|
+
# nope
|
544
|
+
# nope
|
545
|
+
# nope
|
546
|
+
|
547
|
+
# oops
|
548
|
+
# end
|
549
|
+
# end
|
550
|
+
|
551
|
+
|
552
|
+
context "testing instance assertions" do
|
553
|
+
should "assure us that classes have methods" do
|
554
|
+
instance_methods = {
|
555
|
+
Integer => [:to_s, :odd?, :even?, :times, :ceil],
|
556
|
+
Fixnum => [:to_f],
|
557
|
+
Array => [:length, :each, :sort, :map],
|
558
|
+
Object => [:hash, :tap, :is_a?, :to_s]
|
559
|
+
}
|
560
|
+
|
561
|
+
testing_method :assert_has_instance_method do
|
562
|
+
for klass, methods in instance_methods
|
563
|
+
for method in methods
|
564
|
+
yep klass, method
|
565
|
+
end
|
566
|
+
end
|
567
|
+
end
|
568
|
+
end
|
569
|
+
|
570
|
+
should "assure us that classes don't have hinkey instance methods" do
|
571
|
+
instance_methods = {
|
572
|
+
Integer => [:to_p, :old?, :seven?, :timey, :seal],
|
573
|
+
Fixnum => [:to_g],
|
574
|
+
Array => [:lanth, :eech, :sorta, :nap, :way_too_long?],
|
575
|
+
Object => [:hashbrown, :tarp, :is_also_a?, :to_sting]
|
576
|
+
}
|
577
|
+
|
578
|
+
testing_method :assert_has_instance_method do
|
579
|
+
for klass, methods in instance_methods
|
580
|
+
for method in methods
|
581
|
+
nope klass, method
|
582
|
+
end
|
583
|
+
end
|
584
|
+
end
|
585
|
+
end
|
586
|
+
end
|
587
|
+
|
588
|
+
context "testing length assertions" do
|
589
|
+
should "acknowledge the zerolengthiness of the empty array" do
|
590
|
+
@case.assert_length 0, []
|
591
|
+
@case.assert_length 17, %w(my mother told me to pick the very best one and the very best one is you)
|
592
|
+
@case.assert_equal_length [], []
|
593
|
+
end
|
30
594
|
end
|
31
595
|
end
|
32
596
|
end
|