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,217 @@
|
|
|
1
|
+
= MiniTest Compatible Extensions
|
|
2
|
+
|
|
3
|
+
require 'assay/minitest'
|
|
4
|
+
|
|
5
|
+
class ::Object
|
|
6
|
+
include ::Assay::Extensions
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
== must_be
|
|
10
|
+
|
|
11
|
+
1.must_be(:<, 2)
|
|
12
|
+
1.must_be(:odd?)
|
|
13
|
+
|
|
14
|
+
expect ::ExecutionAssay do
|
|
15
|
+
1.wont_be(:<, 2)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
1.wont_be(:>, 2)
|
|
19
|
+
1.wont_be(:even?)
|
|
20
|
+
|
|
21
|
+
== must_equal
|
|
22
|
+
|
|
23
|
+
1.must_equal(1)
|
|
24
|
+
|
|
25
|
+
expect ::EqualAssay do
|
|
26
|
+
1.must_equal(2)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
1.wont_equal(2)
|
|
30
|
+
|
|
31
|
+
== TrueAssay
|
|
32
|
+
|
|
33
|
+
true.must_be_true
|
|
34
|
+
|
|
35
|
+
expect ::TrueAssay do
|
|
36
|
+
false.must_be_true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
false.wont_be_true
|
|
40
|
+
|
|
41
|
+
== must_be_false
|
|
42
|
+
|
|
43
|
+
false.must_be_false
|
|
44
|
+
|
|
45
|
+
expect ::FalseAssay do
|
|
46
|
+
true.must_be_false
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
true.wont_be_false
|
|
50
|
+
|
|
51
|
+
== must_be_nil
|
|
52
|
+
|
|
53
|
+
nil.must_be_nil
|
|
54
|
+
|
|
55
|
+
expect ::NilAssay do
|
|
56
|
+
true.must_be_nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
false.wont_be_nil
|
|
60
|
+
|
|
61
|
+
== must_be_empty
|
|
62
|
+
|
|
63
|
+
[].must_be_empty
|
|
64
|
+
|
|
65
|
+
expect ::EmptyAssay do
|
|
66
|
+
[1].must_be_empty
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
[1].wont_be_empty
|
|
70
|
+
|
|
71
|
+
== must_include
|
|
72
|
+
|
|
73
|
+
[1].must_include(1)
|
|
74
|
+
|
|
75
|
+
expect ::IncludeAssay do
|
|
76
|
+
[1].must_include(2)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
[1].wont_include(2)
|
|
80
|
+
|
|
81
|
+
== must_be_within_delta
|
|
82
|
+
|
|
83
|
+
1.must_be_within_delta(2, 1.5)
|
|
84
|
+
|
|
85
|
+
expect ::WithinAssay do
|
|
86
|
+
1.must_be_within_delta(2, 0.5)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
1.wont_be_within_delta(2, 0.5)
|
|
90
|
+
|
|
91
|
+
== must_match
|
|
92
|
+
|
|
93
|
+
"abc".must_match(/a/)
|
|
94
|
+
|
|
95
|
+
expect ::MatchAssay do
|
|
96
|
+
"abc".must_match(/x/)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
"abc".wont_match(/g/)
|
|
100
|
+
|
|
101
|
+
== must_eql
|
|
102
|
+
|
|
103
|
+
1.must_eql(1)
|
|
104
|
+
|
|
105
|
+
expect ::EqualityAssay do
|
|
106
|
+
1.must_eql(1.0)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
1.wont_eql(1.0)
|
|
110
|
+
|
|
111
|
+
== must_be_same_as
|
|
112
|
+
|
|
113
|
+
:a.must_be_same_as(:a)
|
|
114
|
+
|
|
115
|
+
expect ::IdentityAssay do
|
|
116
|
+
"a".must_be_same_as("a")
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
:a.wont_be_same_as('a')
|
|
120
|
+
|
|
121
|
+
== must_be_instance_of
|
|
122
|
+
|
|
123
|
+
1.must_be_instance_of(Integer)
|
|
124
|
+
|
|
125
|
+
expect ::InstanceAssay do
|
|
126
|
+
1.must_be_instance_of(String)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
1.wont_be_instance_of(String)
|
|
130
|
+
|
|
131
|
+
== must_kind_of
|
|
132
|
+
|
|
133
|
+
1.must_be_kind_of(Integer)
|
|
134
|
+
|
|
135
|
+
expect ::KindAssay do
|
|
136
|
+
1.must_be_kind_of(String)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
1.wont_be_kind_of(String)
|
|
140
|
+
|
|
141
|
+
== must_raise
|
|
142
|
+
|
|
143
|
+
procedure = lambda{ raise ::ArgumentError }
|
|
144
|
+
|
|
145
|
+
procedure.must_raise(::ArgumentError)
|
|
146
|
+
|
|
147
|
+
expect ::RaiseAssay do
|
|
148
|
+
procedure.must_raise(::TypeError)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
procedure.wont_raise(::TypeError)
|
|
152
|
+
|
|
153
|
+
== must_respond_to
|
|
154
|
+
|
|
155
|
+
"string".must_respond_to(:upcase)
|
|
156
|
+
|
|
157
|
+
expect ::RespondAssay do
|
|
158
|
+
"string".must_respond_to(:not_a_method)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
"string".wont_respond_to(:not_a_method)
|
|
162
|
+
|
|
163
|
+
== must_satisfy
|
|
164
|
+
|
|
165
|
+
5.must_satisfy{ |x| x > 3 }
|
|
166
|
+
|
|
167
|
+
expect ::ExecutionAssay do
|
|
168
|
+
5.must_satisfy{ |x| x < 3 }
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
5.wont_satisfy{ |x| x < 3 }
|
|
172
|
+
|
|
173
|
+
== must_send
|
|
174
|
+
|
|
175
|
+
5.must_send([:+, 1])
|
|
176
|
+
|
|
177
|
+
expect ::ExecutionAssay do
|
|
178
|
+
5.must_send([:upcase])
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
5.wont_send([:upcase])
|
|
182
|
+
|
|
183
|
+
== must_throw
|
|
184
|
+
|
|
185
|
+
procedure = lambda{ throw :foo }
|
|
186
|
+
|
|
187
|
+
procedure.must_throw(:foo)
|
|
188
|
+
|
|
189
|
+
expect ::ThrowAssay do
|
|
190
|
+
procedure.must_throw(:bar)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
procedure.wont_throw(:bar)
|
|
194
|
+
|
|
195
|
+
== must_output
|
|
196
|
+
|
|
197
|
+
procedure = lambda{ puts "fun!" }
|
|
198
|
+
|
|
199
|
+
procedure.must_output('fun!')
|
|
200
|
+
|
|
201
|
+
expect ::OutputAssay do
|
|
202
|
+
procedure.must_output('not!')
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
== must_be_like
|
|
206
|
+
|
|
207
|
+
The `#must_be_like` method is not a MiniText expectation, but we have thrown it
|
|
208
|
+
in for gooe measure.
|
|
209
|
+
|
|
210
|
+
/a/.must_be_like('a')
|
|
211
|
+
|
|
212
|
+
expect ::LikeAssay do
|
|
213
|
+
'a'.must_be_like(10)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
'a'.wont_be_like(10)
|
|
217
|
+
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
= Assertion Methods
|
|
2
|
+
|
|
3
|
+
require 'assay/minitest'
|
|
4
|
+
|
|
5
|
+
include ::Assay::Assertions
|
|
6
|
+
|
|
7
|
+
== assert
|
|
8
|
+
|
|
9
|
+
assert(true, "yep it is so")
|
|
10
|
+
|
|
11
|
+
expect ::Assertion do
|
|
12
|
+
assert(false, "yep it is so")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
refute(false, "not on you life")
|
|
16
|
+
|
|
17
|
+
== assert_boolean
|
|
18
|
+
|
|
19
|
+
assert_boolean(true)
|
|
20
|
+
assert_boolean(false)
|
|
21
|
+
|
|
22
|
+
refute_boolean(nil)
|
|
23
|
+
refute_boolean(:foo)
|
|
24
|
+
|
|
25
|
+
== assert_equal
|
|
26
|
+
|
|
27
|
+
assert_equal(1,1)
|
|
28
|
+
|
|
29
|
+
expect ::EqualAssay do
|
|
30
|
+
assert_equal(1,2)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
refute_equal(1,2)
|
|
34
|
+
|
|
35
|
+
== assert_true
|
|
36
|
+
|
|
37
|
+
assert_true(true)
|
|
38
|
+
|
|
39
|
+
expect ::TrueAssay do
|
|
40
|
+
assert_true(false)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
refute_true(false)
|
|
44
|
+
|
|
45
|
+
== assert_false
|
|
46
|
+
|
|
47
|
+
assert_false(false)
|
|
48
|
+
|
|
49
|
+
expect ::FalseAssay do
|
|
50
|
+
assert_false(true)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
refute_false(true)
|
|
54
|
+
|
|
55
|
+
== assert_nil
|
|
56
|
+
|
|
57
|
+
assert_nil(nil)
|
|
58
|
+
|
|
59
|
+
expect ::NilAssay do
|
|
60
|
+
assert_nil(true)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
refute_nil(true)
|
|
64
|
+
refute_nil(false)
|
|
65
|
+
|
|
66
|
+
== assert_in_delta
|
|
67
|
+
|
|
68
|
+
assert_in_delta(1, 1.5, 0.5)
|
|
69
|
+
|
|
70
|
+
expect ::WithinAssay do
|
|
71
|
+
assert_in_delta(1, 2.5, 1)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
refute_in_delta(1, 2.5, 1)
|
|
75
|
+
|
|
76
|
+
== assert_in_epsilon
|
|
77
|
+
|
|
78
|
+
assert_in_epsilon(1, 1.5, 2)
|
|
79
|
+
|
|
80
|
+
expect ::CloseAssay do
|
|
81
|
+
assert_in_epsilon(1, 2.5, 1)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
refute_in_epsilon(1, 2.5, 1)
|
|
85
|
+
|
|
86
|
+
== assert_match
|
|
87
|
+
|
|
88
|
+
assert_match(/a/, "abc")
|
|
89
|
+
|
|
90
|
+
expect ::MatchAssay do
|
|
91
|
+
assert_match(/x/, "abc")
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
refute_match(/a/, "bcd")
|
|
95
|
+
|
|
96
|
+
== assert_no_match
|
|
97
|
+
|
|
98
|
+
assert_no_match(/a/, "bcd")
|
|
99
|
+
|
|
100
|
+
expect ::MatchAssay do
|
|
101
|
+
assert_no_match(/a/, "abc")
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
== assert_operator
|
|
105
|
+
|
|
106
|
+
assert_operator(3, :<, 4)
|
|
107
|
+
|
|
108
|
+
expect ::ExecutionAssay do
|
|
109
|
+
assert_operator(4, :<, 3)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
refute_operator(4, :<, 3)
|
|
113
|
+
|
|
114
|
+
== assert_equivalent
|
|
115
|
+
|
|
116
|
+
assert_equivalent(1, 1)
|
|
117
|
+
|
|
118
|
+
expect ::EqualityAssay do
|
|
119
|
+
assert_equivalent(1, 1.0)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
refute_equivalent(1, 1.0)
|
|
123
|
+
|
|
124
|
+
== assert_empty
|
|
125
|
+
|
|
126
|
+
assert_empty([])
|
|
127
|
+
|
|
128
|
+
expect ::EmptyAssay do
|
|
129
|
+
assert_empty([1,2,3])
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
refute_empty([1,2,3])
|
|
133
|
+
|
|
134
|
+
== assert_include
|
|
135
|
+
|
|
136
|
+
assert_includes([1,2,3], 1)
|
|
137
|
+
|
|
138
|
+
expect ::IncludeAssay do
|
|
139
|
+
assert_includes([1,2,3], 4)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
refute_includes([1,2,3], 4)
|
|
143
|
+
|
|
144
|
+
== assert_same
|
|
145
|
+
|
|
146
|
+
assert_same(:a, :a)
|
|
147
|
+
|
|
148
|
+
expect ::IdentityAssay do
|
|
149
|
+
assert_same("a", "a")
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
refute_same(:a, :b)
|
|
153
|
+
|
|
154
|
+
== assert_instance_of
|
|
155
|
+
|
|
156
|
+
assert_instance_of(Integer, 1)
|
|
157
|
+
|
|
158
|
+
expect ::InstanceAssay do
|
|
159
|
+
assert_instance_of(String, 1)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
refute_instance_of(String, 1)
|
|
163
|
+
|
|
164
|
+
== assert_kind_of
|
|
165
|
+
|
|
166
|
+
assert_kind_of(Integer, 1)
|
|
167
|
+
|
|
168
|
+
expect ::KindAssay do
|
|
169
|
+
assert_kind_of(String, 1)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
refute_kind_of(String, 1)
|
|
173
|
+
|
|
174
|
+
== assert_raises
|
|
175
|
+
|
|
176
|
+
assert_raises(ArgumentError){ raise ArgumentError }
|
|
177
|
+
|
|
178
|
+
expect ::RaiseAssay do
|
|
179
|
+
assert_raises(ArgumentError){ raise TypeError }
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
refute_raises(ArgumentError){ raise TypeError }
|
|
183
|
+
|
|
184
|
+
== assert_nothing_raised
|
|
185
|
+
|
|
186
|
+
assert_nothing_raised{ 'good' }
|
|
187
|
+
|
|
188
|
+
expect ::RescueAssay do
|
|
189
|
+
assert_nothing_raised{ raise }
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
refute_nothing_raised{ raise }
|
|
193
|
+
|
|
194
|
+
== assert_respond_to
|
|
195
|
+
|
|
196
|
+
assert_respond_to("string", :upcase)
|
|
197
|
+
|
|
198
|
+
expect ::RespondAssay do
|
|
199
|
+
assert_respond_to("string", :not_a_method)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
refute_respond_to("string", :not_a_method)
|
|
203
|
+
|
|
204
|
+
== assert_block
|
|
205
|
+
|
|
206
|
+
assert_block{ :ok }
|
|
207
|
+
|
|
208
|
+
expect ::ExecutionAssay do
|
|
209
|
+
assert_block{ raise }
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
== assert_throws
|
|
213
|
+
|
|
214
|
+
assert_throws(:foo){ throw :foo }
|
|
215
|
+
|
|
216
|
+
expect ::ThrowAssay do
|
|
217
|
+
assert_throws(:foo){ throw :bar }
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
refute_throws(:foo){ throw :bar }
|
|
221
|
+
|
|
222
|
+
== assert_predicate
|
|
223
|
+
|
|
224
|
+
assert_predicate(10, :even?)
|
|
225
|
+
|
|
226
|
+
refute_predicate(10, :odd?)
|
|
227
|
+
|
|
228
|
+
== assert_output
|
|
229
|
+
|
|
230
|
+
assert_output('this'){ puts 'this' }
|
|
231
|
+
|
|
232
|
+
refute_output('this'){ puts 'that' }
|
|
233
|
+
|
|
234
|
+
== assert_silent
|
|
235
|
+
|
|
236
|
+
assert_silent{ nil }
|
|
237
|
+
|
|
238
|
+
refute_silent{ puts 'that' }
|
|
239
|
+
|
|
240
|
+
== assert_alike
|
|
241
|
+
|
|
242
|
+
assert_alike(1,1)
|
|
243
|
+
assert_alike(1,1.0)
|
|
244
|
+
|
|
245
|
+
expect ::LikeAssay do
|
|
246
|
+
assert_alike(1,"1")
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
refute_alike(1,"1")
|
|
250
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# RSpec Notation
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
First we need to require the library.
|
|
6
|
+
|
|
7
|
+
require 'assay/rspec'
|
|
8
|
+
|
|
9
|
+
This loads Assay and adds `#should` and `#should_not` to `BasicObject`.
|
|
10
|
+
The matcher methods are in the module `Assay::RSpec::Matchers`, which
|
|
11
|
+
is also included into `Assay::Matchers`. To use them, include either
|
|
12
|
+
module into the test scope.
|
|
13
|
+
|
|
14
|
+
include Assay::Matchers
|
|
15
|
+
|
|
16
|
+
With that in place, we are ready to use the matchers.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
## RSpec Should Method
|
|
2
|
+
|
|
3
|
+
### should
|
|
4
|
+
|
|
5
|
+
Becuase the `#should` method used `=~` as the assertion operator,
|
|
6
|
+
you can do something a bit unexpected, such as,
|
|
7
|
+
|
|
8
|
+
'a'.should /a/
|
|
9
|
+
|
|
10
|
+
### should=
|
|
11
|
+
|
|
12
|
+
As a shortcut one can also use the `#should=` method instead of
|
|
13
|
+
the usual two-step `should ==` call.
|
|
14
|
+
|
|
15
|
+
10.should = 10
|
|
16
|
+
|
|
17
|
+
assert_raises ::EqualAssay do
|
|
18
|
+
10.should = 20
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
The same is true for `#should_not`.
|
|
22
|
+
|
|
23
|
+
10.should_not = 20
|
|
24
|
+
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
## RSpec Matchers
|
|
2
|
+
|
|
3
|
+
### should equal
|
|
4
|
+
|
|
5
|
+
1.should = 1
|
|
6
|
+
|
|
7
|
+
assert_raises ::EqualAssay do
|
|
8
|
+
1.should = 2
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
### be_true
|
|
12
|
+
|
|
13
|
+
true.should be_true
|
|
14
|
+
|
|
15
|
+
assert_raises ::TrueAssay do
|
|
16
|
+
false.should be_true
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
### be_false
|
|
20
|
+
|
|
21
|
+
false.should be_false
|
|
22
|
+
|
|
23
|
+
assert_raises ::FalseAssay do
|
|
24
|
+
true.should be_false
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
### be_nil
|
|
28
|
+
|
|
29
|
+
nil.should be_nil
|
|
30
|
+
|
|
31
|
+
assert_raises ::NilAssay do
|
|
32
|
+
true.should be_nil
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
### be_empty
|
|
36
|
+
|
|
37
|
+
[].should be_empty
|
|
38
|
+
|
|
39
|
+
assert_raises ::EmptyAssay do
|
|
40
|
+
[1].should be_empty
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
[1].should_not be_empty
|
|
44
|
+
|
|
45
|
+
### be_close
|
|
46
|
+
|
|
47
|
+
1.should be_close(1.5, 2)
|
|
48
|
+
|
|
49
|
+
assert_raises ::WithinAssay do
|
|
50
|
+
1.should be_close(0.5, 2)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
1.should_not be_close(0.5, 2)
|
|
54
|
+
|
|
55
|
+
### match
|
|
56
|
+
|
|
57
|
+
"abc".should match(/a/)
|
|
58
|
+
|
|
59
|
+
assert_raises ::MatchAssay do
|
|
60
|
+
"abc".should match(/x/)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
"abc".should_not match(/g/)
|
|
64
|
+
|
|
65
|
+
### eql
|
|
66
|
+
|
|
67
|
+
1.should eql(1)
|
|
68
|
+
|
|
69
|
+
assert_raises ::EqualityAssay do
|
|
70
|
+
1.should eql(1.0)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
1.should_not eql(1.0)
|
|
74
|
+
|
|
75
|
+
### equal
|
|
76
|
+
|
|
77
|
+
:a.should equal(:a)
|
|
78
|
+
|
|
79
|
+
assert_raises ::IdentityAssay do
|
|
80
|
+
"a".should equal("a")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
:a.should_not equal('a')
|
|
84
|
+
|
|
85
|
+
### be_instance_of
|
|
86
|
+
|
|
87
|
+
1.should be_instance_of(Integer)
|
|
88
|
+
|
|
89
|
+
assert_raises ::InstanceAssay do
|
|
90
|
+
1.should be_instance_of(String)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
1.should_not be_instance_of(String)
|
|
94
|
+
|
|
95
|
+
### be_kind_of
|
|
96
|
+
|
|
97
|
+
1.should be_kind_of(Integer)
|
|
98
|
+
|
|
99
|
+
assert_raises ::KindAssay do
|
|
100
|
+
1.should be_kind_of(String)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
1.should_not be_kind_of(String)
|
|
104
|
+
|
|
105
|
+
### raise_error
|
|
106
|
+
|
|
107
|
+
procedure = lambda{ raise ::ArgumentError }
|
|
108
|
+
|
|
109
|
+
procedure.should raise_error(::ArgumentError)
|
|
110
|
+
|
|
111
|
+
assert_raises ::RaiseAssay do
|
|
112
|
+
procedure.should raise_error(::TypeError)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
procedure.should_not raise_error(::TypeError)
|
|
116
|
+
|
|
117
|
+
### respond_to
|
|
118
|
+
|
|
119
|
+
"string".should respond_to(:upcase)
|
|
120
|
+
|
|
121
|
+
assert_raises ::RespondAssay do
|
|
122
|
+
"string".should respond_to(:not_a_method)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
"string".should_not respond_to(:not_a_method)
|
|
126
|
+
|
|
127
|
+
### satisfy
|
|
128
|
+
|
|
129
|
+
5.should satisfy{ |x| x > 3 }
|
|
130
|
+
|
|
131
|
+
assert_raises ::ExecutionAssay do
|
|
132
|
+
5.should satisfy{ |x| x < 3 }
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
5.should_not satisfy{ |x| x < 3 }
|
|
136
|
+
|
|
137
|
+
### throw_symbol
|
|
138
|
+
|
|
139
|
+
procedure = lambda{ throw :foo }
|
|
140
|
+
|
|
141
|
+
procedure.should throw_symbol(:foo)
|
|
142
|
+
|
|
143
|
+
assert_raises ::ThrowAssay do
|
|
144
|
+
procedure.should throw_symbol(:bar)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
procedure.should_not throw_symbol(:bar)
|
|
148
|
+
|
|
149
|
+
## Supplemental Matchers
|
|
150
|
+
|
|
151
|
+
### equate_to
|
|
152
|
+
|
|
153
|
+
This is not strictly an RSpec matcher, but we have thrown it in for good measure.
|
|
154
|
+
It is equivalent to using the `#should=` method.
|
|
155
|
+
|
|
156
|
+
10.should equate_to(10)
|
|
157
|
+
|
|
158
|
+
assert_raises ::EqualityAssay do
|
|
159
|
+
10.should equate_to(10.0)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
10.should_not equate_to(10.0)
|
|
163
|
+
|
|
164
|
+
### be_like
|
|
165
|
+
|
|
166
|
+
The `#be_like` matcher is not strictly an RSpec matcher, but we have thrown it
|
|
167
|
+
in for good measure.
|
|
168
|
+
|
|
169
|
+
/a/.should be_like('a')
|
|
170
|
+
|
|
171
|
+
assert_raises ::LikeAssay do
|
|
172
|
+
/a/.should be_like('b')
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
/a/.should_not be_like('b')
|
|
176
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
### Have
|
|
2
|
+
|
|
3
|
+
The `#have` matchers make it easy to set expectations about the size
|
|
4
|
+
of a collection. In general the term `items` is used if the target
|
|
5
|
+
object is a collection.
|
|
6
|
+
|
|
7
|
+
a = [1, 2, 3]
|
|
8
|
+
|
|
9
|
+
a.should have(3).items
|
|
10
|
+
a.should_not have(2).items
|
|
11
|
+
a.should_not have(4).items
|
|
12
|
+
|
|
13
|
+
a.should have_exactly(3).items
|
|
14
|
+
a.should_not have_exactly(2).items
|
|
15
|
+
a.should_not have_exactly(4).items
|
|
16
|
+
|
|
17
|
+
a.should have_at_least(2).items
|
|
18
|
+
a.should have_at_most(4).items
|
|
19
|
+
|
|
20
|
+
But a method that returns a collection can be used instead.
|
|
21
|
+
|
|
22
|
+
class ::String
|
|
23
|
+
def words
|
|
24
|
+
split(' ')
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
s = "a sentence with some words"
|
|
29
|
+
|
|
30
|
+
s.should have(5).words
|
|
31
|
+
s.should_not have(4).words
|
|
32
|
+
s.should_not have(6).words
|
|
33
|
+
|
|
34
|
+
s.should have_exactly(5).words
|
|
35
|
+
s.should_not have_exactly(4).words
|
|
36
|
+
s.should_not have_exactly(6).words
|
|
37
|
+
|
|
38
|
+
s.should have_at_least(4).words
|
|
39
|
+
s.should have_at_most(6).words
|
|
40
|
+
|
|
41
|
+
Besides `#have` there is also `#have_at_least` and `#have_at_most`.
|
|
42
|
+
|
|
43
|
+
a = [1, 2, 3]
|
|
44
|
+
|
|
45
|
+
a.should have_at_least(2).items
|
|
46
|
+
a.should have_at_most(4).items
|
|
47
|
+
|
|
48
|
+
a.should have_at_least(3).items
|
|
49
|
+
a.should have_at_most(3).items
|
|
50
|
+
|
|
51
|
+
|