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
@@ -10,11 +10,9 @@ module Kernel
10
10
  object_id == other.object_id
11
11
  end
12
12
 
13
- # Ascertain likeness, returns true if any of `equal?`, `eql?`, `==`,
14
- # `===` or `=~` evaluate truthfully, either with `self` as the receiver
15
- # or `other` as the receiver.
16
- #
17
- # @todo Should `#=~` be apart of this comparison?
13
+ # Ascertain likeness, returns true if any of `equal?`, `eql?`, `==` or
14
+ # `===` evaluate truthfully, either with `self` as the receiver or
15
+ # `other` as the receiver.
18
16
  #
19
17
  # @param [Object] other
20
18
  # Any object reference.
@@ -26,12 +24,10 @@ module Kernel
26
24
  self.eql?(other) ||
27
25
  self.==(other) ||
28
26
  self.===(other) ||
29
- self.=~(other) ||
30
27
  other.equal?(self) ||
31
28
  other.eql?(self) ||
32
29
  other.==(self) ||
33
- other.===(self) ||
34
- other.=~(self)
30
+ other.===(self) ? true : false
35
31
  end
36
32
 
37
33
  #
@@ -0,0 +1,27 @@
1
+ require_relative 'grammar'
2
+
3
+ class Object
4
+
5
+ # Use `assert` nomenclature for assertions.
6
+ #
7
+ # 10.assert.kind_of?(Integer)
8
+ #
9
+ def assert(*args, &blk)
10
+ return ::Assay::Fluidity::Grammar::Assert.new(self) if args.empty?
11
+
12
+ matcher = args.first
13
+
14
+ if ::Assay::Assertor === matcher
15
+ matcher =~ self
16
+ else
17
+ super(*args, &blk)
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+
24
+ module Kernel
25
+ public :assert
26
+ public :refute
27
+ end
@@ -0,0 +1,157 @@
1
+ require_relative '../../assay'
2
+
3
+ module Assay; end
4
+ module Assay::Fluidity
5
+
6
+ module Grammar
7
+
8
+ # The grammar classes are built on BasicObject, so that a method every
9
+ # object has, such as `kind_of?`, `nil?` or `eql?`, makes an assertion
10
+ # about the target rather than being answered by the grammar object.
11
+ class Base < ::BasicObject
12
+
13
+ # BasicObject has a few public methods of its own. Making them private
14
+ # sends them through #method_missing like any other.
15
+ private :!, :equal?, :instance_eval, :instance_exec
16
+
17
+ def initialize(target, negate=false)
18
+ @target = target
19
+ @negate = negate
20
+ end
21
+
22
+ # Have to override the ususal `#==` method to support this.
23
+ def ==(other)
24
+ if @negate
25
+ ::EqualAssay.refute!(@target, other, :backtrace=>::Kernel.caller)
26
+ else
27
+ ::EqualAssay.assert!(@target, other, :backtrace=>::Kernel.caller)
28
+ end
29
+ end
30
+
31
+ # Likewise for `#!=`.
32
+ def !=(other)
33
+ if @negate
34
+ ::UnequalAssay.refute!(@target, other, :backtrace=>::Kernel.caller)
35
+ else
36
+ ::UnequalAssay.assert!(@target, other, :backtrace=>::Kernel.caller)
37
+ end
38
+ end
39
+
40
+ def method_missing(s, *a, **kw, &b)
41
+ if assay = (::Assertion.by_name(s) || ::Assertion.by_operator(s))
42
+ a << kw unless kw.empty?
43
+ if @negate
44
+ assay.refute!(@target, *a, {:backtrace=>::Kernel.caller}, &b)
45
+ else
46
+ assay.assert!(@target, *a, {:backtrace=>::Kernel.caller}, &b)
47
+ end
48
+ else
49
+ q = (s.to_s.end_with?('?') ? s : (s.to_s+'?'))
50
+ if @target.respond_to?(q)
51
+ truth = @target.__send__(q, *a, **kw, &b)
52
+ args = (a.map{ |x| x.inspect } + kw.map{ |k,v| "#{k}: #{v.inspect}" }).join(', ')
53
+ call = "#{@target.inspect}.#{q}" + (args.empty? ? '' : "(#{args})")
54
+ if @negate
55
+ ::Kernel.assert(!truth, ::Assertion, "! #{call}", ::Kernel.caller)
56
+ else
57
+ ::Kernel.assert(truth, ::Assertion, call, ::Kernel.caller)
58
+ end
59
+ else
60
+ super
61
+ end
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ #
68
+ class Assert < Base
69
+
70
+ #def method_missing(s, *a, &b)
71
+ # call(s, *a, &b)
72
+ #end
73
+
74
+ def not
75
+ Assert.new(@target, !@negate)
76
+ end
77
+
78
+ end
79
+
80
+ #
81
+ class Be < Base
82
+
83
+ #def method_missing(s, *a, &b)
84
+ # call(s, *a, &b)
85
+ #end
86
+
87
+ #
88
+ def a
89
+ self
90
+ end
91
+
92
+ #
93
+ def an
94
+ self
95
+ end
96
+
97
+ end
98
+
99
+ #
100
+ class Is < Be
101
+
102
+ def not
103
+ Is.new(@target, !@negate)
104
+ end
105
+
106
+ end
107
+
108
+ #
109
+ class Must < Base
110
+
111
+ #def method_missing(s, *a, &b)
112
+ # call(s, *a, &b)
113
+ #end
114
+
115
+ def be
116
+ Be.new(@target, @negate)
117
+ end
118
+
119
+ def not
120
+ Must.new(@target, !@negate)
121
+ end
122
+
123
+ end
124
+
125
+ #
126
+ class Will < Base
127
+
128
+ def be
129
+ Be.new(@target, @negate)
130
+ end
131
+
132
+ def not
133
+ Will.new(@target, !@negate)
134
+ end
135
+
136
+ end
137
+
138
+ #
139
+ class Should < Base
140
+
141
+ #def method_missing(s, *a, &b)
142
+ # call(s, *a, &b)
143
+ #end
144
+
145
+ def be
146
+ Be.new(@target, @negate)
147
+ end
148
+
149
+ def not
150
+ Should.new(@target, !@negate)
151
+ end
152
+
153
+ end
154
+
155
+ end
156
+
157
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'grammar'
2
+
3
+ class Object #BasicObject
4
+
5
+ # Use `is` nomenclature for assertions.
6
+ #
7
+ # 10.is.kind_of?(Integer)
8
+ #
9
+ def is(matcher=nil)
10
+ if matcher
11
+ matcher === self
12
+ else
13
+ ::Assay::Fluidity::Grammar::Is.new(self)
14
+ end
15
+ end
16
+
17
+ end
18
+
@@ -0,0 +1,38 @@
1
+ require_relative 'grammar'
2
+
3
+ # TODO: What about BasicObject ?
4
+
5
+ class Object #BasicObject
6
+
7
+ # Use `must` nomenclature for assertions.
8
+ #
9
+ # 10.must.be.kind_of(Integer)
10
+ #
11
+ def must(matcher=nil)
12
+ if matcher
13
+ matcher =~ self
14
+ else
15
+ ::Assay::Fluidity::Grammar::Must.new(self)
16
+ end
17
+ end
18
+
19
+ # Also, `must_not` nomenclature for assertions.
20
+ #
21
+ # 10.must_not.be.kind_of?(Integer)
22
+ #
23
+ def must_not(matcher=nil)
24
+ if matcher
25
+ matcher !~ self
26
+ else
27
+ ::Assay::Fluidity::Grammar::Must.new(self, true)
28
+ end
29
+ end
30
+
31
+ # Contraction do must not.
32
+ #
33
+ # 10.mustnt.be.kind_of?(Integer)
34
+ #
35
+ alias_method :mustnt, :must_not
36
+
37
+ end
38
+
@@ -0,0 +1,32 @@
1
+ require_relative 'grammar'
2
+
3
+ class Object #BasicObject
4
+
5
+ # Use `should` nomenclature for assertions.
6
+ #
7
+ # 10.should.be.kind_of(Integer)
8
+ #
9
+ def should(matcher=nil)
10
+ if matcher
11
+ matcher =~ self
12
+ else
13
+ ::Assay::Fluidity::Grammar::Should.new(self)
14
+ end
15
+ end
16
+
17
+ # Also, `should_not` nomenclature for assertions.
18
+ #
19
+ # 10.should_not.be.kind_of?(Integer)
20
+ #
21
+ def should_not(matcher=nil)
22
+ if matcher
23
+ matcher !~ self
24
+ else
25
+ ::Assay::Fluidity::Grammar::Should.new(self, true)
26
+ end
27
+ end
28
+
29
+ alias_method :shouldnt, :should_not
30
+
31
+ end
32
+
@@ -0,0 +1,36 @@
1
+ require_relative 'grammar'
2
+
3
+ class Object #BasicObject
4
+
5
+ # Use `will` nomenclature for assertions.
6
+ #
7
+ # 10.will.be.kind_of(Integer)
8
+ #
9
+ def will(matcher=nil)
10
+ if matcher
11
+ matcher =~ self
12
+ else
13
+ ::Assay::Fluidity::Grammar::Will.new(self)
14
+ end
15
+ end
16
+
17
+ # Also, `will_not` nomenclature for assertions.
18
+ #
19
+ # 10.will_not.be.kind_of?(Integer)
20
+ #
21
+ def will_not(matcher=nil)
22
+ if matcher
23
+ matcher !~ self
24
+ else
25
+ ::Assay::Fluidity::Grammar::Will.new(self, true)
26
+ end
27
+ end
28
+
29
+ # Contraction of will not.
30
+ #
31
+ # 10.wont.be.kind_of?(Integer)
32
+ #
33
+ alias_method :wont, :will_not
34
+
35
+ end
36
+
@@ -0,0 +1,6 @@
1
+ require_relative '../assay'
2
+
3
+ require_relative 'fluidity/grammar'
4
+ require_relative 'fluidity/should'
5
+ require_relative 'fluidity/must'
6
+ require_relative 'fluidity/assert'
@@ -14,5 +14,11 @@ class LessAssay < CompareAssay
14
14
  subject < criterion
15
15
  end
16
16
 
17
- end
17
+ #
18
+ # Error message, e.g. `5 < 3`.
19
+ #
20
+ def self.assert_message(subject, criterion)
21
+ standard_message(subject, criterion)
22
+ end
18
23
 
24
+ end
@@ -21,5 +21,11 @@ class LessEqualAssay < CompareAssay
21
21
  subject <= criterion
22
22
  end
23
23
 
24
- end
24
+ #
25
+ # Error message, e.g. `5 <= 3`.
26
+ #
27
+ def self.assert_message(subject, criterion)
28
+ standard_message(subject, criterion)
29
+ end
25
30
 
31
+ end