ae 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.rdoc +16 -0
- data/LICENSE +202 -21
- data/README.rdoc +3 -4
- data/{expo → demo}/cucumber/features/cucumber.feature +0 -0
- data/{expo → demo}/cucumber/features/step_definitions/cucumber_steps.rb +0 -0
- data/{expo → demo}/cucumber/features/support/env.rb +0 -0
- data/demo/minitest/example.rb +34 -0
- data/demo/testunit/example.rb +34 -0
- data/lib/ae.rb +16 -8
- data/lib/ae/adapter.rb +7 -0
- data/lib/ae/adapters/minitest.rb +24 -0
- data/lib/ae/adapters/rspec.rb +14 -0
- data/lib/ae/adapters/testunit.rb +33 -0
- data/lib/ae/assertion.rb +49 -9
- data/lib/ae/assertor.rb +29 -25
- data/lib/ae/basic_object.rb +2 -2
- data/lib/ae/meta/package +2 -2
- data/lib/ae/must.rb +48 -1
- data/lib/ae/pry.rb +1 -1
- data/lib/ae/should.rb +49 -1
- data/qed/01_overview.rdoc +4 -4
- data/qed/02_assertion.rdoc +3 -0
- data/qed/03_assert.rdoc +12 -10
- metadata +16 -12
- data/lib/ae/subjunctive/must.rb +0 -48
- data/lib/ae/subjunctive/should.rb +0 -49
- data/qed/06_counts.rdoc +0 -25
data/HISTORY.rdoc
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
= RELEASE HISTORY
|
2
2
|
|
3
|
+
== 1.5.0 / 2010-09-06
|
4
|
+
|
5
|
+
This release adds adapters for TestUnit, MiniTest and RSpec. AE worked with
|
6
|
+
them previously but AE assertions were seen as errors rather than natice
|
7
|
+
assertions. Likewise assertion counts were off in the final tally. These
|
8
|
+
adapters insert AE's counts so the the tally's are correct.
|
9
|
+
|
10
|
+
In addition to this the Assertion class itself now acts as the final end
|
11
|
+
point for all assertions, which makes for a very clean interface.
|
12
|
+
|
13
|
+
Changes:
|
14
|
+
|
15
|
+
* Add adapters for TestUnit, MiniTest and RSpec.
|
16
|
+
* Move final assertion call to Assertion#test.
|
17
|
+
|
18
|
+
|
3
19
|
== 1.4.0 / 2010-09-02
|
4
20
|
|
5
21
|
Version 1.4 brings Ruby 1.9 compatibility. The Assertor class is now a
|
data/LICENSE
CHANGED
@@ -1,23 +1,204 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
1
|
+
.
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
22
203
|
|
23
204
|
|
data/README.rdoc
CHANGED
@@ -15,7 +15,7 @@ intended for reuse by any TDD, BDD or similar system.
|
|
15
15
|
* Uses higher-order functions and fluid notation.
|
16
16
|
* Reusable core extensions ease assertion construction.
|
17
17
|
* Core extensions are standardized around Ruby Facets.
|
18
|
-
* Facets is
|
18
|
+
* But Facets is not a dependency; the extensions are built-in.
|
19
19
|
* Easily extensible allowing for alternate notations.
|
20
20
|
* Eats it's own dog food.
|
21
21
|
|
@@ -98,10 +98,9 @@ Windows users use 'ruby setup.rb all'.
|
|
98
98
|
|
99
99
|
== COPYRIGHTS & LICENSE
|
100
100
|
|
101
|
-
Copyright (c) 2008 Thomas Sawyer
|
101
|
+
Copyright (c) 2008,2010 Thomas Sawyer
|
102
102
|
|
103
103
|
Unless otherwise provided for by the originating author, this
|
104
|
-
program is distributed under the terms of the
|
104
|
+
program is distributed under the terms of the Apache 2 license.
|
105
105
|
|
106
106
|
See LICENSE file for details.
|
107
|
-
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'ae/adapters/minitest'
|
3
|
+
|
4
|
+
class MiniTestSupport < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_assert_pass
|
7
|
+
x = 5
|
8
|
+
y = 5
|
9
|
+
x.assert == y
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_assert_fail
|
13
|
+
x = 5
|
14
|
+
y = 6
|
15
|
+
x.assert == y
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_assert_fail_original
|
19
|
+
x = 5
|
20
|
+
y = 6
|
21
|
+
assert_equal(x, y)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_assert_pass_original
|
25
|
+
x = 5
|
26
|
+
y = 5
|
27
|
+
assert_equal(x, y)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_exception
|
31
|
+
raise
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'ae/adapters/testunit'
|
3
|
+
|
4
|
+
class TestUnitSupport < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_assert_pass
|
7
|
+
x = 5
|
8
|
+
y = 5
|
9
|
+
x.assert == y
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_assert_fail
|
13
|
+
x = 5
|
14
|
+
y = 6
|
15
|
+
x.assert == y
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_assert_fail_original
|
19
|
+
x = 5
|
20
|
+
y = 6
|
21
|
+
assert_equal(x, y)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_assert_pass_original
|
25
|
+
x = 5
|
26
|
+
y = 5
|
27
|
+
assert_equal(x, y)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_exception
|
31
|
+
raise
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/ae.rb
CHANGED
@@ -1,21 +1,29 @@
|
|
1
|
-
|
1
|
+
Object.__send__(:remove_const, :VERSION) if Object.const_defined?(:VERSION) # becuase Ruby 1.8~ gets in the way
|
2
2
|
|
3
3
|
module AE
|
4
|
-
DIRECTORY = File.dirname(__FILE__)
|
4
|
+
DIRECTORY = File.dirname(__FILE__)
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
def self.package
|
7
|
+
@package ||= (
|
8
|
+
require 'yaml'
|
9
|
+
YAML.load(File.new(DIRECTORY + '/package'))
|
10
|
+
)
|
11
|
+
end
|
8
12
|
|
9
|
-
|
13
|
+
def self.profile
|
14
|
+
@profile ||= (
|
15
|
+
require 'yaml'
|
16
|
+
YAML.load(File.new(DIRECTORY + '/profile'))
|
17
|
+
)
|
18
|
+
end
|
10
19
|
|
11
|
-
#
|
12
20
|
def self.const_missing(name)
|
13
21
|
key = name.to_s.downcase
|
14
|
-
|
22
|
+
package[key] || profile[key] || super(name)
|
15
23
|
end
|
16
24
|
end
|
17
25
|
|
18
26
|
require 'ae/assert'
|
19
27
|
require 'ae/expect'
|
20
28
|
|
21
|
-
# Copyright (c) 2008 Thomas Sawyer
|
29
|
+
# Copyright (c) 2008, 2010 Thomas Sawyer
|
data/lib/ae/adapter.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module MiniTest #:nodoc:
|
2
|
+
class Unit #:nodoc:
|
3
|
+
def status io = @@out
|
4
|
+
ae_count = ::Assertion.count
|
5
|
+
format = "%d tests, %d assertions, %d failures, %d errors, %d skips"
|
6
|
+
io.puts format % [test_count, assertion_count + ae_count, failures, errors, skips]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'ae'
|
12
|
+
|
13
|
+
class Assertion #:nodoc:
|
14
|
+
|
15
|
+
def self.framework_flunk(options)
|
16
|
+
message = options.delete(:message)
|
17
|
+
backtrace = options.delete(:backtrace)
|
18
|
+
|
19
|
+
err = MiniTest::Assertion.new(message)
|
20
|
+
err.set_backtrace(backtrace) if backtrace
|
21
|
+
fail err
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'ae'
|
2
|
+
|
3
|
+
class Assertion
|
4
|
+
|
5
|
+
def self.framework_flunk(options)
|
6
|
+
message = options.delete(:message)
|
7
|
+
backtrace = options.delete(:backtrace)
|
8
|
+
|
9
|
+
err = Spec::Expectations::ExpectationNotMetError.new(message)
|
10
|
+
err.set_backtrace(options[:backtrace]) if options[:backtrace]
|
11
|
+
fail err
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Test #:nodoc:
|
2
|
+
module Unit #:nodoc:
|
3
|
+
class TestCase #:nodoc:
|
4
|
+
alias_method :_run, :run
|
5
|
+
def run(result, &block)
|
6
|
+
$_result = result
|
7
|
+
_run(result, &block)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'ae'
|
14
|
+
|
15
|
+
class Assertion #:nodoc:
|
16
|
+
|
17
|
+
def self.increment(pass)
|
18
|
+
@count += 1
|
19
|
+
@fails += 1 unless pass
|
20
|
+
|
21
|
+
$_result.add_assertion if $_result
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.framework_flunk(options)
|
25
|
+
message = options.delete(:message)
|
26
|
+
backtrace = options.delete(:backtrace)
|
27
|
+
|
28
|
+
err = Test::Unit::AssertionFailedError.new(message)
|
29
|
+
err.set_backtrace(backtrace) if backtrace
|
30
|
+
fail err
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/ae/assertion.rb
CHANGED
@@ -11,25 +11,65 @@ require 'ae/core_ext'
|
|
11
11
|
#
|
12
12
|
class Assertion < Exception
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
@count = 0
|
15
|
+
@fails = 0
|
16
|
+
|
17
|
+
class << self
|
18
|
+
attr_accessor :count
|
19
|
+
attr_accessor :fails
|
20
|
+
|
21
|
+
#
|
22
|
+
def test(test, options={})
|
23
|
+
if test
|
24
|
+
increment(true)
|
25
|
+
else
|
26
|
+
framework_flunk(options)
|
27
|
+
end
|
28
|
+
test
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
#def self.framework_assert(options={})
|
33
|
+
#end
|
18
34
|
|
19
|
-
|
20
|
-
|
35
|
+
# This method can be replaced to support alternate frameworks.
|
36
|
+
# The intent of the methods is to raise the assertion failure
|
37
|
+
# class used.
|
38
|
+
def framework_flunk(options={})
|
39
|
+
message = options.delete(:message)
|
40
|
+
fail ::Assertion.new(message, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Increment assertion counts. If +pass+ is true then only +@count+
|
44
|
+
# is increased. If +pass+ if false then both +@count+ and +@fails+
|
45
|
+
# are incremented.
|
46
|
+
def increment(pass)
|
47
|
+
@count += 1
|
48
|
+
@fails += 1 unless pass
|
49
|
+
end
|
50
|
+
|
51
|
+
# Reset counts.
|
52
|
+
def recount
|
53
|
+
f, c = @fails, @count
|
54
|
+
@count = 0
|
55
|
+
@fails = 0
|
56
|
+
return f, c
|
57
|
+
end
|
58
|
+
end
|
21
59
|
|
22
60
|
#
|
23
|
-
def initialize(message=nil,
|
24
|
-
backtrace = opts[:backtrace]
|
61
|
+
def initialize(message=nil, options={})
|
25
62
|
super(message)
|
63
|
+
backtrace = options[:backtrace]
|
26
64
|
set_backtrace(backtrace) if backtrace
|
65
|
+
self.class.increment(false)
|
27
66
|
end
|
28
67
|
|
68
|
+
#
|
29
69
|
def to_s
|
30
70
|
'fail ' + super
|
31
71
|
end
|
32
72
|
|
33
73
|
end
|
34
74
|
|
35
|
-
# Copyright (c) 2008,
|
75
|
+
# Copyright (c) 2008, 2010 Thomas Sawyer
|
data/lib/ae/assertor.rb
CHANGED
@@ -13,9 +13,6 @@ require 'ae/basic_object'
|
|
13
13
|
#
|
14
14
|
class Assertor < AE::BasicObject
|
15
15
|
|
16
|
-
$assertions = 0
|
17
|
-
$failures = 0
|
18
|
-
|
19
16
|
#
|
20
17
|
#instance_methods.each{ |m| protected m unless /^(__|object_id$)/ =~ m.to_s }
|
21
18
|
|
@@ -87,18 +84,16 @@ class Assertor < AE::BasicObject
|
|
87
84
|
#--
|
88
85
|
# TODO: Should we deprecate the receiver matches in favor of #expected ?
|
89
86
|
# In other words, should the <code>|| @delegate</code> be dropped?
|
90
|
-
#
|
91
|
-
# TODO: respond_to?(:exception) && match = exception if Exception === match
|
92
87
|
#++
|
93
88
|
def expect(*args, &block)
|
94
89
|
return self if args.empty? && !block_given? # same as #assert
|
95
90
|
|
96
91
|
target = block || args.shift
|
97
92
|
|
98
|
-
if ::Proc === target
|
99
|
-
block = target.to_proc
|
93
|
+
if ::Proc === target #|| target.respond_to?(:to_proc)
|
94
|
+
#block = target.to_proc
|
100
95
|
match = args.shift || @delegate
|
101
|
-
if
|
96
|
+
if exception?(match)
|
102
97
|
$DEBUG, debug = false, $DEBUG # b/c it always spits-out a NameError
|
103
98
|
begin
|
104
99
|
block.arity > 0 ? block.call(@delegate) : block.call
|
@@ -126,14 +121,21 @@ class Assertor < AE::BasicObject
|
|
126
121
|
msg = @message || "#{target.inspect} === #{@delegate.inspect}"
|
127
122
|
end
|
128
123
|
|
129
|
-
#flunk(msg, caller) unless pass
|
130
124
|
__assert__(pass, msg)
|
131
125
|
end
|
132
126
|
|
127
|
+
# Is the +object+ and Exception or an instance of one.
|
128
|
+
#--
|
129
|
+
# TODO: Should we use a more libreral determination of exception.
|
130
|
+
# e.g. <code>respond_to?(:exception)</code>.
|
131
|
+
#++
|
132
|
+
def exception?(object)
|
133
|
+
::Exception === object or ::Class === object and object.ancestors.include?(::Exception)
|
134
|
+
end
|
135
|
+
|
133
136
|
#
|
134
|
-
def flunk(
|
135
|
-
|
136
|
-
fail ::Assertion.new(msg || @message, :backtrace=>@backtrace)
|
137
|
+
def flunk(message=nil)
|
138
|
+
__assert__(false, message || @message)
|
137
139
|
end
|
138
140
|
|
139
141
|
# Ruby seems to have a quark in it's implementation whereby
|
@@ -156,12 +158,6 @@ class Assertor < AE::BasicObject
|
|
156
158
|
pass = @delegate.__send__(sym, *a, &b)
|
157
159
|
#pass = @delegate.public_send(sym, *a, &b)
|
158
160
|
__assert__(pass, @message || __msg__(sym, *a, &b))
|
159
|
-
#Assertor.count += 1
|
160
|
-
#if (@negated ? pass : !pass)
|
161
|
-
#unless @negated ^ pass
|
162
|
-
# msg = @message || __msg__(sym, *a, &b)
|
163
|
-
# flunk(msg) #fail Assertion.new(msg, :backtrace=>@backtrace)
|
164
|
-
#end
|
165
161
|
end
|
166
162
|
|
167
163
|
# Puts together a suitable error message.
|
@@ -177,14 +173,22 @@ class Assertor < AE::BasicObject
|
|
177
173
|
end
|
178
174
|
|
179
175
|
# Pure old simple assert.
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
176
|
+
#--
|
177
|
+
# TODO: Can the handling of the message be simplified/improved?
|
178
|
+
#++
|
179
|
+
def __assert__(pass, message=nil)
|
180
|
+
pass = @negated ^ pass
|
181
|
+
# msg = message || @message
|
182
|
+
::Assertion.test(pass, :message=>message, :backtrace=>@backtrace)
|
183
|
+
return pass
|
186
184
|
end
|
187
185
|
|
186
|
+
# This method can be replaced to support alternate frameworks.
|
187
|
+
# The idea is to use to record that an assertion took place.
|
188
|
+
# def framework_assert(pass, message)
|
189
|
+
# # by default nothing needed
|
190
|
+
# end
|
191
|
+
|
188
192
|
#
|
189
193
|
def matcher_message(matcher)
|
190
194
|
if @negated
|
@@ -210,7 +214,7 @@ end
|
|
210
214
|
|
211
215
|
# DO WE MAKE THESE EXCEPTIONS?
|
212
216
|
#class BasicObject
|
213
|
-
# def assert
|
217
|
+
# def assert
|
214
218
|
# end
|
215
219
|
#end
|
216
220
|
|
data/lib/ae/basic_object.rb
CHANGED
@@ -21,7 +21,7 @@ else
|
|
21
21
|
# BlankSlate is useful as a base class when writing classes that
|
22
22
|
# depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
|
23
23
|
#
|
24
|
-
class BasicObject
|
24
|
+
class BasicObject #:nodoc:
|
25
25
|
|
26
26
|
# Hide the method named +name+ in the BlankSlate class. Don't
|
27
27
|
# hide +instance_eval+ or any method beginning with "__".
|
@@ -101,7 +101,7 @@ else
|
|
101
101
|
# "feature" of Ruby prevents late includes into modules from being
|
102
102
|
# exposed in the first place.
|
103
103
|
#
|
104
|
-
class Module
|
104
|
+
class Module #:nodoc:
|
105
105
|
alias basic_object_original_append_features append_features
|
106
106
|
def append_features(mod)
|
107
107
|
result = basic_object_original_append_features(mod)
|
data/lib/ae/meta/package
CHANGED
data/lib/ae/must.rb
CHANGED
@@ -1 +1,48 @@
|
|
1
|
-
require 'ae/subjunctive
|
1
|
+
require 'ae/subjunctive'
|
2
|
+
|
3
|
+
module AE
|
4
|
+
|
5
|
+
# = Must
|
6
|
+
#
|
7
|
+
# "It is not enough to succeed. Others must fail."
|
8
|
+
# --Gore Vidal (1925 - )
|
9
|
+
#
|
10
|
+
# THIS IS AN OPTIONAL LIBRARY.
|
11
|
+
#
|
12
|
+
module Must
|
13
|
+
# The #must method is functionaly the same as #should.
|
14
|
+
#
|
15
|
+
# 4.must == 3 #=> Assertion Error
|
16
|
+
#
|
17
|
+
# 4.must do
|
18
|
+
# self == 4
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
def must(*args, &block)
|
22
|
+
Assertor.new(self, :backtrace=>caller).be(*args, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Designate a negated expectation via a *functor*.
|
26
|
+
# Read this as "must not".
|
27
|
+
#
|
28
|
+
# 4.must! == 4 #=> Assertion Error
|
29
|
+
#
|
30
|
+
def must!(*args, &block)
|
31
|
+
Assertor.new(self, :backtrace=>caller).not.be(*args, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Perhaps not literally the counter-term to *must* (rather *will*),
|
35
|
+
# it is close enough for our purposes and conveys the appropriate semantics.
|
36
|
+
alias_method :wont, :must!
|
37
|
+
|
38
|
+
# Alias for #must! method.
|
39
|
+
#alias_method :musnt , :must!
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
class ::Object #:nodoc:
|
45
|
+
include AE::Must
|
46
|
+
end
|
47
|
+
|
48
|
+
# Copyright (c) 2008,2009 Thomas Sawyer
|
data/lib/ae/pry.rb
CHANGED
data/lib/ae/should.rb
CHANGED
@@ -1 +1,49 @@
|
|
1
|
-
require 'ae/subjunctive
|
1
|
+
require 'ae/subjunctive'
|
2
|
+
|
3
|
+
module AE
|
4
|
+
|
5
|
+
# = Should
|
6
|
+
#
|
7
|
+
# "Always and never are two words you should always
|
8
|
+
# remember never to use."
|
9
|
+
# --Wendell Johnson
|
10
|
+
#
|
11
|
+
# THIS IS AN OPTIONAL LIBRARY.
|
12
|
+
#
|
13
|
+
module Should
|
14
|
+
# Make an assertion in subjunctive tense.
|
15
|
+
#
|
16
|
+
# 4.should == 3 #=> Assertion Error
|
17
|
+
#
|
18
|
+
# 4.should do
|
19
|
+
# self == 4
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
def should(*args, &block)
|
23
|
+
Assertor.new(self, :backtrace=>caller).be(*args, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Designate a negated expectation via a *functor*.
|
27
|
+
# Read this as "should not".
|
28
|
+
#
|
29
|
+
# 4.should! == 4 #=> Assertion Error
|
30
|
+
#
|
31
|
+
def should!(*args, &block)
|
32
|
+
Assertor.new(self, :backtrace=>caller).not.be(*args, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Not quite the literally the counter-term to *should* (rather *shall*), but
|
36
|
+
# it is close enough for our purposes and conveys the appropriate semantics.
|
37
|
+
#alias_method :shant, :should!
|
38
|
+
|
39
|
+
# Alias for #should! method.
|
40
|
+
alias_method :shouldnt, :should!
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
class ::Object #:nodoc:
|
46
|
+
include AE::Should
|
47
|
+
end
|
48
|
+
|
49
|
+
# Copyright (c) 2008,2009 Thomas Sawyer
|
data/qed/01_overview.rdoc
CHANGED
@@ -7,14 +7,14 @@ reroutes method calls while monitoring them for failing
|
|
7
7
|
conditions.
|
8
8
|
|
9
9
|
|
10
|
-
== What
|
10
|
+
== What AE Provides
|
11
11
|
|
12
12
|
Requiring the AE library.
|
13
13
|
|
14
14
|
require 'ae'
|
15
15
|
|
16
16
|
Loads two classes, +Assertion+ and +Assertor+, the Kernel
|
17
|
-
method +assert+ and it's
|
17
|
+
method +assert+ and it's antonyms +assert!+ and +refute+
|
18
18
|
and a set of core extensions that make writing certain types
|
19
19
|
of assertions easier.
|
20
20
|
|
@@ -26,7 +26,7 @@ methods depend on it. The +Assertion+ class is a subclass
|
|
26
26
|
of Exception. When an assertion is made and fails, it is
|
27
27
|
an instance of Assertion that is raised.
|
28
28
|
|
29
|
-
Assertion
|
29
|
+
expect Assertion do
|
30
30
|
msg = "my failure message"
|
31
31
|
assert false, msg
|
32
32
|
end
|
@@ -63,7 +63,7 @@ statements like:
|
|
63
63
|
If the operation evaluates to false or nil, then an Assertion error
|
64
64
|
is raised.
|
65
65
|
|
66
|
-
Assertion
|
66
|
+
expect Assertion do
|
67
67
|
1.assert == 2
|
68
68
|
end
|
69
69
|
|
data/qed/02_assertion.rdoc
CHANGED
data/qed/03_assert.rdoc
CHANGED
@@ -11,7 +11,7 @@ the assertion fail.
|
|
11
11
|
|
12
12
|
assert(true, "Not true!")
|
13
13
|
|
14
|
-
Assertion
|
14
|
+
expect Assertion do
|
15
15
|
assert(false, "Not true!")
|
16
16
|
end
|
17
17
|
|
@@ -271,20 +271,22 @@ can be used in conjunction with +assert+.
|
|
271
271
|
|
272
272
|
x = X.new(4)
|
273
273
|
|
274
|
-
x.
|
275
|
-
|
274
|
+
x.instance_eval do
|
275
|
+
@a.assert == 4
|
276
276
|
end
|
277
277
|
|
278
|
-
|
278
|
+
However #instance_eval is a reserved method for the underlying Assertor class,
|
279
|
+
so it cannot be used on #assert, e.g.
|
279
280
|
|
280
|
-
|
281
|
-
|
282
|
-
5 == @a
|
283
|
-
end
|
281
|
+
x.assert.instance_eval do
|
282
|
+
@a == "obvisouly wrong"
|
284
283
|
end
|
285
284
|
|
285
|
+
AE offers an optional helper method for times when testing underlying private
|
286
|
+
or protected methods is important, called #pry. See the QED on pry for more
|
287
|
+
information.
|
288
|
+
|
286
289
|
For some testing underlying implementation might be considered poor
|
287
290
|
form. You will get no argument here. It should be used thoughtfully,
|
288
291
|
but I would not bet against there being occasions when such validations
|
289
|
-
might be
|
290
|
-
|
292
|
+
might be needed.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Thomas Sawyer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-06 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -55,16 +55,21 @@ extensions: []
|
|
55
55
|
extra_rdoc_files:
|
56
56
|
- README.rdoc
|
57
57
|
files:
|
58
|
-
-
|
59
|
-
-
|
60
|
-
-
|
58
|
+
- demo/cucumber/features/cucumber.feature
|
59
|
+
- demo/cucumber/features/step_definitions/cucumber_steps.rb
|
60
|
+
- demo/cucumber/features/support/env.rb
|
61
|
+
- demo/minitest/example.rb
|
62
|
+
- demo/testunit/example.rb
|
61
63
|
- qed/01_overview.rdoc
|
62
64
|
- qed/02_assertion.rdoc
|
63
65
|
- qed/03_assert.rdoc
|
64
66
|
- qed/04_subjunctive.rdoc
|
65
67
|
- qed/05_expect.rdoc
|
66
|
-
- qed/06_counts.rdoc
|
67
68
|
- qed/07_matchers.rdoc
|
69
|
+
- lib/ae/adapter.rb
|
70
|
+
- lib/ae/adapters/minitest.rb
|
71
|
+
- lib/ae/adapters/rspec.rb
|
72
|
+
- lib/ae/adapters/testunit.rb
|
68
73
|
- lib/ae/assert.rb
|
69
74
|
- lib/ae/assertion.rb
|
70
75
|
- lib/ae/assertor.rb
|
@@ -79,8 +84,6 @@ files:
|
|
79
84
|
- lib/ae/must.rb
|
80
85
|
- lib/ae/pry.rb
|
81
86
|
- lib/ae/should.rb
|
82
|
-
- lib/ae/subjunctive/must.rb
|
83
|
-
- lib/ae/subjunctive/should.rb
|
84
87
|
- lib/ae/subjunctive.rb
|
85
88
|
- lib/ae.rb
|
86
89
|
- HISTORY.rdoc
|
@@ -124,5 +127,6 @@ rubygems_version: 1.3.7
|
|
124
127
|
signing_key:
|
125
128
|
specification_version: 3
|
126
129
|
summary: Assertive Expressive
|
127
|
-
test_files:
|
128
|
-
|
130
|
+
test_files:
|
131
|
+
- lib/ae/adapters/minitest.rb
|
132
|
+
- lib/ae/adapters/testunit.rb
|
data/lib/ae/subjunctive/must.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'ae/subjunctive'
|
2
|
-
|
3
|
-
module AE
|
4
|
-
|
5
|
-
# = Must
|
6
|
-
#
|
7
|
-
# "It is not enough to succeed. Others must fail."
|
8
|
-
# --Gore Vidal (1925 - )
|
9
|
-
#
|
10
|
-
# THIS IS AN OPTIONAL LIBRARY.
|
11
|
-
#
|
12
|
-
module Must
|
13
|
-
# The #must method is functionaly the same as #should.
|
14
|
-
#
|
15
|
-
# 4.must == 3 #=> Assertion Error
|
16
|
-
#
|
17
|
-
# 4.must do
|
18
|
-
# self == 4
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
def must(*args, &block)
|
22
|
-
Assertor.new(self, :backtrace=>caller).be(*args, &block)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Designate a negated expectation via a *functor*.
|
26
|
-
# Read this as "must not".
|
27
|
-
#
|
28
|
-
# 4.must! == 4 #=> Assertion Error
|
29
|
-
#
|
30
|
-
def must!(*args, &block)
|
31
|
-
Assertor.new(self, :backtrace=>caller).not.be(*args, &block)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Perhaps not literally the counter-term to *must* (rather *will*),
|
35
|
-
# it is close enough for our purposes and conveys the appropriate semantics.
|
36
|
-
alias_method :wont, :must!
|
37
|
-
|
38
|
-
# Alias for #must! method.
|
39
|
-
#alias_method :musnt , :must!
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
class ::Object #:nodoc:
|
45
|
-
include AE::Must
|
46
|
-
end
|
47
|
-
|
48
|
-
# Copyright (c) 2008,2009 Thomas Sawyer
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'ae/subjunctive'
|
2
|
-
|
3
|
-
module AE
|
4
|
-
|
5
|
-
# = Should
|
6
|
-
#
|
7
|
-
# "Always and never are two words you should always
|
8
|
-
# remember never to use."
|
9
|
-
# --Wendell Johnson
|
10
|
-
#
|
11
|
-
# THIS IS AN OPTIONAL LIBRARY.
|
12
|
-
#
|
13
|
-
module Should
|
14
|
-
# Make an assertion in subjunctive tense.
|
15
|
-
#
|
16
|
-
# 4.should == 3 #=> Assertion Error
|
17
|
-
#
|
18
|
-
# 4.should do
|
19
|
-
# self == 4
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
def should(*args, &block)
|
23
|
-
Assertor.new(self, :backtrace=>caller).be(*args, &block)
|
24
|
-
end
|
25
|
-
|
26
|
-
# Designate a negated expectation via a *functor*.
|
27
|
-
# Read this as "should not".
|
28
|
-
#
|
29
|
-
# 4.should! == 4 #=> Assertion Error
|
30
|
-
#
|
31
|
-
def should!(*args, &block)
|
32
|
-
Assertor.new(self, :backtrace=>caller).not.be(*args, &block)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Not quite the literally the counter-term to *should* (rather *shall*), but
|
36
|
-
# it is close enough for our purposes and conveys the appropriate semantics.
|
37
|
-
#alias_method :shant, :should!
|
38
|
-
|
39
|
-
# Alias for #should! method.
|
40
|
-
alias_method :shouldnt, :should!
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
class ::Object #:nodoc:
|
46
|
-
include AE::Should
|
47
|
-
end
|
48
|
-
|
49
|
-
# Copyright (c) 2008,2009 Thomas Sawyer
|
data/qed/06_counts.rdoc
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
= Assertion Counts
|
2
|
-
|
3
|
-
AE tracks the number of assertions made and the number that failed to pass.
|
4
|
-
We can reset the count using the +recount+ class method.
|
5
|
-
|
6
|
-
Assertion.recount
|
7
|
-
|
8
|
-
For example if we one assertion fails and another fails.
|
9
|
-
|
10
|
-
assert(true)
|
11
|
-
assert(false)
|
12
|
-
|
13
|
-
We will see that AE counted two assertions and one failure.
|
14
|
-
|
15
|
-
Assertion.count.assert == 2
|
16
|
-
Assertion.fails.assert == 1
|
17
|
-
|
18
|
-
The above calls simply access the actual global variables.
|
19
|
-
|
20
|
-
$assertions.assert == 4
|
21
|
-
$failures.assert == 1
|
22
|
-
|
23
|
-
Notice there are now two additional assertions.
|
24
|
-
|
25
|
-
|