ae 1.8.1 → 1.8.2

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.
@@ -1,100 +0,0 @@
1
- = Subjunctives
2
-
3
- Okay. I can hear the BDDers rumbling, "where's the *should?*"
4
- AE has nothing against "should", but there are different
5
- approaches for utilizing should nomenclature in specifications,
6
- and AE wants to be open to these techniques. One of which
7
- is how Shoulda (http://shoulda.rubyforge.org) utilizes
8
- +should+ in a way analogous to RSpec's use of +it+.
9
-
10
- Even so, AE provides an optional mixin called +Subjunctive+ which
11
- can be used to create assertor methods with English subjunctive
12
- terms, such as +should+, or +must+, +shall+ and +will+.
13
- To load this library use:
14
-
15
- require 'ae/subjunctive'
16
-
17
- Then all that is required it to define a subjunctive method for all
18
- objects. For example:
19
-
20
- def will(*args, &block)
21
- Assertor.new(self, :backtrace=>caller).be(*args,&block)
22
- end
23
-
24
- It's that easy. Because of their commonality AE provides two such terms,
25
- +should+ and +must+ as optional add-ons out-of-the-box.
26
-
27
- require 'ae/should'
28
- require 'ae/must'
29
-
30
- We will use these two methods interchangeable for the rest of this
31
- demonstration, but to be clear they both work exactly the same way,
32
- and almost exactly like +assert+.
33
-
34
- Keep in mind, AE "conical" functionality does not entail the subjunctive
35
- forms. These are simply options you can load via your <tt>test_helper.rb</tt>,
36
- or similar script, if you prefer these nomenclatures.
37
-
38
-
39
- == Fluent Notation and Antonyms
40
-
41
- Like +assert+, +should+ and +must+ can be used as higher order functions.
42
-
43
- 4.should == 4
44
- 4.must == 4
45
-
46
- Antonyms provided for +should+ as <tt>should!</tt> (read "should not") and +shouldnt+.
47
- For +must+ +must+, they are <tt>must!</tt> and +wont+.
48
-
49
- 4.should! == 5
50
- 4.shouldnt == 5
51
-
52
- 4.must! == 5
53
- 4.wont == 5
54
-
55
-
56
- == To Be
57
-
58
- On occasions where the English readability of a specification is hindered,
59
- +be+ can be used.
60
-
61
- StandardError.must.be.raised? do
62
- unknown_method
63
- end
64
-
65
- The +be+ method is the same as +assert+ with the single exception
66
- that it will compare a lone argument to the receiver using +equate?+,
67
- unlike +assert+ which simply checks to see that the argument evaluates
68
- as true.
69
-
70
- 10.should.be 10
71
- 10.should.be 10.0
72
- 10.should.be Numeric
73
-
74
- Assertion.assert.raised? do
75
- 10.should.be "40"
76
- end
77
-
78
-
79
- == Indefinite Articles
80
-
81
- Additional English forms are +a+ and +an+, equivalent to +be+ except
82
- that they use <tt>case?</tt> (same as <tt>#===</tt>) instead of
83
- <tt>equate?</tt> when acting on a single argument.
84
-
85
- "hi".must.be.a String
86
-
87
- Assertion.assert.raised? do
88
- /x/.must.be.a /x/
89
- end
90
-
91
- Otherwise they are interchangeable.
92
-
93
- "hi".must.be.an.instance_of?(String)
94
-
95
- The indefinite articles work well when a noun follows as an arguments.
96
-
97
- palindrome = lambda{ |x| x == x.reverse }
98
-
99
- "abracarba".must.be.a palindrome
100
-
@@ -1,104 +0,0 @@
1
- = Expect Method
2
-
3
- Expect is another assertion nomenclature available for use in your
4
- tests or specifications. Inspired by Jay Fields' Expectations library,
5
- it provides convenient syntax for creating exception and case equality
6
- assertions.
7
-
8
- require 'ae/expect'
9
-
10
-
11
- == Underlying Comparison
12
-
13
- Expect uses #=== for comparison. So providing an argument and a block to
14
- #expect we can test for a somewhat broader range of compassion than #assert.
15
- For example we can test for a subclass.
16
-
17
- expect Numeric do
18
- 3
19
- end
20
-
21
- Assertion.assert.raised? do
22
- expect Numeric do
23
- "3"
24
- end
25
- end
26
-
27
-
28
- == Exception Expectation
29
-
30
- If the comparator is an Exception class or a instance of an Exception class,
31
- then #expect will check to see if the block raises that kind of exception.
32
-
33
- expect StandardError do
34
- some_undefined_method
35
- end
36
-
37
- expect Assertion do
38
- expect(nil)
39
- end
40
-
41
- This is an important distinction to note because it means #expect can not be used
42
- if verify instances of Exception classes.
43
-
44
- Assertion.assert.raised? do
45
- expect Exception do
46
- Exception.new
47
- end
48
- end
49
-
50
-
51
- == Regex Expectations
52
-
53
- That #expect entails #=== also means we can check for Regexp matches.
54
-
55
- expect /x/ do
56
- "oooxooo"
57
- end
58
-
59
-
60
- == Expected Method
61
-
62
- We can use #expected to make the receiver the object of expectation.
63
-
64
- x = "dummy"
65
-
66
- /x/.expected do
67
- "x"
68
- end
69
-
70
-
71
- == Without Block
72
-
73
- Without a block, the receiver is compared to the argument.
74
-
75
- x.expect String
76
-
77
-
78
- == Negative Forms
79
-
80
- Like #assert, #expect has a negated form called #expect!
81
-
82
- expect! /x/ do
83
- "o"
84
- end
85
-
86
- The pure word form for those who do not like the clever use of the
87
- explimation mark is #forbid.
88
-
89
- forbid /x/ do
90
- "o"
91
- end
92
-
93
-
94
- == Functor, or Higher Order Function
95
-
96
- Like #assert, #expect can be used used as a *fluid* notation.
97
-
98
- 10.expect == 10
99
-
100
- In which case it works just like #assert, including negative forms.
101
-
102
- 10.expect! == 11
103
- 10.forbid == 11
104
-
@@ -1,33 +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
- old_counts = AE::Assertor.recount
7
-
8
- For example if we have one assertion pass and another fail.
9
-
10
- assert(true)
11
-
12
- expect Assertion do
13
- assert(false)
14
- end
15
-
16
- We will see that AE counted three assertions and one failure.
17
-
18
- counts = AE::Assertor.counts.dup
19
-
20
- counts[:total].assert == 3
21
- counts[:pass].assert == 2
22
- counts[:fail].assert == 1
23
-
24
- The #expect call is an assertion too, which is why the total count is 3
25
- rather than 2.
26
-
27
- Now that we are done checking counts we will restore them so that
28
- any other demos being run with this will tally correctly.
29
-
30
- AE::Assertor.recount(old_counts)
31
- AE::Assertor.counts[:total] += 3
32
- AE::Assertor.counts[:pass] += 3
33
-
@@ -1,34 +0,0 @@
1
- = Matchers
2
-
3
- Matchers are simply Procs or objects with the proper interface that can be
4
- passed to #assert or #refute (or other Assertor) as an ecapsulated test.
5
-
6
- == Proc or #to_proc
7
-
8
- Passing a Proc object or an object that responds to :to_proc, will use it
9
- as if it were a block of the method. This allows for a simple way to quickly
10
- create reusable assertions.
11
-
12
- palindrome = lambda{ |word| word == word.reverse }
13
-
14
- "abracarba".assert palindrome
15
-
16
- == #matches?
17
-
18
- Additionally if an object responds to #matches? then the receiver
19
- will be passed to this method to determine if the assertion passes.
20
-
21
- palindrome = Object.new
22
-
23
- def palindrome.matches?(word)
24
- word == word.reverse
25
- end
26
-
27
- "abracarba".assert palindrome
28
-
29
- == RSpec, Shoulda and other 3rd-Party Matchers
30
-
31
- With tha addition of #matches?, AE supports the same interface for matchers
32
- as RSpec. Any matcher library designed for use with RSpec should therefore
33
- be usable with AE as well. This includes RSpecs own matchers and Shoulda's
34
- excellent Rails matchers.
@@ -1,63 +0,0 @@
1
- == Check Ok/No
2
-
3
- The Check library is an optional library that can be used
4
- to conveniently speed-up construction of reptitive assertions.
5
-
6
- To use it, first require the library, then include the mixin
7
- into the namespace in which you will utilize it.
8
-
9
- require 'ae/check'
10
-
11
- include AE::Check
12
-
13
- Now we can define ok/no check procedures. A one-off procedure is
14
- defined with a block only.
15
-
16
- check do |x, y|
17
- x == y
18
- end
19
-
20
- ok 1,1
21
-
22
- no 1,2
23
-
24
- To define reusable check procedures, give the procedure a name.
25
-
26
- check :palindrome do |x|
27
- x.reverse == x
28
- end
29
-
30
- This will also cause the current check method to be set.
31
- Later in the code, the check procedure can be reset to this
32
- by just passing the name.
33
-
34
- check :palindrome
35
-
36
- ok 'abracarba'
37
-
38
- no 'foolishness'
39
-
40
- The Check mixin comes preloaded with a few standard checks.
41
- By default the `:equality` procedure is used.
42
-
43
- check :equality
44
-
45
- ok 1=>1.0
46
-
47
- Notice the use of the hash argument here. This is a useful construct for
48
- many check procedures becuase it it akin to the `#=>` pattern we often
49
- see in code examples and it also allows for multiple assertions in one call.
50
- For instance, in the case of `:equality`, multiple entries convey a
51
- meaning of logical-or.
52
-
53
- ok 1=>2, 1=>1
54
-
55
- This would pass becuase the second assertion of equality is true.
56
-
57
- Another built in check is `:case_equality` which uses `#===` instead of `#==`
58
- to make the comparison.
59
-
60
- check :case_equality
61
-
62
- ok 1=>Integer
63
-