ae 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ module AE
9
9
  #
10
10
  # An Assertor is an Assertion Functor. A Functor is a succinct name for what
11
11
  # is also known as Higher Order Function. In other words, it is a function
12
- # that acts on a function. It is very similiar to a delegator in most
12
+ # that acts on a function. It is very similiar to a delegator in most
13
13
  # respects, but is conditioned on the operation applied, rather then simply
14
14
  # passing-off to an alternate reciever.
15
15
  #
@@ -19,11 +19,11 @@ module AE
19
19
  ZERO_COUNTS = {:total=>0,:pass=>0,:fail=>0}
20
20
 
21
21
  # Initialize assertion counts global variable.
22
- $assertion_counts = ZERO_COUNTS.dup
22
+ $ASSERTION_COUNTS = ZERO_COUNTS.dup
23
23
 
24
24
  # Returns Hash used to track assertion counts.
25
25
  def self.counts
26
- $assertion_counts
26
+ $ASSERTION_COUNTS
27
27
  end
28
28
 
29
29
  # Reset assertion counts.
@@ -335,6 +335,18 @@ module AE
335
335
  __assert__(test, msg)
336
336
  end
337
337
 
338
+ # Assert that an Array, or any other object the responds to #include?
339
+ # thus contains the given element.
340
+ #
341
+ # @raise [Assertion] if test fails
342
+ #
343
+ # @return nothing
344
+ def assert_includes(elem, array, msg=nil)
345
+ test = array.include?(elem)
346
+ msg = "Expected #{elem.inspect} is not found in #{array.inspect}" unless msg
347
+ __assert__(test, msg)
348
+ end
349
+
338
350
  # Flunk always fails.
339
351
  #
340
352
  # @example
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.8.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-04 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ansi
16
- requirement: &31611960 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *31611960
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: detroit
27
- requirement: &31611420 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *31611420
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: qed
38
- requirement: &31610920 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *31610920
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: ! "Assertive Expressive is an assertions library specifically designed
48
63
  \nfor reuse by other test frameworks."
49
64
  email:
@@ -51,10 +66,10 @@ email:
51
66
  executables: []
52
67
  extensions: []
53
68
  extra_rdoc_files:
54
- - HISTORY.rdoc
55
- - README.rdoc
56
- - QED.rdoc
57
- - NOTICE.rdoc
69
+ - DEMO.rdoc
70
+ - HISTORY.md
71
+ - README.md
72
+ - NOTICE.md
58
73
  files:
59
74
  - .ruby
60
75
  - .yardopts
@@ -80,18 +95,10 @@ files:
80
95
  - lib/ae/version.rb
81
96
  - lib/ae.rb
82
97
  - lib/ae.yml
83
- - qed/01_overview.rdoc
84
- - qed/02_assertion.rdoc
85
- - qed/03_assert.rdoc
86
- - qed/04_subjunctive.rdoc
87
- - qed/05_expect.rdoc
88
- - qed/06_counts.rdoc
89
- - qed/07_matchers.rdoc
90
- - qed/08_check.rdoc
91
- - HISTORY.rdoc
92
- - README.rdoc
93
- - QED.rdoc
94
- - NOTICE.rdoc
98
+ - DEMO.rdoc
99
+ - HISTORY.md
100
+ - README.md
101
+ - NOTICE.md
95
102
  homepage: http://rubyworks.github.com/ae
96
103
  licenses:
97
104
  - BSD-2-Clause
@@ -113,8 +120,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
120
  version: '0'
114
121
  requirements: []
115
122
  rubyforge_project:
116
- rubygems_version: 1.8.10
123
+ rubygems_version: 1.8.24
117
124
  signing_key:
118
125
  specification_version: 3
119
126
  summary: Assertive Expressive
120
127
  test_files: []
