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.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +7 -0
  3. data/HISTORY.md +128 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +287 -0
  6. data/demo/ae/01_overview.md +98 -0
  7. data/demo/ae/03_assert.md +398 -0
  8. data/demo/ae/04_subjunctive.md +100 -0
  9. data/demo/ae/05_expect.md +136 -0
  10. data/demo/ae/06_counts.md +33 -0
  11. data/demo/ae/07_matchers.md +34 -0
  12. data/demo/ae/08_check.md +61 -0
  13. data/demo/ae/09_assay.md +124 -0
  14. data/demo/ae/applique/setup.rb +11 -0
  15. data/{test → demo/applique}/helper.rb +8 -2
  16. data/demo/applique/setup.rb +1 -0
  17. data/demo/bang/01_bang.md +220 -0
  18. data/demo/core/00_introduction.md +2 -0
  19. data/demo/core/01_assay_classes/00_introduction.md +2 -0
  20. data/demo/core/01_assay_classes/01_nil_assay.md +35 -0
  21. data/demo/core/01_assay_classes/02_boolean_assay.md +35 -0
  22. data/demo/core/01_assay_classes/03_false_assay.md +19 -0
  23. data/demo/core/01_assay_classes/03_true_assay.md +20 -0
  24. data/demo/core/01_assay_classes/04_like_assay.md +19 -0
  25. data/demo/core/01_assay_classes/05_equal_assay.md +19 -0
  26. data/demo/core/01_assay_classes/06_unequal_assay.md +35 -0
  27. data/demo/core/01_assay_classes/07_equality_assay.md +19 -0
  28. data/demo/core/01_assay_classes/08_identity_assay.md +24 -0
  29. data/demo/core/01_assay_classes/09_case_assay.md +22 -0
  30. data/demo/core/01_assay_classes/10_match_assay.md +15 -0
  31. data/demo/core/01_assay_classes/11_nomatch_assay.md +16 -0
  32. data/demo/core/01_assay_classes/12_compare_assay.md +24 -0
  33. data/demo/core/01_assay_classes/13_less_assay.md +29 -0
  34. data/demo/core/01_assay_classes/14_more_assay.md +29 -0
  35. data/demo/core/01_assay_classes/15_less_equal_assay.md +30 -0
  36. data/demo/core/01_assay_classes/16_more_equal_assay.md +29 -0
  37. data/demo/core/01_assay_classes/17_close_assay.md +42 -0
  38. data/demo/core/01_assay_classes/17_within_assay.md +42 -0
  39. data/demo/core/01_assay_classes/18_kind_assay.md +17 -0
  40. data/demo/core/01_assay_classes/19_instance_assay.md +16 -0
  41. data/demo/core/01_assay_classes/20_include_assay.md +17 -0
  42. data/demo/core/01_assay_classes/21_empty_assay.md +15 -0
  43. data/demo/core/01_assay_classes/22_respond_assay.md +15 -0
  44. data/demo/core/01_assay_classes/23_execution_assay.md +40 -0
  45. data/demo/core/01_assay_classes/23_return_assay.md +37 -0
  46. data/demo/core/01_assay_classes/24_rescue_assay.md +40 -0
  47. data/demo/core/01_assay_classes/25_raise_assay.md +40 -0
  48. data/demo/core/01_assay_classes/26_throw_assay.md +47 -0
  49. data/demo/core/01_assay_classes/27_path_assay.md +20 -0
  50. data/demo/core/01_assay_classes/28_directory_assay.md +21 -0
  51. data/demo/core/01_assay_classes/29_file_assay.md +20 -0
  52. data/demo/core/01_assay_classes/30_output_assay.md +39 -0
  53. data/demo/core/01_assay_classes/31_stdout_assay.md +21 -0
  54. data/demo/core/01_assay_classes/32_stderr_assay.md +21 -0
  55. data/demo/core/02_lookup.md +25 -0
  56. data/demo/core/03_assertor.md +117 -0
  57. data/demo/core/04_assay.md +40 -0
  58. data/demo/fluidity/00_intro.md +7 -0
  59. data/demo/fluidity/01_should.md +52 -0
  60. data/demo/fluidity/02_must.md +58 -0
  61. data/demo/fluidity/03_assert.md +71 -0
  62. data/demo/fluidity/04_other.md +35 -0
  63. data/demo/fluidity/05_object_methods.md +102 -0
  64. data/demo/minitest/01_minitest_extensions.rdoc +217 -0
  65. data/demo/minitest/02_minitest_assertions.rdoc +250 -0
  66. data/demo/rspec/00_introduction.md +16 -0
  67. data/demo/rspec/01_should.md +24 -0
  68. data/demo/rspec/02_matchers.md +176 -0
  69. data/demo/rspec/03_have.md +51 -0
  70. data/demo/rspec/04_expect.md +49 -0
  71. data/demo/rspec/applique/setup.rb +2 -0
  72. data/demo/testunit/01_testunit_assertions.md +266 -0
  73. data/lib/assay/adapter/minitest.rb +32 -21
  74. data/lib/assay/adapter/testunit.rb +31 -38
  75. data/lib/assay/ae/assert.rb +77 -0
  76. data/lib/assay/ae/assertor.rb +453 -0
  77. data/lib/assay/ae/check.rb +154 -0
  78. data/lib/assay/ae/core_ext.rb +146 -0
  79. data/lib/assay/ae/expect.rb +72 -0
  80. data/lib/assay/ae/must.rb +64 -0
  81. data/lib/assay/ae/should.rb +58 -0
  82. data/lib/assay/ae/subjunctive.rb +66 -0
  83. data/lib/assay/ae.rb +29 -0
  84. data/lib/assay/assertable.rb +21 -5
  85. data/lib/assay/assertor.rb +4 -4
  86. data/lib/assay/bang.rb +147 -0
  87. data/lib/assay/close_assay.rb +2 -2
  88. data/lib/assay/core_ext/kernel.rb +4 -8
  89. data/lib/assay/fluidity/assert.rb +27 -0
  90. data/lib/assay/fluidity/grammar.rb +157 -0
  91. data/lib/assay/fluidity/is.rb +18 -0
  92. data/lib/assay/fluidity/must.rb +38 -0
  93. data/lib/assay/fluidity/should.rb +32 -0
  94. data/lib/assay/fluidity/will.rb +36 -0
  95. data/lib/assay/fluidity.rb +6 -0
  96. data/lib/assay/less_assay.rb +7 -1
  97. data/lib/assay/less_equal_assay.rb +7 -1
  98. data/lib/assay/minitest/assertions.rb +495 -0
  99. data/lib/assay/minitest/extensions.rb +496 -0
  100. data/lib/assay/minitest.rb +24 -0
  101. data/lib/assay/more_assay.rb +7 -1
  102. data/lib/assay/more_equal_assay.rb +7 -1
  103. data/lib/assay/rspec/expect.rb +151 -0
  104. data/lib/assay/rspec/have.rb +201 -0
  105. data/lib/assay/rspec/matchers.rb +272 -0
  106. data/lib/assay/rspec/operatics.rb +60 -0
  107. data/lib/assay/rspec/should.rb +49 -0
  108. data/lib/assay/rspec.rb +13 -0
  109. data/lib/assay/testunit/assertions.rb +484 -0
  110. data/lib/assay/testunit.rb +9 -0
  111. data/lib/assay/version.rb +3 -0
  112. data/lib/assay.rb +7 -21
  113. metadata +211 -80
  114. data/.ruby +0 -51
  115. data/COPYING.rdoc +0 -38
  116. data/HISTORY.rdoc +0 -65
  117. data/QED.rdoc +0 -1143
  118. data/README.rdoc +0 -173
  119. data/lib/assay.yml +0 -51
  120. data/test/case_compare_assay.rb +0 -59
  121. data/test/case_empty_assay.rb +0 -51
  122. data/test/case_equal_assay.rb +0 -53
  123. data/test/case_equality_assay.rb +0 -55
  124. data/test/case_false_assay.rb +0 -48
  125. data/test/case_identity_assay.rb +0 -51
  126. data/test/case_include_assay.rb +0 -51
  127. data/test/case_instance_assay.rb +0 -51
  128. data/test/case_kind_assay.rb +0 -51
  129. data/test/case_less_assay.rb +0 -53
  130. data/test/case_less_equal_assay.rb +0 -53
  131. data/test/case_like_assay.rb +0 -57
  132. data/test/case_match_assay.rb +0 -45
  133. data/test/case_more_assay.rb +0 -53
  134. data/test/case_more_equal_assay.rb +0 -53
  135. data/test/case_nil_assay.rb +0 -48
  136. data/test/case_nomatch_assay.rb +0 -47
  137. data/test/case_raise_assay.rb +0 -51
  138. data/test/case_respond_assay.rb +0 -51
  139. data/test/case_throw_assay.rb +0 -51
  140. data/test/case_true_assay.rb +0 -48
  141. data/test/case_unequal_assay.rb +0 -55
  142. data/test/case_within_assay.rb +0 -61
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e1cd843e332e66543d082f330bfe235b485adcb0108922705bbffe4f464d3357
4
+ data.tar.gz: 9b709e135cf23e1528c9f3af28dcb6c0a4ac5e084ede0099104be81ab68890ed
5
+ SHA512:
6
+ metadata.gz: b5f0f62e5ad8b60e6a1722d51d6039a12f470b8a85c84c9d17eba961a099ecefd21fb8ebe519782f4aa4393ccf1a0ece2c656f02aefe0708623041f51bb0303b
7
+ data.tar.gz: ac391305763a9894254489aa7d72d0bd4f3f39d49d6580114652046ff492301f078923f4eca0a29dfde9e11b39fdbb457a476f3abe70252cb296838d102c48b4
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --title "Assay"
2
+ --readme README.md
3
+ --protected
4
+ --private
5
+ lib
6
+ -
7
+ [A-Z]*.*
data/HISTORY.md ADDED
@@ -0,0 +1,128 @@
1
+ # HISTORY
2
+
3
+ ## 0.5.0 | 2026-11-23
4
+
5
+ Assay is one library again. The notations that were spun off as separate
6
+ gems in 0.4 (Fluidity, RSpecial, Assay MiniTest and Assay TestUnit) are
7
+ back, each loaded on its own, and Bang and AE join them. Assay needs Ruby 2.7 or newer.
8
+
9
+ Changes:
10
+
11
+ * Add `assay/fluidity`, the fluent notation (`x.should.equal y`), from
12
+ the Fluidity gem. Its module is `Assay::Fluidity`.
13
+ * Add `assay/rspec`, RSpec-style matchers and `expect`, from the RSpecial
14
+ gem. Its module is `Assay::RSpec`.
15
+ * Add `assay/minitest` and `assay/testunit`, the assertion methods of
16
+ those frameworks, from the Assay MiniTest and Assay TestUnit gems.
17
+ * Add `assay/bang`, from the Bang gem, rebuilt on Assay's classes:
18
+ `x.equal!(y)` fails with an `EqualAssay`. A query method Assay has
19
+ no class for still works (`10.even!`) and fails with an `Assertion`.
20
+ * Add `assay/ae`, the notation of the AE gem (`x.assert == y`,
21
+ `expect`, and optionally `should`, `must` and `ok`/`no`), built on
22
+ Assay's classes: a failure is of the Assay class for the method
23
+ where there is one. Its module is `Assay::AE`. The AE gem itself
24
+ carries on unchanged.
25
+ * Fix a Hash under test being taken for options, which made comparing
26
+ two hashes raise ArgumentError in every notation. Only a trailing
27
+ Hash whose keys are all `:message` or `:backtrace` is options now.
28
+ * Rewrite the Minitest and Test::Unit adapters for Minitest 5 and 6 and
29
+ for test-unit 3. The old ones patched classes those frameworks no
30
+ longer have.
31
+ * `expect` takes a block: `expect{ ... }.to raise_error(ArgumentError)`.
32
+ * Fix `assert(false)` passing silently once `assay/fluidity/assert` was
33
+ loaded. Worse, Assay itself called that `assert`, so no assay could
34
+ fail either.
35
+ * Fix fluent assertions that used a method every object has, such as
36
+ `x.should.be.kind_of?(String)`, `x.assert.nil?` or `x.assert != y`.
37
+ The grammar object answered them itself, so they never failed. This
38
+ goes back to the Fluidity gem. Likewise `expect(x).to.kind_of?(String)`
39
+ in the RSpec notation, which is now a NoMethodError.
40
+ * The fluent notation passes keyword arguments on to an object's own
41
+ query method.
42
+ * Fix the fluent fallback to an object's own query method ignoring
43
+ negation: `x.should_not.be.no` now fails when `x.no?` is true.
44
+ * Fix `will_not` and `wont`. They were never defined, and loading the
45
+ `will` notation raised NameError.
46
+ * Fix `assert_in_epsilon` and `assert_not_in_epsilon` in the Test::Unit
47
+ notation, which raised NameError.
48
+ * Fix `CloseAssay` for a negative criterion, and its message for long
49
+ values.
50
+ * Give `LessAssay`, `LessEqualAssay`, `MoreAssay` and `MoreEqualAssay`
51
+ messages of their own (`5 <= 3`). They said `5 <=> 3 == 0`.
52
+ * `Kernel#like?` no longer tries `=~`, which Ruby 3.2 removed from
53
+ Object. It is now the same as Facets' `like?`.
54
+ * An operator with no assay of its own, used with `expect(x).to`, is
55
+ sent to the object and fails with an Assertion. It raised an
56
+ unrelated error.
57
+ * Assay's failures no longer depend on which `assert` method is in
58
+ scope: it calls BRASS's directly.
59
+ * `Assay::VERSION` gives the version. `Assay.metadata`, and the
60
+ constants made from it, are gone.
61
+ * Replace the old packaging (`.index`, `.gemspec`, `Assembly`,
62
+ `MANIFEST`) with a plain `assay.gemspec`, and Travis with GitHub
63
+ Actions, testing Ruby 2.7 to 4.0.
64
+
65
+
66
+ ## 0.4.1 | 2012-01-27
67
+
68
+ This release adds CloseAssay for relative approxmation assertions on values,
69
+ where as the WithinAssay handles absolute difference.
70
+
71
+ Changes:
72
+
73
+ * Add CloseAssay for relative approximation.
74
+ * Use past tense for RescueAssay's assertive name, i.e. :rescued.
75
+
76
+
77
+ ## 0.4.0 | 2012-01-25
78
+
79
+ Version 0.4 is a very polished partial rewrite of the Assay project.
80
+ This release sheds all ancillary code to separate projects. The
81
+ compatibility layers are now `assay-testunit`, `assay-minitest` and
82
+ `assay-rspec`. The built-in grammar is now the `fluidity` project.
83
+ All assertion classes now end with `Assay` suffix instead of `Failure`
84
+ and they are defined at the toplevel.
85
+
86
+ Changes:
87
+
88
+ * Spin-off all ancillary code, leaving only core functionality.
89
+ * Polish and semi-rewrite code.
90
+ * Renamed all Assertion subclasses form xxxFailure to xxxAssay.
91
+ * Add many new Assertion subclasses.
92
+
93
+
94
+ ## 0.3.0 | 2011-05-07
95
+
96
+ This release fix the interface of the assertive methods so they accept
97
+ a message argument, like the original testunit.
98
+
99
+ Changes:
100
+
101
+ * Fix assertive methods to take message argument.
102
+ * Fix Assertion class to store message.
103
+
104
+
105
+ ## 0.2.0 | 2011-05-05
106
+
107
+ This release of Assay is in good working order and can now be used
108
+ by other frameworks such as A.E. The only caveats at this point
109
+ are the Matcher API, which is still a bit unstable as the names of
110
+ some of its methods may yet change, and the error messages
111
+ for the various Failure classes still need improvement.
112
+
113
+ Changes:
114
+
115
+ * Add adapters for minitest and testunit.
116
+ * Add colorized comparison to EqualityFailure (via ANSI gem).
117
+ * Use standard exception messages (#to_s) instead of class methods.
118
+
119
+
120
+ ## 0.1.0 | 2010-11-14
121
+
122
+ This is the initial working version of Assay.
123
+ But it is far from ready for widespread usage.
124
+
125
+ Changes:
126
+
127
+ * Happy Birthday!
128
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ (BSD-2-Clause License)
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice,
7
+ this list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
14
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
15
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
16
+ COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
17
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
20
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
22
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,287 @@
1
+ # Assay
2
+
3
+ [Documentation](https://rubydoc.info/gems/assay) /
4
+ [Report Issue](https://github.com/rubyworks/assay/issues) /
5
+ [Source Code](https://github.com/rubyworks/assay)
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/assay.svg)](https://badge.fury.io/rb/assay)
8
+ [![CI](https://github.com/rubyworks/assay/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyworks/assay/actions/workflows/ci.yml)
9
+
10
+
11
+ ## DESCRIPTION
12
+
13
+ Assay defines assertions in the same way that Ruby defines
14
+ exceptions. Each kind of assertion is a class: it knows how to test,
15
+ how to explain a failure, and it is the exception raised when the
16
+ assertion fails. Assay provides a complete set of these classes for
17
+ the common kinds of assertion.
18
+
19
+ On top of the classes Assay provides a choice of notations for writing
20
+ assertions, each loaded on its own:
21
+
22
+ | Require | Notation |
23
+ |---|---|
24
+ | `assay/minitest` | Minitest's `assert_equal` and `must_equal` |
25
+ | `assay/testunit` | Test::Unit's `assert_equal` |
26
+ | `assay/rspec` | RSpec's `should eq` and `expect(x).to eq` |
27
+ | `assay/fluidity` | Assay's own: `x.should.equal y`, `x.assert == y` |
28
+ | `assay/ae` | AE's functor: `x.assert == y`, `a.assert.include?(e)` |
29
+ | `assay/bang` | Query methods as assertions: `x.equal!(y)`, `x.empty!` |
30
+
31
+ Whichever you choose, a failure is an instance of the same assay class,
32
+ and any test framework that follows the
33
+ [BRASS](https://github.com/rubyworks/brass) standard counts it as a
34
+ failed assertion.
35
+
36
+
37
+ ## FEATURES
38
+
39
+ * Patterned after the Ruby exception system.
40
+ * A failed assertion has a type, and an error message to suit it.
41
+ * Supports any variety of assertion notation.
42
+ * Can be used with almost any test framework.
43
+
44
+
45
+ ## INSTALLATION
46
+
47
+ $ gem install assay
48
+
49
+ Assay needs Ruby 2.7 or newer.
50
+
51
+
52
+ ## UTILIZATION
53
+
54
+ ### Assay Classes
55
+
56
+ Assay consists of a set of Assertion subclasses known as *assays*. They
57
+ are akin to Ruby's Exception subclasses, indeed the `Assertion` base class
58
+ is a subclass of Exception. But assays have special class methods that are
59
+ used to make assertions.
60
+
61
+ Consider the `EqualAssay` class. It defines methods for asserting equality
62
+ via the `#==` method.
63
+
64
+ EqualAssay.assert!(1,1)
65
+
66
+ Additionally, we can check the assertion's test without actually raising the
67
+ assertion if it fails using the query method.
68
+
69
+ EqualAssay.pass?(1,1) #=> true
70
+
71
+ Assays also provide the opposite method `#refute!` along with `#fail?`.
72
+
73
+ EqualAssay.refute!(1,2)
74
+
75
+ EqualAssay.fail?(1,2) #=> true
76
+
77
+ Assay instances are test matchers, which can be conveniently defined with `#[]`.
78
+
79
+ EqualAssay[1] =~ 1
80
+
81
+ Notice in the example we have used `#=~` to apply the matcher which makes
82
+ the `#assert!` call to the Assay object. Likewise `#!~` can be used to
83
+ call `#refute!` instead. And note that `#===` is also an alias for `#=~`.
84
+
85
+ EqualAssay[1] === 1
86
+
87
+ Which means assay matchers can be used in case statements.
88
+
89
+ case 10
90
+ when InstanceAssay[Integer]
91
+ when EqualAssay[10.0]
92
+ end
93
+
94
+ Pretty neat.
95
+
96
+ ### Notations
97
+
98
+ The classes make a sound foundation, but in the end we want to write
99
+ assertions easily and concisely. Each notation is a thin layer over the
100
+ assay classes, and is loaded only when asked for.
101
+
102
+ #### Fluidity
103
+
104
+ Assay's own notation reads as a chain of words off the object under test.
105
+
106
+ require 'assay/fluidity'
107
+
108
+ 10.should.be.kind_of(Integer)
109
+ 10.should_not.equal(20)
110
+
111
+ If you are accustomed to Minitest's spec methods, you might prefer `must`.
112
+
113
+ 10.must.be.kind_of(Integer)
114
+
115
+ And to satisfy the technical aficionados there is `assert`.
116
+
117
+ 10.assert.kind_of(Integer)
118
+ 10.assert == 10
119
+
120
+ `assay/fluidity` loads `should`, `must` and `assert`. Each can be loaded
121
+ alone (`assay/fluidity/should`), and `is` and `will` are available the
122
+ same way (`assay/fluidity/is`, `assay/fluidity/will`).
123
+
124
+ #### AE
125
+
126
+ The AE notation, from the [AE](https://github.com/rubyworks/ae) gem,
127
+ needs no vocabulary of its own: call any method of the object under
128
+ test through `assert`, and its result is asserted.
129
+
130
+ require 'assay/ae'
131
+
132
+ x.assert == y
133
+ a.assert.include?(e)
134
+ x.refute.nil?
135
+ "Daffy Duck".assert.start_with?("Daffy")
136
+
137
+ Where Assay has a class for the method, as it does for the first three,
138
+ that class is the failure raised; otherwise it is a plain `Assertion`.
139
+ `assert` still takes a truth value, or a block, as it does in Test::Unit.
140
+
141
+ assert(x > 3, "too small")
142
+ assert{ x > 3 }
143
+
144
+ `expect` tests a block's result by case equality, or that it raises.
145
+
146
+ expect ArgumentError do
147
+ Integer("x")
148
+ end
149
+
150
+ The subjunctive verbs and the `ok`/`no` checks are loaded separately.
151
+
152
+ require 'assay/ae/should' # x.should == y, x.should.be.a String
153
+ require 'assay/ae/must' # x.must == y
154
+ require 'assay/ae/check' # check{ |a, b| a == b }; ok 1, 1
155
+
156
+ AE and Fluidity both define `assert`, `should` and `must` on every
157
+ object, so load one or the other. Likewise load `assay/ae` or the AE
158
+ gem, not both: the gem stands on its own and raises only `Assertion`.
159
+
160
+ #### Bang
161
+
162
+ Bang turns a query method into an assertion: call it with `!` in place
163
+ of `?`, and prefix `not_` to negate it.
164
+
165
+ require 'assay/bang'
166
+
167
+ 10.kind_of!(Integer)
168
+ 10.equal!(5 + 5)
169
+ 10.not_equal!(20)
170
+
171
+ Where Assay has a class for the assertion, as it does for these, that
172
+ class is the failure raised. Any other query method an object has works
173
+ too, and fails with a plain `Assertion`.
174
+
175
+ 10.even!
176
+ 10.between!(1, 20)
177
+
178
+ For a procedure there are `raises!`, `rescues!` and `throws!`.
179
+
180
+ lambda{ raise ArgumentError }.raises!(ArgumentError)
181
+
182
+ #### RSpec
183
+
184
+ require 'assay/rspec'
185
+
186
+ include Assay::Matchers
187
+
188
+ 10.should be_kind_of(Integer)
189
+
190
+ expect(10).to eq(10)
191
+ expect{ raise ArgumentError }.to raise_error(ArgumentError)
192
+
193
+ #### Minitest
194
+
195
+ require 'assay/minitest'
196
+
197
+ include Assay::Assertions
198
+
199
+ assert_equal 10, 5 + 5
200
+ assert_kind_of Integer, 10
201
+
202
+ 10.must_equal 5 + 5
203
+
204
+ #### Test::Unit
205
+
206
+ require 'assay/testunit'
207
+
208
+ include Assay::Assertions
209
+
210
+ assert_equal 10, 5 + 5
211
+ assert_not_equal 10, 6 + 5
212
+
213
+ The three compatibility notations make it possible to move tests to
214
+ another framework without rewriting their assertions. They cover the
215
+ commonly used parts of each framework's API, not all of it.
216
+
217
+ These are just a few possible notations. There is no reason not to build
218
+ your own on top of Assay's classes if you have another approach in mind.
219
+ That, after all, is the purpose of having a set of reusable assertion
220
+ classes. Assay classes can be looked up by operator or by name, which
221
+ makes this easy:
222
+
223
+ Assay.lookup(:==) #=> EqualAssay
224
+ Assay.lookup(:empty?) #=> EmptyAssay
225
+
226
+ ### Framework Adapters
227
+
228
+ Assay follows the BRASS standard: its assertion classes have an
229
+ `#assertion?` method that returns `true`, by which a test framework can
230
+ tell a failed assertion from an ordinary error.
231
+ [Rubytest](https://github.com/rubyworks/rubytest) and the frameworks
232
+ built on it do this already. For Minitest and Test::Unit, which don't,
233
+ Assay provides adapters. Add one to your test helper:
234
+
235
+ require 'assay/adapter/minitest'
236
+
237
+ or
238
+
239
+ require 'assay/adapter/testunit'
240
+
241
+ Without the adapter you can still use Assay with these frameworks. They
242
+ will count Assay's failed assertions as errors rather than failures.
243
+
244
+ RSpec has no adapter. It reports any exception raised in an example as
245
+ a failure of that example, so Assay works in it as is.
246
+
247
+ ### Upgrading from 0.4
248
+
249
+ Since version 0.5 the notations are part of Assay again. The separate
250
+ gems are retired:
251
+
252
+ | Before | Now |
253
+ |---|---|
254
+ | gem `fluidity`, `require 'fluidity'` | `require 'assay/fluidity'` |
255
+ | gem `rspecial`, `require 'rspecial'` | `require 'assay/rspec'` |
256
+ | gem `assay-minitest` | `require 'assay/minitest'` |
257
+ | gem `assay-testunit` | `require 'assay/testunit'` |
258
+ | gem `bang`, `require 'bang'` | `require 'assay/bang'` |
259
+
260
+ `Fluidity` is now `Assay::Fluidity`, and `RSpecial` is `Assay::RSpec`.
261
+ Bang's failures are now assay classes where there is one, not
262
+ `Bang::Assertion`, and the query methods it added to Object (such as
263
+ `equal_to?` and `raises?`) are gone.
264
+ `Assay::Assertions`, `Assay::Matchers` and `Assay::Extensions` are as
265
+ they were.
266
+
267
+ The AE gem is not retired. `assay/ae` is the same notation built on
268
+ Assay's classes, under `Assay::AE` rather than `AE`. It leaves out
269
+ `ae/legacy` (use `assay/testunit`), `ae/pry` and AE's framework
270
+ adapters (Assay has its own, above).
271
+
272
+ ### Learning More
273
+
274
+ There is more to learn about Assay, mainly the variety of assay classes
275
+ available. The [demos](https://github.com/rubyworks/assay/tree/master/demo)
276
+ give an overview with working examples: they are run as tests with
277
+ [QED](https://github.com/rubyworks/qed). The
278
+ [API documentation](https://rubydoc.info/gems/assay) has the rest.
279
+
280
+
281
+ ## LICENSE & COPYRIGHT
282
+
283
+ Copyright (c) 2010 Rubyworks
284
+
285
+ This program is distributed under the terms of the *BSD-2-Clause* license.
286
+
287
+ See LICENSE.txt file for details.
@@ -0,0 +1,98 @@
1
+ # The AE Notation
2
+
3
+ AE (Assertive Expressive) is a notation designed around the concept of
4
+ an Assertor. The Assertor is an Assertion Functor, or Higher-Order
5
+ Function, which reroutes method calls while monitoring them for failing
6
+ conditions. It began as a library of its own, the AE gem, and is here
7
+ built on Assay's assertion classes.
8
+
9
+
10
+ ## What It Provides
11
+
12
+ Requiring the notation
13
+
14
+ require 'assay/ae'
15
+
16
+ loads the +Assertor+ class, the method +assert+ and its antonyms
17
+ +assert!+ and +refute+, the method +expect+, and a set of core
18
+ extensions that make writing certain types of assertions easier.
19
+
20
+
21
+ ## Assertion and Assertor Classes
22
+
23
+ The +Assertion+ class is at the heart of it. The +Assertion+ class
24
+ is a subclass of Exception. When an assertion is made and fails, it
25
+ is an Assertion that is raised: either an instance of Assertion
26
+ itself, or of the Assay class for the method used, each of which is
27
+ a subclass of Assertion.
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 `$!`.
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(Assay::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
+ Assay has a class for `==`, so more exactly it is an EqualAssay.
71
+
72
+ expect EqualAssay do
73
+ 1.assert == 2
74
+ end
75
+
76
+ The methods <tt>assert!</tt> and +refute+ are just like +assert+
77
+ expect they purport the negative condition. Patterned after Ruby's
78
+ own use of "<tt>!</tt>" as meaning +not+, <tt>assert!</tt> should be
79
+ read "assert not". While +refute+ exists for the sake of those who
80
+ find the use of a bang method for this purpose unsuited to them.
81
+
82
+
83
+ ## How It Works
84
+
85
+ An Assertor essentially sits in wait for a method call (via
86
+ method_missing). When that happens it applies the method to the
87
+ original receiver, but wrapped in a clause that raises an
88
+ Assertion should the statement fail. If we wanted to be
89
+ pedantic, we could write our assertions like:
90
+
91
+ raise Assertion.new("1 != 1") unless 1 == 1
92
+
93
+ Instead of
94
+
95
+ 1.assert == 1
96
+
97
+ Obviously using Assertor methods are whole lot more concise.
98
+