assay 0.4.1 → 0.5.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.
- checksums.yaml +7 -0
- data/.yardopts +7 -0
- data/HISTORY.md +128 -0
- data/LICENSE.txt +22 -0
- data/README.md +287 -0
- data/demo/ae/01_overview.md +98 -0
- data/demo/ae/03_assert.md +398 -0
- data/demo/ae/04_subjunctive.md +100 -0
- data/demo/ae/05_expect.md +136 -0
- data/demo/ae/06_counts.md +33 -0
- data/demo/ae/07_matchers.md +34 -0
- data/demo/ae/08_check.md +61 -0
- data/demo/ae/09_assay.md +124 -0
- data/demo/ae/applique/setup.rb +11 -0
- data/{test → demo/applique}/helper.rb +8 -2
- data/demo/applique/setup.rb +1 -0
- data/demo/bang/01_bang.md +220 -0
- data/demo/core/00_introduction.md +2 -0
- data/demo/core/01_assay_classes/00_introduction.md +2 -0
- data/demo/core/01_assay_classes/01_nil_assay.md +35 -0
- data/demo/core/01_assay_classes/02_boolean_assay.md +35 -0
- data/demo/core/01_assay_classes/03_false_assay.md +19 -0
- data/demo/core/01_assay_classes/03_true_assay.md +20 -0
- data/demo/core/01_assay_classes/04_like_assay.md +19 -0
- data/demo/core/01_assay_classes/05_equal_assay.md +19 -0
- data/demo/core/01_assay_classes/06_unequal_assay.md +35 -0
- data/demo/core/01_assay_classes/07_equality_assay.md +19 -0
- data/demo/core/01_assay_classes/08_identity_assay.md +24 -0
- data/demo/core/01_assay_classes/09_case_assay.md +22 -0
- data/demo/core/01_assay_classes/10_match_assay.md +15 -0
- data/demo/core/01_assay_classes/11_nomatch_assay.md +16 -0
- data/demo/core/01_assay_classes/12_compare_assay.md +24 -0
- data/demo/core/01_assay_classes/13_less_assay.md +29 -0
- data/demo/core/01_assay_classes/14_more_assay.md +29 -0
- data/demo/core/01_assay_classes/15_less_equal_assay.md +30 -0
- data/demo/core/01_assay_classes/16_more_equal_assay.md +29 -0
- data/demo/core/01_assay_classes/17_close_assay.md +42 -0
- data/demo/core/01_assay_classes/17_within_assay.md +42 -0
- data/demo/core/01_assay_classes/18_kind_assay.md +17 -0
- data/demo/core/01_assay_classes/19_instance_assay.md +16 -0
- data/demo/core/01_assay_classes/20_include_assay.md +17 -0
- data/demo/core/01_assay_classes/21_empty_assay.md +15 -0
- data/demo/core/01_assay_classes/22_respond_assay.md +15 -0
- data/demo/core/01_assay_classes/23_execution_assay.md +40 -0
- data/demo/core/01_assay_classes/23_return_assay.md +37 -0
- data/demo/core/01_assay_classes/24_rescue_assay.md +40 -0
- data/demo/core/01_assay_classes/25_raise_assay.md +40 -0
- data/demo/core/01_assay_classes/26_throw_assay.md +47 -0
- data/demo/core/01_assay_classes/27_path_assay.md +20 -0
- data/demo/core/01_assay_classes/28_directory_assay.md +21 -0
- data/demo/core/01_assay_classes/29_file_assay.md +20 -0
- data/demo/core/01_assay_classes/30_output_assay.md +39 -0
- data/demo/core/01_assay_classes/31_stdout_assay.md +21 -0
- data/demo/core/01_assay_classes/32_stderr_assay.md +21 -0
- data/demo/core/02_lookup.md +25 -0
- data/demo/core/03_assertor.md +117 -0
- data/demo/core/04_assay.md +40 -0
- data/demo/fluidity/00_intro.md +7 -0
- data/demo/fluidity/01_should.md +52 -0
- data/demo/fluidity/02_must.md +58 -0
- data/demo/fluidity/03_assert.md +71 -0
- data/demo/fluidity/04_other.md +35 -0
- data/demo/fluidity/05_object_methods.md +102 -0
- data/demo/minitest/01_minitest_extensions.rdoc +217 -0
- data/demo/minitest/02_minitest_assertions.rdoc +250 -0
- data/demo/rspec/00_introduction.md +16 -0
- data/demo/rspec/01_should.md +24 -0
- data/demo/rspec/02_matchers.md +176 -0
- data/demo/rspec/03_have.md +51 -0
- data/demo/rspec/04_expect.md +49 -0
- data/demo/rspec/applique/setup.rb +2 -0
- data/demo/testunit/01_testunit_assertions.md +266 -0
- data/lib/assay/adapter/minitest.rb +32 -21
- data/lib/assay/adapter/testunit.rb +31 -38
- data/lib/assay/ae/assert.rb +77 -0
- data/lib/assay/ae/assertor.rb +453 -0
- data/lib/assay/ae/check.rb +154 -0
- data/lib/assay/ae/core_ext.rb +146 -0
- data/lib/assay/ae/expect.rb +72 -0
- data/lib/assay/ae/must.rb +64 -0
- data/lib/assay/ae/should.rb +58 -0
- data/lib/assay/ae/subjunctive.rb +66 -0
- data/lib/assay/ae.rb +29 -0
- data/lib/assay/assertable.rb +21 -5
- data/lib/assay/assertor.rb +4 -4
- data/lib/assay/bang.rb +147 -0
- data/lib/assay/close_assay.rb +2 -2
- data/lib/assay/core_ext/kernel.rb +4 -8
- data/lib/assay/fluidity/assert.rb +27 -0
- data/lib/assay/fluidity/grammar.rb +157 -0
- data/lib/assay/fluidity/is.rb +18 -0
- data/lib/assay/fluidity/must.rb +38 -0
- data/lib/assay/fluidity/should.rb +32 -0
- data/lib/assay/fluidity/will.rb +36 -0
- data/lib/assay/fluidity.rb +6 -0
- data/lib/assay/less_assay.rb +7 -1
- data/lib/assay/less_equal_assay.rb +7 -1
- data/lib/assay/minitest/assertions.rb +495 -0
- data/lib/assay/minitest/extensions.rb +496 -0
- data/lib/assay/minitest.rb +24 -0
- data/lib/assay/more_assay.rb +7 -1
- data/lib/assay/more_equal_assay.rb +7 -1
- data/lib/assay/rspec/expect.rb +151 -0
- data/lib/assay/rspec/have.rb +201 -0
- data/lib/assay/rspec/matchers.rb +272 -0
- data/lib/assay/rspec/operatics.rb +60 -0
- data/lib/assay/rspec/should.rb +49 -0
- data/lib/assay/rspec.rb +13 -0
- data/lib/assay/testunit/assertions.rb +484 -0
- data/lib/assay/testunit.rb +9 -0
- data/lib/assay/version.rb +3 -0
- data/lib/assay.rb +7 -21
- metadata +211 -80
- data/.ruby +0 -51
- data/COPYING.rdoc +0 -38
- data/HISTORY.rdoc +0 -65
- data/QED.rdoc +0 -1143
- data/README.rdoc +0 -173
- data/lib/assay.yml +0 -51
- data/test/case_compare_assay.rb +0 -59
- data/test/case_empty_assay.rb +0 -51
- data/test/case_equal_assay.rb +0 -53
- data/test/case_equality_assay.rb +0 -55
- data/test/case_false_assay.rb +0 -48
- data/test/case_identity_assay.rb +0 -51
- data/test/case_include_assay.rb +0 -51
- data/test/case_instance_assay.rb +0 -51
- data/test/case_kind_assay.rb +0 -51
- data/test/case_less_assay.rb +0 -53
- data/test/case_less_equal_assay.rb +0 -53
- data/test/case_like_assay.rb +0 -57
- data/test/case_match_assay.rb +0 -45
- data/test/case_more_assay.rb +0 -53
- data/test/case_more_equal_assay.rb +0 -53
- data/test/case_nil_assay.rb +0 -48
- data/test/case_nomatch_assay.rb +0 -47
- data/test/case_raise_assay.rb +0 -51
- data/test/case_respond_assay.rb +0 -51
- data/test/case_throw_assay.rb +0 -51
- data/test/case_true_assay.rb +0 -48
- data/test/case_unequal_assay.rb +0 -55
- data/test/case_within_assay.rb +0 -61
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
## StdoutAssay
|
|
2
|
+
|
|
3
|
+
The `StdoutAssay` asserts that a output is sent to `$stdout`.
|
|
4
|
+
|
|
5
|
+
assert StdoutAssay.pass?('foo'){ puts 'foo' }
|
|
6
|
+
|
|
7
|
+
refute StdoutAssay.pass?('foo'){ nil }
|
|
8
|
+
refute StdoutAssay.pass?('foo'){ puts 'bar' }
|
|
9
|
+
|
|
10
|
+
And conversely,
|
|
11
|
+
|
|
12
|
+
refute StdoutAssay.fail?('foo'){ puts 'foo' }
|
|
13
|
+
|
|
14
|
+
assert StdoutAssay.fail?('foo'){ nil }
|
|
15
|
+
assert StdoutAssay.fail?('foo'){ puts 'bar' }
|
|
16
|
+
|
|
17
|
+
The StdoutAssay uses `#===` to test the match so we can also
|
|
18
|
+
match against a regular expression.
|
|
19
|
+
|
|
20
|
+
assert StdoutAssay.pass?(/f/){ puts 'foo' }
|
|
21
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
## StderrAssay
|
|
2
|
+
|
|
3
|
+
The `StderrAssay` asserts that a output is sent to `$stderr`.
|
|
4
|
+
|
|
5
|
+
assert StderrAssay.pass?('foo'){ $stderr.puts 'foo' }
|
|
6
|
+
|
|
7
|
+
refute StderrAssay.pass?('foo'){ nil }
|
|
8
|
+
refute StderrAssay.pass?('foo'){ $stderr.puts 'bar' }
|
|
9
|
+
|
|
10
|
+
And conversely,
|
|
11
|
+
|
|
12
|
+
refute StderrAssay.fail?('foo'){ $stderr.puts 'foo' }
|
|
13
|
+
|
|
14
|
+
assert StderrAssay.fail?('foo'){ nil }
|
|
15
|
+
assert StderrAssay.fail?('foo'){ $stderr.puts 'bar' }
|
|
16
|
+
|
|
17
|
+
The StderrAssay uses `#===` to test the match so we can also
|
|
18
|
+
match against a regular expression.
|
|
19
|
+
|
|
20
|
+
assert StderrAssay.pass?(/f/){ $stderr.puts 'foo' }
|
|
21
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Asay Lookup
|
|
2
|
+
|
|
3
|
+
Assay classes are indexed by both name and associated operation, so they
|
|
4
|
+
can be looked-up by either. The indexes are stored as class attributes of
|
|
5
|
+
the Assertion base class.
|
|
6
|
+
|
|
7
|
+
Let's lookup the class for `==` equality.
|
|
8
|
+
|
|
9
|
+
Assertion.by_operator(:==) #=> ::EqualAssay
|
|
10
|
+
|
|
11
|
+
Let's lookup the assertion class for `#empty?`.
|
|
12
|
+
|
|
13
|
+
Assertion.by_operator(:empty?) #=> ::EmptyAssay
|
|
14
|
+
|
|
15
|
+
If we wish to lookup by assertive name instead of operator, we can use
|
|
16
|
+
the `by_name` method instead.
|
|
17
|
+
|
|
18
|
+
Assertion.by_name(:empty) #=> ::EmptyAssay
|
|
19
|
+
|
|
20
|
+
We can also use the `Assay.lookup` module method, which will lookup an assay
|
|
21
|
+
class by either assertion name or associated operator.
|
|
22
|
+
|
|
23
|
+
Assay.lookup(:==) #=> ::EqualAssay
|
|
24
|
+
Assay.lookup(:empty?) #=> ::EmptyAssay
|
|
25
|
+
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Assay as Assertor
|
|
2
|
+
|
|
3
|
+
Assay classes can be converted to assertors, otherwise known as *matchers* in
|
|
4
|
+
RSpec circles. The idea behind Assertors is that they can be initialized with
|
|
5
|
+
pre-set criteria and then applied to target subjects.
|
|
6
|
+
|
|
7
|
+
## Standard Target Matching
|
|
8
|
+
|
|
9
|
+
assertor = EqualAssay[1]
|
|
10
|
+
|
|
11
|
+
assertor.assert!(1)
|
|
12
|
+
|
|
13
|
+
expect EqualAssay do
|
|
14
|
+
assertor.assert!(2)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
## Partial Arguments
|
|
18
|
+
|
|
19
|
+
assertor = LessAssay[1,__]
|
|
20
|
+
|
|
21
|
+
We can apply the assertor using the `#pass!` method.
|
|
22
|
+
|
|
23
|
+
assertor.assert!(2)
|
|
24
|
+
|
|
25
|
+
Likewise we can assert the negated expression using `#fail!`.
|
|
26
|
+
|
|
27
|
+
assertor.refute!(0)
|
|
28
|
+
|
|
29
|
+
Assay partial a very versile because they allow any argument to become
|
|
30
|
+
the target of a assertor.
|
|
31
|
+
|
|
32
|
+
assertor = CompareAssay[2,1,__]
|
|
33
|
+
|
|
34
|
+
assertor.assert!(1)
|
|
35
|
+
assertor.refute!(0)
|
|
36
|
+
|
|
37
|
+
## Match Operator
|
|
38
|
+
|
|
39
|
+
The `#=~` method is an alias for `#assert!`.
|
|
40
|
+
|
|
41
|
+
assertor = EqualAssay[1]
|
|
42
|
+
assertor =~ 1
|
|
43
|
+
|
|
44
|
+
Conversely, `#!~` method is an alias for `#refute!`.
|
|
45
|
+
|
|
46
|
+
assertor !~ 2
|
|
47
|
+
|
|
48
|
+
## Case Operator
|
|
49
|
+
|
|
50
|
+
The `#===` method is also an alias for `#assert!`.
|
|
51
|
+
|
|
52
|
+
assertor === 1
|
|
53
|
+
|
|
54
|
+
This allows the `case` statement to be used in an intersting way.
|
|
55
|
+
|
|
56
|
+
case 10
|
|
57
|
+
when KindAssay[Numeric]
|
|
58
|
+
when EqualAssay[10.0]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
## Negated Assertors
|
|
62
|
+
|
|
63
|
+
Assertors can also be negated so that pass and fail methods swap behaviors.
|
|
64
|
+
|
|
65
|
+
assertor = EqualityAssay[1]
|
|
66
|
+
|
|
67
|
+
assertor.not =~ 2
|
|
68
|
+
assertor.not !~ 1
|
|
69
|
+
|
|
70
|
+
For conveience we can also negate the assertor using the `~` unary operator.
|
|
71
|
+
|
|
72
|
+
!assertor === 2
|
|
73
|
+
|
|
74
|
+
## Just Cheking
|
|
75
|
+
|
|
76
|
+
Assertors can also be used just to test the assertion without actually
|
|
77
|
+
raising the associated exception.
|
|
78
|
+
|
|
79
|
+
assertor = EqualityAssay[__,1]
|
|
80
|
+
|
|
81
|
+
assertor.pass?(1)
|
|
82
|
+
assertor.fail?(2)
|
|
83
|
+
|
|
84
|
+
## RSpec Compatability
|
|
85
|
+
|
|
86
|
+
RSpec compatibality is provided via neccessary method alias, in particular
|
|
87
|
+
`#matches?` and `#does_not_match?`.
|
|
88
|
+
|
|
89
|
+
assertor = EqualityAssay[__,1]
|
|
90
|
+
|
|
91
|
+
assert assertor.matches?(1)
|
|
92
|
+
assert assertor.does_not_match?(2)
|
|
93
|
+
|
|
94
|
+
Error messages are handle by RSpec by `#failure_message_for_should` and
|
|
95
|
+
`#failure_message_for_should_not`.
|
|
96
|
+
|
|
97
|
+
assertor.failure_message_for_should(1)
|
|
98
|
+
assertor.failure_message_for_should_not(2)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## Hashes
|
|
102
|
+
|
|
103
|
+
A Hash under test is not mistaken for options. Only a trailing Hash
|
|
104
|
+
whose keys are all `:message` or `:backtrace` is taken as options.
|
|
105
|
+
|
|
106
|
+
EqualAssay.assert!({:a=>1}, {:a=>1})
|
|
107
|
+
EqualAssay.assert!({}, {})
|
|
108
|
+
|
|
109
|
+
expect ::EqualAssay do
|
|
110
|
+
EqualAssay.assert!({:a=>1}, {:a=>2})
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
EqualAssay[{:a=>1}] =~ {:a=>1}
|
|
114
|
+
|
|
115
|
+
expect ::EqualAssay do
|
|
116
|
+
EqualAssay.assert!(1, 2, :message=>"my message")
|
|
117
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Assay Class Methods
|
|
2
|
+
|
|
3
|
+
## Version
|
|
4
|
+
|
|
5
|
+
The version of the library is available as a constant.
|
|
6
|
+
|
|
7
|
+
assert Assay::VERSION =~ /^\d+\.\d+\.\d+/
|
|
8
|
+
|
|
9
|
+
## Color Messages
|
|
10
|
+
|
|
11
|
+
We can have some Assay error messages use ANSI color output by
|
|
12
|
+
setting the `Assay.color` setting to `true`.
|
|
13
|
+
|
|
14
|
+
Assay.color = true
|
|
15
|
+
|
|
16
|
+
Keep in mind that this requires the `ansi` library.
|
|
17
|
+
|
|
18
|
+
In particular it is the equality related assertions that utilize color
|
|
19
|
+
output when the objects compared are large. This helps the developer
|
|
20
|
+
pinpint the differences quickly.
|
|
21
|
+
|
|
22
|
+
expect EqualAssay do
|
|
23
|
+
EqualAssay['really long string'] === 'other string'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
## Lookup Assay Classes
|
|
27
|
+
|
|
28
|
+
Assay tracks all created Assay classes by both associated operation
|
|
29
|
+
and assertive name.
|
|
30
|
+
|
|
31
|
+
Assay.lookup_by_operator(:==) #=> EqualAssay
|
|
32
|
+
|
|
33
|
+
Assay.lookup_by_name(:equal) #=> EqualAssay
|
|
34
|
+
|
|
35
|
+
We can look for either with just `lookup`.
|
|
36
|
+
|
|
37
|
+
Assay.lookup(:==) #=> EqualAssay
|
|
38
|
+
Assay.lookup(:equal) #=> EqualAssay
|
|
39
|
+
|
|
40
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
## Should
|
|
2
|
+
|
|
3
|
+
require 'assay/fluidity/should'
|
|
4
|
+
|
|
5
|
+
Now we have a fluent notation with which to make assertions.
|
|
6
|
+
|
|
7
|
+
true.should.be.true
|
|
8
|
+
false.should.be.false
|
|
9
|
+
|
|
10
|
+
(5 + 5).should.equal 10
|
|
11
|
+
|
|
12
|
+
[1,2,3].should.include(2)
|
|
13
|
+
|
|
14
|
+
We can also use the associated operator (Ruby's built-in query method name).
|
|
15
|
+
|
|
16
|
+
false.should.be.false?
|
|
17
|
+
true.should.be.true?
|
|
18
|
+
|
|
19
|
+
(5 + 5).should == 10
|
|
20
|
+
|
|
21
|
+
Indefinite article `a` and `an` are suppored.
|
|
22
|
+
|
|
23
|
+
12.should.be.a.kind_of?(Integer)
|
|
24
|
+
|
|
25
|
+
As is `not` for negation.
|
|
26
|
+
|
|
27
|
+
12.should.not.equal(20)
|
|
28
|
+
|
|
29
|
+
We should also make sure such assertions can fail.
|
|
30
|
+
|
|
31
|
+
IncludeAssay.should.be.raised do
|
|
32
|
+
[1,2,3].should.include(4)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
FalseAssay.should.be.raised do
|
|
36
|
+
true.should.be.false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
EqualAssay.should.be.raised do
|
|
40
|
+
(5 + 5).should == 11
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
Matcher notation is also supported, if you have any matcher classes
|
|
44
|
+
to use. Assay classes can be converted to matchers, so we can use
|
|
45
|
+
one of those to try this out.
|
|
46
|
+
|
|
47
|
+
be_sixteen = EqualAssay[16.0]
|
|
48
|
+
|
|
49
|
+
16.should be_sixteen
|
|
50
|
+
|
|
51
|
+
15.should_not be_sixteen
|
|
52
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
## Must
|
|
2
|
+
|
|
3
|
+
require 'assay/fluidity/must'
|
|
4
|
+
|
|
5
|
+
Now we have a fluent notation with which to make assertions.
|
|
6
|
+
|
|
7
|
+
true.must.be.true
|
|
8
|
+
false.must.be.false
|
|
9
|
+
|
|
10
|
+
(5 + 5).must.equal 10
|
|
11
|
+
|
|
12
|
+
[1,2,3].must.include(2)
|
|
13
|
+
|
|
14
|
+
We can also use the associated operator (Ruby's built-in query method name).
|
|
15
|
+
|
|
16
|
+
false.must.be.false?
|
|
17
|
+
true.must.be.true?
|
|
18
|
+
|
|
19
|
+
(5 + 5).must == 10
|
|
20
|
+
|
|
21
|
+
Indefinite article `a` and `an` are suppored.
|
|
22
|
+
|
|
23
|
+
12.must.be.a.kind_of?(Integer)
|
|
24
|
+
|
|
25
|
+
12.must.be.an.instance_of?(Integer)
|
|
26
|
+
|
|
27
|
+
As is `not` for negation.
|
|
28
|
+
|
|
29
|
+
12.must.not.equal(20)
|
|
30
|
+
|
|
31
|
+
Or `must_not` can also be used.
|
|
32
|
+
|
|
33
|
+
12.must_not.equal(20)
|
|
34
|
+
|
|
35
|
+
We must also make sure such assertions can fail.
|
|
36
|
+
|
|
37
|
+
IncludeAssay.must.be.raised do
|
|
38
|
+
[1,2,3].must.include(4)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
FalseAssay.must.be.raised do
|
|
42
|
+
true.must.be.false
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
EqualAssay.must.be.raised do
|
|
46
|
+
(5 + 5).must == 11
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
Matcher notation is also supported, if you have any matcher classes
|
|
50
|
+
to use. Assay classes can be converted to matchers, so we can use
|
|
51
|
+
one of those to try this out.
|
|
52
|
+
|
|
53
|
+
be_sixteen = EqualAssay[16.0]
|
|
54
|
+
|
|
55
|
+
16.must be_sixteen
|
|
56
|
+
|
|
57
|
+
15.must_not be_sixteen
|
|
58
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
## Grammer
|
|
2
|
+
|
|
3
|
+
require 'assay/fluidity/assert'
|
|
4
|
+
|
|
5
|
+
Now we have a fluent notation with which to make assertions.
|
|
6
|
+
|
|
7
|
+
true.assert.true
|
|
8
|
+
false.assert.false
|
|
9
|
+
|
|
10
|
+
(5 + 5).must.equal 10
|
|
11
|
+
|
|
12
|
+
[1,2,3].must.include(2)
|
|
13
|
+
|
|
14
|
+
We can also use the associated operator (Ruby's built-in query method name).
|
|
15
|
+
|
|
16
|
+
false.assert.false?
|
|
17
|
+
true.assert.true?
|
|
18
|
+
|
|
19
|
+
(5 + 5).assert == 10
|
|
20
|
+
|
|
21
|
+
(9 + 9).assert.not == 10
|
|
22
|
+
|
|
23
|
+
12.assert.kind_of?(Integer)
|
|
24
|
+
|
|
25
|
+
As is `not` for negation.
|
|
26
|
+
|
|
27
|
+
12.assert.not.equal(20)
|
|
28
|
+
|
|
29
|
+
Or `should_not` can also be used.
|
|
30
|
+
|
|
31
|
+
12.should_not.equal(20)
|
|
32
|
+
|
|
33
|
+
We must also make sure such assertions can fail. Since #assert is special
|
|
34
|
+
method to assay classes, we can use it as on these as part of our test
|
|
35
|
+
grmmer. So we use the raw `#assert!` method to handle the test.
|
|
36
|
+
|
|
37
|
+
RaiseAssay.assert!(IncludeAssay) do
|
|
38
|
+
[1,2,3].assert.include(4)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
RaiseAssay.assert!(FalseAssay) do
|
|
42
|
+
true.assert.false
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
RaiseAssay.assert!(EqualAssay) do
|
|
46
|
+
(5 + 5).assert == 11
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
Matcher notation is also supported, if you have any matcher classes
|
|
50
|
+
to use. Assay classes can be converted to matchers, so we can use
|
|
51
|
+
one of those to try this out.
|
|
52
|
+
|
|
53
|
+
is_sixteen = EqualAssay[16.0]
|
|
54
|
+
|
|
55
|
+
16.assert is_sixteen
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
The ordinary form of `assert`, given a truth value, still works as it
|
|
59
|
+
does without the fluent notation.
|
|
60
|
+
|
|
61
|
+
o = Object.new
|
|
62
|
+
|
|
63
|
+
o.instance_eval{ assert(true) }
|
|
64
|
+
|
|
65
|
+
RaiseAssay.assert!(RuntimeError) do
|
|
66
|
+
o.instance_eval{ assert(false) }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
RaiseAssay.assert!(RuntimeError) do
|
|
70
|
+
o.instance_eval{ assert(nil) }
|
|
71
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
## Other Stuff
|
|
2
|
+
|
|
3
|
+
What if there is an assertion made for which no Assay class exists?
|
|
4
|
+
If the target object has a query method defined by the same name,
|
|
5
|
+
that is, one ending in a `?` mark, then that mehtod will be used
|
|
6
|
+
to test the assertion.
|
|
7
|
+
|
|
8
|
+
c = Class.new do
|
|
9
|
+
def initialize(truth)
|
|
10
|
+
@truth = truth
|
|
11
|
+
end
|
|
12
|
+
def yes?
|
|
13
|
+
@truth
|
|
14
|
+
end
|
|
15
|
+
def no?
|
|
16
|
+
!@truth
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
x = c.new(true)
|
|
21
|
+
|
|
22
|
+
x.should.be.yes
|
|
23
|
+
|
|
24
|
+
x.should_not.be.no
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
And such an assertion fails when the query says otherwise.
|
|
28
|
+
|
|
29
|
+
RaiseAssay.assert!(Assertion) do
|
|
30
|
+
x.should.be.no
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
RaiseAssay.assert!(Assertion) do
|
|
34
|
+
x.should_not.be.yes
|
|
35
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
## Methods Every Object Has
|
|
2
|
+
|
|
3
|
+
require 'assay/fluidity'
|
|
4
|
+
|
|
5
|
+
Some query methods belong to every object: `kind_of?`, `instance_of?`,
|
|
6
|
+
`nil?`, `eql?`, `equal?`, `respond_to?`, `is_a?`, `frozen?`. Used in an
|
|
7
|
+
assertion they are still about the object under test, so they pass and
|
|
8
|
+
fail like any other.
|
|
9
|
+
|
|
10
|
+
10.assert.kind_of?(Integer)
|
|
11
|
+
10.should.be.kind_of?(Integer)
|
|
12
|
+
10.must.be.an.instance_of?(Integer)
|
|
13
|
+
nil.should.be.nil?
|
|
14
|
+
10.assert.eql?(10)
|
|
15
|
+
10.assert.respond_to?(:succ)
|
|
16
|
+
10.assert.is_a?(Numeric)
|
|
17
|
+
:a.assert.equal?(:a)
|
|
18
|
+
"abc".freeze.assert.frozen?
|
|
19
|
+
|
|
20
|
+
Each of these fails when it should. Where an Assay class covers the
|
|
21
|
+
method, the failure is of that class.
|
|
22
|
+
|
|
23
|
+
RaiseAssay.assert!(KindAssay) do
|
|
24
|
+
10.assert.kind_of?(String)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
RaiseAssay.assert!(KindAssay) do
|
|
28
|
+
10.should.be.kind_of?(String)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
RaiseAssay.assert!(InstanceAssay) do
|
|
32
|
+
10.must.be.an.instance_of?(Numeric)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
RaiseAssay.assert!(NilAssay) do
|
|
36
|
+
10.should.be.nil?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
RaiseAssay.assert!(EqualityAssay) do
|
|
40
|
+
10.assert.eql?(10.0)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
RaiseAssay.assert!(RespondAssay) do
|
|
44
|
+
10.assert.respond_to?(:upcase)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
Where none does, the object's own method decides, and the failure is a
|
|
48
|
+
plain Assertion.
|
|
49
|
+
|
|
50
|
+
RaiseAssay.assert!(Assertion) do
|
|
51
|
+
10.assert.is_a?(String)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
RaiseAssay.assert!(Assertion) do
|
|
55
|
+
"abc".assert.equal?("abc".dup)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
RaiseAssay.assert!(Assertion) do
|
|
59
|
+
"abc".dup.assert.frozen?
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
The same goes for negation.
|
|
63
|
+
|
|
64
|
+
10.should_not.be.kind_of?(String)
|
|
65
|
+
10.assert.not.nil?
|
|
66
|
+
|
|
67
|
+
RaiseAssay.assert!(KindAssay) do
|
|
68
|
+
10.should_not.be.kind_of?(Integer)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
RaiseAssay.assert!(NilAssay) do
|
|
72
|
+
nil.assert.not.nil?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
The `!=` operator is the opposite of `==`.
|
|
76
|
+
|
|
77
|
+
10.assert != 11
|
|
78
|
+
|
|
79
|
+
RaiseAssay.assert!(UnequalAssay) do
|
|
80
|
+
10.assert != 10
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
Keyword arguments are passed along to the object's method.
|
|
84
|
+
|
|
85
|
+
gate = Class.new do
|
|
86
|
+
def open?(strict: false)
|
|
87
|
+
!strict
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
gate.new.should.be.open?(strict: false)
|
|
92
|
+
|
|
93
|
+
RaiseAssay.assert!(Assertion) do
|
|
94
|
+
gate.new.should.be.open?(strict: true)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
A method the object doesn't have is an error, not an assertion.
|
|
98
|
+
|
|
99
|
+
RaiseAssay.assert!(NoMethodError) do
|
|
100
|
+
10.assert.zork
|
|
101
|
+
end
|
|
102
|
+
|