128
+ has_rdoc:
@@ -1,92 +0,0 @@
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 AE Provides
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 antonyms +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 at the heart of AE. All other AE
25
- methods depend on it. The +Assertion+ class is a subclass
26
- of Exception. When an assertion is made and fails, it is
27
- an instance of Assertion that is raised.
28
-
29
- expect Assertion do
30
- msg = "my failure message"
31
- assert false, msg
32
- end
33
-
34
- Like any raised exception, the last Assertion message is available
35
- via <tt>$!</tt>.
36
-
37
- (FYI, in Test::Unit the equivalent class was called +AssertionFailedError+.)
38
-
39
- Assertions themselves are not generally used in creating tests or
40
- behavior specifications. Rather they are used to create additional
41
- types of assertion methods.
42
-
43
- As mentioned above the +Assertor+ class is a type of Higher-Order
44
- function, or Functor, which intercedes with a normal message
45
- invocation to monitor for failed conditions, upon which is raises
46
- Assertion exceptions.
47
-
48
-
49
- == Assertion Methods
50
-
51
- The three methods, +assert+, <tt>assert!</tt> and +refute+ all
52
- return an Assertor instance when used fluidly, i.e. magic-dot
53
- notation, higher-order notation, functor notation, whatever you
54
- prefer to call it.
55
-
56
- assert(AE::Assertor === assert)
57
-
58
- Through the use of +method_missing+, the Assertor allows us to write
59
- statements like:
60
-
61
- 1.assert == 1
62
-
63
- If the operation evaluates to false or nil, then an Assertion error
64
- is raised.
65
-
66
- expect Assertion do
67
- 1.assert == 2
68
- end
69
-
70
- The methods <tt>assert!</tt> and +refute+ are just like +assert+
71
- expect they purport the negative condition. Patterned after Ruby's
72
- own use of "<tt>!</tt>" as meaning +not+, <tt>assert!</tt> should be
73
- read "assert not". While +refute+ exists for the sake of those who
74
- find the use of a bang method for this purpose unsuited to them.
75
-
76
-
77
- == How It Works
78
-
79
- An Assertor essentially sits in wait for a method call (via
80
- method_missing). When that happens it applies the method to the
81
- original receiver, but wrapped in a clause that raises an
82
- Assertion should the statement fail. If we wanted to be
83
- pedantic, we could write our assertions like:
84
-
85
- raise Assertion.new("1 != 1") unless 1 == 1
86
-
87
- Instead of
88
-
89
- 1.assert == 1
90
-
91
- Obviously using Assertor methods are whole lot more concise.
92
-
@@ -1,4 +0,0 @@
1
- = Assertion Class
2
-
3
- The Assertion class is a subclass of Exception and is the error raised when
4
- and assertion fails.
@@ -1,298 +0,0 @@
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 <tt>Test::Unit</tt>.
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
- expect Assertion 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 <tt>assert!</tt>.
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
- == Lambda Assertions
61
-
62
- Passing +assert+ a `Proc` object, or any object that responds to `#call`,
63
- will be used as if it were a block. This allows for a simple way to quickly
64
- create reusable assertions.
65
-
66
- palindrome = lambda{ |word| word == word.reverse }
67
-
68
- "abracarba".assert palindrome
69
-
70
- The message for a failed assertion will come from calling `#to_s` on the
71
- object.
72
-
73
- == RSpec-style Assertion Matchers
74
-
75
- If an object passed to assert responds to `#matches?` then AE will handle
76
- the object as an RSpec-style mather, the receiver will be passed to the
77
- `#matches?` method to determine if the assertion passes and RSpec matcher
78
- message methods will be used if they are defined.
79
-
80
- palindrome = Object.new
81
-
82
- def palindrome.matches?(word)
83
- word == word.reverse
84
- end
85
-
86
- "abracarba".assert palindrome
87
-
88
-
89
- == Identity Assertions
90
-
91
- Rather then the general form.
92
-
93
- x = 10
94
- x.assert.object_id == x.object_id
95
-
96
- We can use Ruby's own <tt>equal?</tt> method.
97
-
98
- x.assert.equal?(x)
99
-
100
- AE provides <tt>identical?</tt> method as an alternative
101
- to make it a bit more clear.
102
-
103
- x.assert.identical?(x)
104
-
105
-
106
- == Equality Assertions
107
-
108
- The most common assertion is that of value equality (<tt>==</tt>),
109
- as we have seen throughout this document. But other forms of
110
- equality can be verified as easily. We have already mentioned
111
- identity. In addition there is <i>type equality</i>.
112
-
113
- 17.assert.eql? 17
114
-
115
- Assertion.assert.raised? do
116
- 17.assert.eql? 17.0
117
- end
118
-
119
- And there is <i>case equality</i>.
120
-
121
- Numeric.assert === 3
122
-
123
-
124
- == Checking Equality with a Block
125
-
126
- Because operators can not take blocks, and at times blocks can
127
- be convenient means of supplying a value to an assertion,
128
- AE has defined alternate renditions of the equality methods.
129
- For equal? and eql?, the method names are the same, they simply
130
- can take a block in place of an argument if need be.
131
-
132
- For <i>value equality</i> (<tt>==</tt>), the method is called <tt>eq?</tt>.
133
-
134
- 10.assert.eq? do
135
- 10.0
136
- end
137
-
138
- And should it fail...
139
-
140
- Assertion.assert.raised? do
141
- 10.assert.eq? do
142
- 20
143
- end
144
- end
145
-
146
- == Case Equality
147
-
148
- For <i>case equality</i> (<tt>===</tt>), it is <tt>case?</tt>.
149
-
150
- Numeric.assert.case? do
151
- "3".to_i
152
- end
153
-
154
- Assertion.assert.raised? do
155
- Numeric.assert.case? do
156
- "3"
157
- end
158
- end
159
-
160
-
161
- == Regular Expressions
162
-
163
- Regular Expressions can be used to make assertions in much the same way as equality.
164
-
165
- /i/.assert =~ "i"
166
-
167
- Assertion.assert.raised? do
168
- /i/.assert =~ "g"
169
- end
170
-
171
- Conversely the String class recognizes the #=~ method as well.
172
-
173
- "i".assert =~ /i/
174
-
175
- Assertion.assert.raised? do
176
- "i".assert =~ /g/
177
- end
178
-
179
-
180
- == Exception Assertions
181
-
182
- Validating errors is easy too, as has already been shown
183
- in the document to verify assertion failures.
184
-
185
- StandardError.assert.raised? do
186
- unknown_method
187
- end
188
-
189
-
190
- == Assertions on Object State
191
-
192
- While testing or specifying the internal state of an object is
193
- generally considered poor form, there are times when it is
194
- necessary. Assert combined with +instance_eval+ makes it easy too.
195
-
196
- class X
197
- attr :a
198
- def initialize(a); @a = a; end
199
- end
200
-
201
- x = X.new(1)
202
-
203
- x.assert.instance_eval do
204
- @a == 1
205
- end
206
-
207
-
208
- == Catch/Try Assertions
209
-
210
- Catch/Try throws can be tested via <tt>Symbol#thrown?</tt>.
211
-
212
- :hookme.assert.thrown? do
213
- throw :hookme
214
- end
215
-
216
- Alternatively, a lambda containing the potential throw
217
- can be the receiver using <tt>throws?</tt>.
218
-
219
- hook = lambda{ throw :hookme }
220
-
221
- hook.assert.throws?(:hookme)
222
-
223
-
224
- == Assertions on Proc Changes
225
-
226
- I have to admit I'm not sure how this is useful,
227
- but I found it in the Bacon API and ported it over
228
- just for sake of thoroughness.
229
-
230
- a = 0
231
-
232
- l = lambda{ a }
233
-
234
- l.assert.change?{ a +=1 }
235
-
236
-
237
- == Assertion on literal True, False and Nil
238
-
239
- Ruby already provides the #nil? method.
240
-
241
- nil.assert.nil?
242
-
243
- AE adds <tt>true?</tt> and <tt>false?</tt> which acts accordingly.
244
-
245
- true.assert.true?
246
- false.assert.false?
247
-
248
-
249
- == Send Assertions
250
-
251
- Assert that a method can be successfully called.
252
-
253
- "STRING".assert.send?(:upcase)
254
-
255
-
256
- == Numeric Delta and Epsilon
257
-
258
- You may wish to assert that a numeric value is with some
259
- range.
260
-
261
- 3.in_delta?(1,5)
262
-
263
- Or minimum range.
264
-
265
- 3.in_epsilon?(3,5)
266
-
267
-
268
- == Verifying Object State
269
-
270
- Not surprisingly if underlying object state needs to be verified, +instance_eval+
271
- can be used in conjunction with +assert+.
272
-
273
- class X
274
- attr :a
275
- def initialize(a); @a = a; end
276
- end
277
-
278
- x = X.new(4)
279
-
280
- x.instance_eval do
281
- @a.assert == 4
282
- end
283
-
284
- However #instance_eval is a reserved method for the underlying Assertor class,
285
- so it cannot be used on #assert, e.g.
286
-
287
- x.assert.instance_eval do
288
- @a == "obvisouly wrong"
289
- end
290
-
291
- AE offers an optional helper method for times when testing underlying private
292
- or protected methods is important, called #pry. See the QED on pry for more
293
- information.
294
-
295
- For some testing underlying implementation might be considered poor
296
- form. You will get no argument here. It should be used thoughtfully,
297
- but I would not bet against there being occasions when such validations
298
- might be needed.