ae 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/HISTORY +12 -0
- data/LICENSE +677 -0
- data/MANIFEST +39 -0
- data/README +84 -0
- data/demo/01_overview.rdoc +97 -0
- data/demo/02_assertion.rdoc +1 -0
- data/demo/03_assert.rdoc +230 -0
- data/demo/04_subjunctive.rdoc +127 -0
- data/doc/qedoc/index.html +704 -0
- data/doc/qedoc/jquery.js +19 -0
- data/lib/ae.rb +7 -0
- data/lib/ae/assert.rb +57 -0
- data/lib/ae/assertion.rb +27 -0
- data/lib/ae/assertor.rb +104 -0
- data/lib/ae/core_ext.rb +202 -0
- data/lib/ae/subjunctive.rb +73 -0
- data/lib/ae/subjunctive/must.rb +48 -0
- data/lib/ae/subjunctive/should.rb +49 -0
- data/meta/authors +1 -0
- data/meta/contact +1 -0
- data/meta/created +1 -0
- data/meta/description +2 -0
- data/meta/homepage +1 -0
- data/meta/license +1 -0
- data/meta/package +1 -0
- data/meta/project +1 -0
- data/meta/released +1 -0
- data/meta/repository +1 -0
- data/meta/ruby +2 -0
- data/meta/summary +1 -0
- data/meta/title +1 -0
- data/meta/version +1 -0
- metadata +96 -0
data/MANIFEST
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!mast mast bin demo doc/qedoc lib meta test [A-Z]*
|
2
|
+
demo
|
3
|
+
demo/01_overview.rdoc
|
4
|
+
demo/02_assertion.rdoc
|
5
|
+
demo/03_assert.rdoc
|
6
|
+
demo/04_subjunctive.rdoc
|
7
|
+
doc/qedoc
|
8
|
+
doc/qedoc/index.html
|
9
|
+
doc/qedoc/jquery.js
|
10
|
+
lib
|
11
|
+
lib/ae
|
12
|
+
lib/ae/assert.rb
|
13
|
+
lib/ae/assertion.rb
|
14
|
+
lib/ae/assertor.rb
|
15
|
+
lib/ae/core_ext.rb
|
16
|
+
lib/ae/subjunctive
|
17
|
+
lib/ae/subjunctive/must.rb
|
18
|
+
lib/ae/subjunctive/should.rb
|
19
|
+
lib/ae/subjunctive.rb
|
20
|
+
lib/ae.rb
|
21
|
+
meta
|
22
|
+
meta/authors
|
23
|
+
meta/contact
|
24
|
+
meta/created
|
25
|
+
meta/description
|
26
|
+
meta/homepage
|
27
|
+
meta/license
|
28
|
+
meta/package
|
29
|
+
meta/project
|
30
|
+
meta/released
|
31
|
+
meta/repository
|
32
|
+
meta/ruby
|
33
|
+
meta/summary
|
34
|
+
meta/title
|
35
|
+
meta/version
|
36
|
+
test
|
37
|
+
LICENSE
|
38
|
+
README
|
39
|
+
HISTORY
|
data/README
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
= A.E. -- Assertive Expressive
|
2
|
+
|
3
|
+
* http://protuils.rubyforge.org/ae
|
4
|
+
|
5
|
+
|
6
|
+
== DESCRIPTION
|
7
|
+
|
8
|
+
Assertions Expressive (A.E.) is an assertions framework
|
9
|
+
intended for reuse by any TDD, BDD or similar system.
|
10
|
+
|
11
|
+
|
12
|
+
== FEATURES/ISSUES
|
13
|
+
|
14
|
+
* Clear, simple and concise syntax.
|
15
|
+
* Uses higher-order functions and fluid notation.
|
16
|
+
* Reusable core extensions ease assertion construction.
|
17
|
+
* Core extensions are stable and standardized via Ruby Facets.
|
18
|
+
* Facets is an optional dependency; extensions are built-in.
|
19
|
+
* Easily extensible allowing for alternate notations.
|
20
|
+
* Eats it's own dog food.
|
21
|
+
|
22
|
+
|
23
|
+
== RELEASE NOTES
|
24
|
+
|
25
|
+
Please see HISTORY file.
|
26
|
+
|
27
|
+
|
28
|
+
== SYNOPSIS
|
29
|
+
|
30
|
+
AE defines the method +assert+. It's is compatible with the method
|
31
|
+
as defined by Test::Unit and minitest, which verifies truth of a
|
32
|
+
single argument (and can accept an optional failure message).
|
33
|
+
|
34
|
+
assert(true)
|
35
|
+
|
36
|
+
In addition AE's +assert+ method has been extended to accept a block,
|
37
|
+
the result of which is likewise verified.
|
38
|
+
|
39
|
+
assert{true}
|
40
|
+
|
41
|
+
But these are simply legacy compatibility modes. The true power the
|
42
|
+
AE's +assert+ method, lies in it's use without argument or block.
|
43
|
+
In this case, it returns an +Assertor+ instance. An +Assertor+ is an
|
44
|
+
Assertion Functor, or Higher-Order Function, which is a function
|
45
|
+
that operates on another function. With it we can make assertions
|
46
|
+
like:
|
47
|
+
|
48
|
+
x.assert == y
|
49
|
+
|
50
|
+
a.assert.include? e
|
51
|
+
|
52
|
+
StandardError.assert.raised? do
|
53
|
+
...
|
54
|
+
end
|
55
|
+
|
56
|
+
And so forth. AE's abilities in this areas are quite extensive.
|
57
|
+
You are encouraged to read the QEDocs to learn more.
|
58
|
+
|
59
|
+
|
60
|
+
== HOW TO INSTALL
|
61
|
+
|
62
|
+
To install with RubyGems simply open a console and type:
|
63
|
+
|
64
|
+
gem install ae
|
65
|
+
|
66
|
+
Local installation requires Setup.rb (gem install setup),
|
67
|
+
then download the tarball package and type:
|
68
|
+
|
69
|
+
tar -xvzf ae-1.0.0.tgz
|
70
|
+
cd ae-1.0.0.tgz
|
71
|
+
sudo setup.rb all
|
72
|
+
|
73
|
+
Windows users use 'ruby setup.rb all'.
|
74
|
+
|
75
|
+
|
76
|
+
== COPYRIGHTS & LICENSE
|
77
|
+
|
78
|
+
Copyright (c) 2008,2009 Thomas Sawyer
|
79
|
+
|
80
|
+
Unless otherwise provided for by the originating author, this
|
81
|
+
program is distributed under the terms of the GPL v3 license.
|
82
|
+
|
83
|
+
See LICENSE file for details.
|
84
|
+
|
@@ -0,0 +1,97 @@
|
|
1
|
+
= Introduction
|
2
|
+
|
3
|
+
AE is an assertions framework for Ruby. It's designed
|
4
|
+
around the concept of an Assertor. The Assertor is an
|
5
|
+
Assertion Functor, or Higher-Order Function, which
|
6
|
+
reroutes method calls while monitoring them for failing
|
7
|
+
conditions.
|
8
|
+
|
9
|
+
|
10
|
+
== What's Provided
|
11
|
+
|
12
|
+
Requiring the AE library.
|
13
|
+
|
14
|
+
require 'ae'
|
15
|
+
|
16
|
+
Loads two classes, +Assertion+ and +Assertor+, the Kernel
|
17
|
+
method +assert+ and it's ancillaries +assert!+ and +refute+
|
18
|
+
and a set of core extensions that make writing certain types
|
19
|
+
of assertions easier.
|
20
|
+
|
21
|
+
|
22
|
+
== Assertion and Assertor Classes
|
23
|
+
|
24
|
+
The +Assertion+ class is a subclass of +Exception+. It is the
|
25
|
+
error raised when an assertion fails.
|
26
|
+
|
27
|
+
The +Assertion+ class is at the heart of AE. All other AE
|
28
|
+
method resolve by... The +Assertion+ class is at subclass
|
29
|
+
of Exception. When an assertion is made, and fails, it is
|
30
|
+
an instance of Assertion that is raised.
|
31
|
+
|
32
|
+
Assertion.assert.raised? do
|
33
|
+
msg = "my failure message"
|
34
|
+
assert false, msg
|
35
|
+
end
|
36
|
+
|
37
|
+
Like any raised exception, the last Assertion message is available
|
38
|
+
via +$!+.
|
39
|
+
|
40
|
+
(FYI, in Test::Unit the equivalent class was called AssertionFailureError.
|
41
|
+
AE has adopted the shortened term for my fingers sake ;) Also, recently
|
42
|
+
it was discoverd to be the choosen term in minitest --proving good ideas
|
43
|
+
find their way to the top.)
|
44
|
+
|
45
|
+
Assertions themsevles are not generally used in creating tests or
|
46
|
+
behavior specifications. Rather they are used to create additonal
|
47
|
+
types of assertion methods.
|
48
|
+
|
49
|
+
As mentioned above the +Assertor+ class is a type of Functor,
|
50
|
+
or Higher-Order function, which intercedes with a normal message
|
51
|
+
invocation to monitor for failed conditions, upon which is raises
|
52
|
+
Assertion exceptions.
|
53
|
+
|
54
|
+
|
55
|
+
== Assertion Methods
|
56
|
+
|
57
|
+
The three methods, +assert+, +assert!+ and +refute+ all return
|
58
|
+
an Assertor instance when used fluidly, i.e. magic-dot notation,
|
59
|
+
higher-order notation, functor notation, whatever you prefer
|
60
|
+
to call it.
|
61
|
+
|
62
|
+
assert(Assertor === assert)
|
63
|
+
|
64
|
+
This allows us to write statements like:
|
65
|
+
|
66
|
+
1.assert == 1
|
67
|
+
|
68
|
+
If the operation evaluates to false or nil, then an Assertion error
|
69
|
+
is raised.
|
70
|
+
|
71
|
+
Assertion.assert.raised? do
|
72
|
+
1.assert == 2
|
73
|
+
end
|
74
|
+
|
75
|
+
The methods +assert!+ and +refute+ are just like +assert+ expect
|
76
|
+
they purport the negative condition. Patterned after Ruby's own
|
77
|
+
use of +!+ as meaning +not+, +assert!+ should be read "assert not".
|
78
|
+
While +refute+ exists for the sake of those that find the use of
|
79
|
+
a "bang method" for this purpose unsuited to them.
|
80
|
+
|
81
|
+
|
82
|
+
== How It All Works
|
83
|
+
|
84
|
+
An Assertor essentially sits in wait for a method call (via
|
85
|
+
method_missing). When that happens it applies the method to
|
86
|
+
the original receiver, but wrapped in a clause that raises
|
87
|
+
an Assertion should the statement fail. If we wanted to
|
88
|
+
be pedantic, we could write our assertions like:
|
89
|
+
|
90
|
+
raise Assertion.new("1 != 1") unless 1 == 1
|
91
|
+
|
92
|
+
Instead of
|
93
|
+
|
94
|
+
1.assert == 1
|
95
|
+
|
96
|
+
Obviously using Assertor methods are whole lot more concise.
|
97
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/demo/03_assert.rdoc
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
= Assert Method
|
2
|
+
|
3
|
+
== Compatible with Test::Unit
|
4
|
+
|
5
|
+
The +#assert+ method is designed to be backward compatible
|
6
|
+
with the same method in +Test::Unit+.
|
7
|
+
|
8
|
+
Using an argument, #assert will check that an argument evaluates
|
9
|
+
to true. Optionally one can send along a meaningful message should
|
10
|
+
the assertion fail.
|
11
|
+
|
12
|
+
assert(true, "Not true!")
|
13
|
+
|
14
|
+
Assertion.assert.raised? do
|
15
|
+
assert(false, "Not true!")
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
== Assert with a Block
|
20
|
+
|
21
|
+
In addition #assert has been extended to accept a block. Like the case of the
|
22
|
+
argument, the block is expected to return something that evaluates as true.
|
23
|
+
|
24
|
+
assert do
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
Assertion.assert.raised? do
|
29
|
+
assert do
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
We should also mention that, while probably not very useful, since
|
35
|
+
the arity of a block can be checked, one can also pass the receiver
|
36
|
+
into the block as a block argument.
|
37
|
+
|
38
|
+
"hi".assert do |s|
|
39
|
+
/h/ =~ s
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
== Antonyms for Assert
|
44
|
+
|
45
|
+
We can state the opposite assertion using #assert!
|
46
|
+
|
47
|
+
10.assert! == 9
|
48
|
+
|
49
|
+
Or, because some people do not like the use of a bang method, +#refute+.
|
50
|
+
|
51
|
+
10.refute == 9
|
52
|
+
|
53
|
+
These terms can be used just as #assert is used in all examples,
|
54
|
+
but with the opposite inference.
|
55
|
+
|
56
|
+
Another way to get the opposite inference, is to use #not.
|
57
|
+
|
58
|
+
10.assert.not == 9
|
59
|
+
|
60
|
+
|
61
|
+
== Identity Assertions
|
62
|
+
|
63
|
+
Rather then the general form:
|
64
|
+
|
65
|
+
x = 10
|
66
|
+
x.assert.object_id == x.object_id
|
67
|
+
|
68
|
+
We can use Ruby's own +equal?+ method.
|
69
|
+
|
70
|
+
x.assert.equal?(x)
|
71
|
+
|
72
|
+
AE provides +identical?+ method as an alternative
|
73
|
+
to make it a bit more clear.
|
74
|
+
|
75
|
+
x.assert.identical?(x)
|
76
|
+
|
77
|
+
|
78
|
+
== Equality Assertions
|
79
|
+
|
80
|
+
The most common assertion is that of value equality (+==_),
|
81
|
+
as we have seen throughout this document. But other forms of
|
82
|
+
equality can be verified as easily. We have already mentioned
|
83
|
+
identity. In addition there is *Type Equality*.
|
84
|
+
|
85
|
+
17.assert.eql? 17
|
86
|
+
|
87
|
+
Assertion.assert.raised? do
|
88
|
+
17.assert.eql? 17.0
|
89
|
+
end
|
90
|
+
|
91
|
+
And there is *Case Equality*.
|
92
|
+
|
93
|
+
Numeric.assert === 3
|
94
|
+
|
95
|
+
|
96
|
+
== Checking Equality with a Block
|
97
|
+
|
98
|
+
Because operators can not take blocks, and at times blocks can
|
99
|
+
be convenient means of supplying a value to an assertion,
|
100
|
+
AE has defined alternate renditions of the equality methods.
|
101
|
+
For equal? and eql?, the method name remains the same, they simply
|
102
|
+
can take a block instead of argument if need be.
|
103
|
+
|
104
|
+
For *Value Equality*, +==+, the method is called +eq?+.
|
105
|
+
|
106
|
+
10.assert.eq? do
|
107
|
+
10.0
|
108
|
+
end
|
109
|
+
|
110
|
+
And should it fail...
|
111
|
+
|
112
|
+
Assertion.assert.raised? do
|
113
|
+
10.assert.eq? do
|
114
|
+
20
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
For *Case Equality, +===+, it is +case?+.
|
119
|
+
|
120
|
+
Numeric.assert.case? do
|
121
|
+
"3".to_i
|
122
|
+
end
|
123
|
+
|
124
|
+
Assertion.assert.raised? do
|
125
|
+
Numeric.assert.case? do
|
126
|
+
"3"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
== Exception Assertions
|
132
|
+
|
133
|
+
Validating errors is easy too, as has already been shown
|
134
|
+
in the document to verify assertion failures.
|
135
|
+
|
136
|
+
StandardError.assert.raised? do
|
137
|
+
unknown_method
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
== Assertions on Object State
|
142
|
+
|
143
|
+
While testing or specifying the internal state of an object is
|
144
|
+
generally considered poor form, there are times when it is
|
145
|
+
necessay. Assert combined with +instance_eval+ makes it easy too.
|
146
|
+
|
147
|
+
class X
|
148
|
+
attr :a
|
149
|
+
def initialize(a); @a = a; end
|
150
|
+
end
|
151
|
+
|
152
|
+
x = X.new(1)
|
153
|
+
|
154
|
+
x.assert.instance_eval do
|
155
|
+
@a == 1
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
== Catch/Try Assertions
|
160
|
+
|
161
|
+
Catch/Try throws can be tested via +Symbol#thrown?+.
|
162
|
+
|
163
|
+
:hookme.assert.thrown? do
|
164
|
+
throw :hookme
|
165
|
+
end
|
166
|
+
|
167
|
+
Alternatively, a lambda containing the potential throw
|
168
|
+
can be the receiver using +throws?+.
|
169
|
+
|
170
|
+
hook = lambda{ throw :hookme }
|
171
|
+
|
172
|
+
hook.assert.throws?(:hookme)
|
173
|
+
|
174
|
+
|
175
|
+
== Assertions on Proc Changes
|
176
|
+
|
177
|
+
I have to admit I'm not sure how this is useful,
|
178
|
+
but I found it in the Bacon API and ported it over
|
179
|
+
just for sake of thoroughness.
|
180
|
+
|
181
|
+
a = 0
|
182
|
+
|
183
|
+
l = lambda{ a }
|
184
|
+
|
185
|
+
l.assert.change?{ a +=1 }
|
186
|
+
|
187
|
+
|
188
|
+
== Assertion on literal True, False and Nil
|
189
|
+
|
190
|
+
Ruby already provides the #nil? method.
|
191
|
+
|
192
|
+
nil.assert.nil?
|
193
|
+
|
194
|
+
AE add true? and false? which acts accordingly.
|
195
|
+
|
196
|
+
true.assert.true?
|
197
|
+
false.assert.false?
|
198
|
+
|
199
|
+
|
200
|
+
== Send Assertions
|
201
|
+
|
202
|
+
Assert that a method can be successfully called.
|
203
|
+
|
204
|
+
"STRING".assert.send?(:upcase)
|
205
|
+
|
206
|
+
|
207
|
+
== Numeric Delta and Epsilon
|
208
|
+
|
209
|
+
You may wish to assert that a numeric value is with some
|
210
|
+
range.
|
211
|
+
|
212
|
+
3.in_delta?(1,5)
|
213
|
+
|
214
|
+
Or minimum range.
|
215
|
+
|
216
|
+
3.in_epsilon?(3,5)
|
217
|
+
|
218
|
+
|
219
|
+
== Custom Lambda Assertions
|
220
|
+
|
221
|
+
Passing a lambda to the subjunctive method, will use it as if it were
|
222
|
+
a block of the method. This allows for a simple way to quickly
|
223
|
+
create reusable assertions.
|
224
|
+
|
225
|
+
palindrome = lambda{ |x| x == x.reverse }
|
226
|
+
|
227
|
+
"abracarba".assert palindrome
|
228
|
+
|
229
|
+
QED.
|
230
|
+
|