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,201 @@
|
|
|
1
|
+
module Assay::RSpec
|
|
2
|
+
|
|
3
|
+
# Delegate to Have Assays.
|
|
4
|
+
#
|
|
5
|
+
class Have
|
|
6
|
+
|
|
7
|
+
attr :expected
|
|
8
|
+
|
|
9
|
+
attr :collection_name
|
|
10
|
+
|
|
11
|
+
attr :relation
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# Initialize new Have delegator.
|
|
15
|
+
#
|
|
16
|
+
def initialize(expected, relation=:exactly)
|
|
17
|
+
@expected = case expected
|
|
18
|
+
when :no then 0
|
|
19
|
+
when String then expected.to_i
|
|
20
|
+
else expected
|
|
21
|
+
end
|
|
22
|
+
@relation = relation
|
|
23
|
+
@collection_name = nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
# @param [#size,#length,#count] collection_or_owner
|
|
28
|
+
#
|
|
29
|
+
def collection(collection_or_owner)
|
|
30
|
+
if collection_or_owner.respond_to?(@collection_name)
|
|
31
|
+
collection_or_owner.__send__(@collection_name, *@args, &@block)
|
|
32
|
+
elsif query_method(collection_or_owner)
|
|
33
|
+
collection_or_owner
|
|
34
|
+
else
|
|
35
|
+
collection_or_owner.__send__(@collection_name, *@args, &@block)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#
|
|
40
|
+
#
|
|
41
|
+
#
|
|
42
|
+
def query_method(collection)
|
|
43
|
+
[:size, :length, :count].detect {|m| collection.respond_to?(m)}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#
|
|
47
|
+
#
|
|
48
|
+
#
|
|
49
|
+
def method_missing(method, *args, &block)
|
|
50
|
+
@collection_name = method
|
|
51
|
+
@args = args
|
|
52
|
+
@block = block
|
|
53
|
+
|
|
54
|
+
case @relation
|
|
55
|
+
when :at_least
|
|
56
|
+
Assay::RSpec::HaveAtLeastAssay.assertor(self)
|
|
57
|
+
when :at_most
|
|
58
|
+
Assay::RSpec::HaveAtMostAssay.assertor(self)
|
|
59
|
+
else
|
|
60
|
+
Assay::RSpec::HaveExactlyAssay.assertor(self)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
#
|
|
65
|
+
#
|
|
66
|
+
module Helpers
|
|
67
|
+
|
|
68
|
+
#
|
|
69
|
+
#
|
|
70
|
+
#
|
|
71
|
+
def collection_set(collection_or_owner, have)
|
|
72
|
+
collection = have.collection(collection_or_owner)
|
|
73
|
+
query_method = query_method(collection)
|
|
74
|
+
|
|
75
|
+
raise not_a_collection(have) unless query_method
|
|
76
|
+
|
|
77
|
+
actual = collection.__send__(query_method)
|
|
78
|
+
|
|
79
|
+
return collection, query_method, actual
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
# Return the actual size of the collection.
|
|
84
|
+
#
|
|
85
|
+
def collection_actual(collection_or_owner, have)
|
|
86
|
+
collection_set(collection_or_owner, have).last
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
#
|
|
90
|
+
# Which size method to use: `size`, `length` or `count`.
|
|
91
|
+
#
|
|
92
|
+
def query_method(collection)
|
|
93
|
+
[:size, :length, :count].detect {|m| collection.respond_to?(m)}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
#
|
|
97
|
+
# Message to use when collection doesn't respond to `size`, `length` or `count`.
|
|
98
|
+
#
|
|
99
|
+
def not_a_collection(have)
|
|
100
|
+
"expected #{have.collection_name} to be a collection but it does not respond to #length, #size or #count"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
#
|
|
104
|
+
# TODO: use when verbose error message mode
|
|
105
|
+
#
|
|
106
|
+
def self.assert_description(collection_or_owner, have)
|
|
107
|
+
collection, method, actual = collection_set(collection_or_owner, have)
|
|
108
|
+
"expected #{have.relation} #{have.expected} #{have.collection_name}, got #{actual}"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
#
|
|
112
|
+
#
|
|
113
|
+
#
|
|
114
|
+
def self.refute_descrptipon(collection_or_owner, have)
|
|
115
|
+
collection, method, actual = collection_set(collection_or_owner, have)
|
|
116
|
+
"expected not to have #{have.relation} #{have.expected} #{have.collection_name}, got #{actual}"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
#
|
|
124
|
+
#
|
|
125
|
+
class HaveExactlyAssay < EqualAssay
|
|
126
|
+
|
|
127
|
+
extend Have::Helpers
|
|
128
|
+
|
|
129
|
+
register :have
|
|
130
|
+
|
|
131
|
+
#
|
|
132
|
+
#
|
|
133
|
+
#
|
|
134
|
+
def self.pass?(collection_or_owner, have)
|
|
135
|
+
actual = collection_actual(collection_or_owner, have)
|
|
136
|
+
super(actual, have.expected)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
#
|
|
140
|
+
# Error message for have equal assertion.
|
|
141
|
+
#
|
|
142
|
+
def self.assert_message(collection_or_owner, have)
|
|
143
|
+
actual = collection_actual(collection_or_owner, have)
|
|
144
|
+
super(actual, have.expected)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
#
|
|
150
|
+
#
|
|
151
|
+
class HaveAtLeastAssay < MoreEqualAssay
|
|
152
|
+
|
|
153
|
+
extend Have::Helpers
|
|
154
|
+
|
|
155
|
+
register :have_at_least
|
|
156
|
+
|
|
157
|
+
#
|
|
158
|
+
#
|
|
159
|
+
#
|
|
160
|
+
def self.pass?(collection_or_owner, have)
|
|
161
|
+
actual = collection_actual(collection_or_owner, have)
|
|
162
|
+
super(actual, have.expected)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
#
|
|
166
|
+
#
|
|
167
|
+
#
|
|
168
|
+
def self.assert_message(collection_or_owner, have)
|
|
169
|
+
actual = collection_actual(collection_or_owner, have)
|
|
170
|
+
super(actual, have.expected)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
#
|
|
176
|
+
#
|
|
177
|
+
class HaveAtMostAssay < LessEqualAssay
|
|
178
|
+
|
|
179
|
+
extend Have::Helpers
|
|
180
|
+
|
|
181
|
+
register :have_at_most
|
|
182
|
+
|
|
183
|
+
#
|
|
184
|
+
#
|
|
185
|
+
#
|
|
186
|
+
def self.pass?(collection_or_owner, have)
|
|
187
|
+
actual = collection_actual(collection_or_owner, have)
|
|
188
|
+
super(actual, have.expected)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
#
|
|
192
|
+
#
|
|
193
|
+
#
|
|
194
|
+
def self.assert_message(collection_or_owner, have)
|
|
195
|
+
actual = collection_actual(collection_or_owner, have)
|
|
196
|
+
super(actual, have.expected)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
end
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
module Assay; end
|
|
2
|
+
module Assay::RSpec
|
|
3
|
+
|
|
4
|
+
# This module provides matchers for RSpec-compatiblity.
|
|
5
|
+
#
|
|
6
|
+
# The set is not fully compataible, but provides most RSpec matchers.
|
|
7
|
+
# The most notable exlusion for the moment is the `have` matchers.
|
|
8
|
+
#
|
|
9
|
+
# Compatability will improve with time. Feel _obligated_ to submit a
|
|
10
|
+
# patch if you really need it. ;)
|
|
11
|
+
#
|
|
12
|
+
# @see https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
|
13
|
+
#
|
|
14
|
+
module Matchers
|
|
15
|
+
|
|
16
|
+
#def self.included(base)
|
|
17
|
+
# @_once ||= require_relative('should').nil?
|
|
18
|
+
#end
|
|
19
|
+
|
|
20
|
+
#def self.extended(base)
|
|
21
|
+
# @_once ||= require_relative('should').nil?
|
|
22
|
+
#end
|
|
23
|
+
|
|
24
|
+
# Passes if the expected and actual are alike.
|
|
25
|
+
#
|
|
26
|
+
# object.should be_like(criterion)
|
|
27
|
+
#
|
|
28
|
+
# There is no equivalant for this in RSpec, we simply add it
|
|
29
|
+
# here to cover all Assays available.
|
|
30
|
+
#
|
|
31
|
+
# @raise LikeAssay
|
|
32
|
+
#
|
|
33
|
+
def be_like(criterion)
|
|
34
|
+
LikeAssay.assertor(criterion)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Passes if expected and actual are nto equal within delta tolerance.
|
|
38
|
+
#
|
|
39
|
+
# value.should be_close(delta, criterion)
|
|
40
|
+
#
|
|
41
|
+
# @raise WithinAssay
|
|
42
|
+
#
|
|
43
|
+
def be_close(delta, criterion)
|
|
44
|
+
WithinAssay.assertor(criterion, delta)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Passes if object is empty.
|
|
48
|
+
#
|
|
49
|
+
# object.should be_empty
|
|
50
|
+
#
|
|
51
|
+
# @raise EmptyAssay
|
|
52
|
+
#
|
|
53
|
+
def be_empty
|
|
54
|
+
EmptyAssay.assertor
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Passes if +expected+ == +actual+.
|
|
58
|
+
#
|
|
59
|
+
# 'MY STRING'.should equate_to('my string'.upcase)
|
|
60
|
+
# 'MY STRING'.should_not equate_to('another string')
|
|
61
|
+
#
|
|
62
|
+
# This matcher is not supported by RSpec, but is added so that the
|
|
63
|
+
# EqualityAssay has an explict matcher available.
|
|
64
|
+
#
|
|
65
|
+
# @raise EqualityAssay
|
|
66
|
+
#
|
|
67
|
+
def equate_to(exp)
|
|
68
|
+
EqualityAssay.assertor(exp)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
#
|
|
72
|
+
# Passes if block is satisfied given target object as argument.
|
|
73
|
+
#
|
|
74
|
+
# 5.should satisfy{ |n| n > 3}
|
|
75
|
+
#
|
|
76
|
+
# @raise ExecutionAssay
|
|
77
|
+
#
|
|
78
|
+
def satisfy(&block)
|
|
79
|
+
ExecutionAssay.assertor(&block)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
# Passed if object is +false+.
|
|
84
|
+
#
|
|
85
|
+
# value.should be_false
|
|
86
|
+
#
|
|
87
|
+
# @raise FalseAssay
|
|
88
|
+
#
|
|
89
|
+
def be_false
|
|
90
|
+
FalseAssay.assertor
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
#
|
|
94
|
+
# Passes if actual is the same exact object as expected.
|
|
95
|
+
#
|
|
96
|
+
# object.should be_identical_to(object)
|
|
97
|
+
#
|
|
98
|
+
# @raise IdentityAssay
|
|
99
|
+
#
|
|
100
|
+
def equal(obj)
|
|
101
|
+
IdentityAssay.assertor(obj)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
alias :be_identical_to :equal
|
|
105
|
+
|
|
106
|
+
#
|
|
107
|
+
# Passes if `actual == expected`.
|
|
108
|
+
#
|
|
109
|
+
# object.should eq(object)
|
|
110
|
+
#
|
|
111
|
+
# @raise EqualAssay
|
|
112
|
+
#
|
|
113
|
+
def eq(obj)
|
|
114
|
+
EqualAssay.assertor(obj)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#
|
|
118
|
+
# Passes if object is an instance of class.
|
|
119
|
+
#
|
|
120
|
+
# object.should be_instance_of(class)
|
|
121
|
+
#
|
|
122
|
+
# @raise InstanceAssay
|
|
123
|
+
#
|
|
124
|
+
def be_instance_of(cls)
|
|
125
|
+
InstanceAssay.assertor(cls)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
alias :be_an_instance_of :be_instance_of
|
|
129
|
+
|
|
130
|
+
#
|
|
131
|
+
# Pass if object is a kind of class.
|
|
132
|
+
#
|
|
133
|
+
# object.should be_kind_of(class)
|
|
134
|
+
#
|
|
135
|
+
# @raise KindAssay
|
|
136
|
+
#
|
|
137
|
+
def be_kind_of(cls)
|
|
138
|
+
KindAssay.assertor(cls)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
alias :be_a_kind_of :be_kind_of
|
|
142
|
+
alias :be_a :be_kind_of
|
|
143
|
+
alias :be_an :be_kind_of
|
|
144
|
+
|
|
145
|
+
#
|
|
146
|
+
# Pass if object matches pattern using `#=~` method.
|
|
147
|
+
#
|
|
148
|
+
# object.should match(regexp)
|
|
149
|
+
#
|
|
150
|
+
# @raise MatchAssay
|
|
151
|
+
#
|
|
152
|
+
def match(regexp)
|
|
153
|
+
MatchAssay.assertor(regexp)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
#
|
|
157
|
+
# Pass if object is +nil+.
|
|
158
|
+
#
|
|
159
|
+
# value.should be_nil
|
|
160
|
+
#
|
|
161
|
+
# @raise NilAssay
|
|
162
|
+
#
|
|
163
|
+
def be_nil
|
|
164
|
+
NilAssay.assertor
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
#
|
|
168
|
+
# Pass if an exception is raised.
|
|
169
|
+
#
|
|
170
|
+
# lambda { do_something_risky }.should raise_error
|
|
171
|
+
# lambda { do_something_risky }.should raise_error(PoorRiskDecisionError)
|
|
172
|
+
#
|
|
173
|
+
# @raise RaiseAssay
|
|
174
|
+
#
|
|
175
|
+
# @todo Support for message matching ?
|
|
176
|
+
#
|
|
177
|
+
def raise_error(exception=Exception)
|
|
178
|
+
RaiseAssay.assertor(exception)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
#
|
|
182
|
+
# Pass if object responds to message.
|
|
183
|
+
#
|
|
184
|
+
# object.should respond_to(:method_name)
|
|
185
|
+
#
|
|
186
|
+
# @raise RespondAssay
|
|
187
|
+
#
|
|
188
|
+
def respond_to(method)
|
|
189
|
+
RespondAssay.assertor(method)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
#
|
|
193
|
+
# Pass if two objects are equal using `#eql?` method.
|
|
194
|
+
#
|
|
195
|
+
# object1.should eql(object2)
|
|
196
|
+
#
|
|
197
|
+
# @raise EqualityAssay
|
|
198
|
+
#
|
|
199
|
+
def eql(exp)
|
|
200
|
+
EqualityAssay.assertor(exp)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
#
|
|
204
|
+
# Pass if procedure throws a specified symbol.
|
|
205
|
+
#
|
|
206
|
+
# lambda { do_something_risky }.should throw_symbol
|
|
207
|
+
# lambda { do_something_risky }.should throw_symbol(:that_was_risky)
|
|
208
|
+
#
|
|
209
|
+
# @raise ThrowAssay
|
|
210
|
+
#
|
|
211
|
+
# @todo Support for throw argument. (Does RSpec even support this?)
|
|
212
|
+
#
|
|
213
|
+
def throw_symbol(sym=nil) #, arg=nil)
|
|
214
|
+
ThrowAssay.assertor(sym)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
#
|
|
218
|
+
# Passed if object is +true+.
|
|
219
|
+
#
|
|
220
|
+
# object.should be_true
|
|
221
|
+
#
|
|
222
|
+
# @raise TrueAssay
|
|
223
|
+
#
|
|
224
|
+
def be_true
|
|
225
|
+
TrueAssay.assertor
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
#
|
|
229
|
+
#
|
|
230
|
+
#
|
|
231
|
+
def have(n)
|
|
232
|
+
Have.new(n)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
alias :have_exactly :have
|
|
236
|
+
|
|
237
|
+
#
|
|
238
|
+
#
|
|
239
|
+
#
|
|
240
|
+
def have_at_least(n)
|
|
241
|
+
Have.new(n, :at_least)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
#
|
|
245
|
+
#
|
|
246
|
+
#
|
|
247
|
+
def have_at_most(n)
|
|
248
|
+
Have.new(n, :at_most)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
#
|
|
252
|
+
# Wrap the target of an expectation, a value or a block.
|
|
253
|
+
#
|
|
254
|
+
# expect(actual).to eq(3)
|
|
255
|
+
# expect{ perform }.to raise_error(ArgumentError)
|
|
256
|
+
#
|
|
257
|
+
def expect(*target, &block)
|
|
258
|
+
case
|
|
259
|
+
when block && !target.empty?
|
|
260
|
+
raise ArgumentError, "expect takes a value or a block, not both"
|
|
261
|
+
when block
|
|
262
|
+
Expect.new(block)
|
|
263
|
+
when target.size == 1
|
|
264
|
+
Expect.new(target.first)
|
|
265
|
+
else
|
|
266
|
+
raise ArgumentError, "wrong number of arguments (given #{target.size}, expected 1)"
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Assay::RSpec
|
|
2
|
+
|
|
3
|
+
# Operatics delegates operator based assertions for execpt.rb.
|
|
4
|
+
#
|
|
5
|
+
# It is built on BasicObject, so that a word method such as `kind_of?`
|
|
6
|
+
# is an error rather than being answered by this object.
|
|
7
|
+
#
|
|
8
|
+
class Operatics < ::BasicObject
|
|
9
|
+
instance_methods.each{ |m| undef_method m if m.to_s =~ /^\W/ }
|
|
10
|
+
|
|
11
|
+
#
|
|
12
|
+
def initialize(target, negate=false)
|
|
13
|
+
@target = target
|
|
14
|
+
@negate = negate
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
#
|
|
20
|
+
def method_missing(op, *a, &b)
|
|
21
|
+
super(op, *a, &b) if op.to_s =~ /^\w/
|
|
22
|
+
|
|
23
|
+
if @negate
|
|
24
|
+
refute!(op, *a, &b)
|
|
25
|
+
else
|
|
26
|
+
assert!(op, *a, &b)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
def assert!(op, *a, &b)
|
|
32
|
+
if assay = ::Assertion.by_operator(op)
|
|
33
|
+
return assay.assert!(@target, *a, {:backtrace=>::Kernel.caller}, &b)
|
|
34
|
+
else
|
|
35
|
+
::Kernel.assert(@target.__send__(op, *a, &b), ::Assertion, "#{@target.inspect} #{op} #{a.map{ |x| x.inspect }.join(', ')}", ::Kernel.caller)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#
|
|
40
|
+
def refute!(op, *a, &b)
|
|
41
|
+
if assay = ::Assertion.by_operator(op)
|
|
42
|
+
return assay.refute!(@target, *a, {:backtrace=>::Kernel.caller}, &b)
|
|
43
|
+
else
|
|
44
|
+
::Kernel.refute(@target.__send__(op, *a, &b), ::Assertion, "! #{@target.inspect} #{op} #{a.map{ |x| x.inspect }.join(', ')}", ::Kernel.caller)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
#
|
|
49
|
+
def generic?(op)
|
|
50
|
+
@target.method(op).owner == ::Kernel
|
|
51
|
+
end if ::Method.method_defined?(:owner)
|
|
52
|
+
|
|
53
|
+
#
|
|
54
|
+
def generic?(op)
|
|
55
|
+
@target.method(op).to_s.include?('(Kernel)')
|
|
56
|
+
end unless ::Method.method_defined?(:owner)
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Assay::RSpec
|
|
2
|
+
|
|
3
|
+
# The Should module is included into BasicObject to provide
|
|
4
|
+
# the needed assertion interface that RSpec utilizes. Namely, the
|
|
5
|
+
# `should` and `should_not` methods.
|
|
6
|
+
#
|
|
7
|
+
module Should
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# Use `should` nomenclature for assertions.
|
|
11
|
+
#
|
|
12
|
+
# 10.should be_kind_of(Integer)
|
|
13
|
+
#
|
|
14
|
+
def should(matcher)
|
|
15
|
+
matcher =~ self
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# Also, `should_not` nomenclature for assertions.
|
|
20
|
+
#
|
|
21
|
+
# 10.should_not be_kind_of?(Integer)
|
|
22
|
+
#
|
|
23
|
+
def should_not(matcher)
|
|
24
|
+
matcher !~ self
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
#
|
|
29
|
+
#
|
|
30
|
+
def should=(value)
|
|
31
|
+
EqualAssay.assert!(self, value, :backtrace=>caller)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
#
|
|
36
|
+
#
|
|
37
|
+
def should_not=(value)
|
|
38
|
+
EqualAssay.refute!(self, value, :backtrace=>caller)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class BasicObject # Object ?
|
|
47
|
+
include ::Assay::RSpec::Should
|
|
48
|
+
end
|
|
49
|
+
|
data/lib/assay/rspec.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require_relative '../assay'
|
|
2
|
+
|
|
3
|
+
require_relative 'rspec/matchers'
|
|
4
|
+
require_relative 'rspec/have'
|
|
5
|
+
require_relative 'rspec/should'
|
|
6
|
+
require_relative 'rspec/expect'
|
|
7
|
+
require_relative 'rspec/operatics'
|
|
8
|
+
|
|
9
|
+
# RSpec-compatible matcher methods (`eq`, `be_nil`, `expect`, ...), to mix
|
|
10
|
+
# into a test scope.
|
|
11
|
+
module Assay::Matchers
|
|
12
|
+
include Assay::RSpec::Matchers
|
|
13
|
+
end
|