xspec 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +1 -1
- data/lib/xspec/assertion_contexts.rb +29 -7
- data/lib/xspec/notifiers.rb +2 -0
- data/spec/unit/doubles_spec.rb +20 -0
- data/spec/unit/notifiers_spec.rb +10 -0
- data/xspec.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43babe397ea759864cca9b9cf9f7b3f85574df64
|
4
|
+
data.tar.gz: 9bb1e2521e47fd442469f79c15f5ac0bb785a010
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a3278a29ac464e56907888124acf872c5151282718286ee141cd57e933e2b28e15d817c81e20b1a5f29199b2097ba962264190d7df44b604ab974ddfed3e76f
|
7
|
+
data.tar.gz: 652428e1709ecb942d8e858f764489cf5681d40b8b09e4061c9b2814a93f956ddc8df5d48b39fc382b6ec755f455a2c3df8fb4fcf7f93bea7aebdd10b808fb3d
|
data/README.md
CHANGED
@@ -162,16 +162,23 @@ EOS
|
|
162
162
|
# is desired, it can be supplied as a block, for example:
|
163
163
|
# `expect(double).some_method(1, 2) { "return value" }`
|
164
164
|
def expect(obj)
|
165
|
-
Recorder.new(obj)
|
165
|
+
Recorder.new(obj, :_expect)
|
166
|
+
end
|
167
|
+
|
168
|
+
# An allowed method will never be validated by `assert_exhausted`.
|
169
|
+
# Matching expectations are always given precendence to allows.
|
170
|
+
def allow(obj)
|
171
|
+
Recorder.new(obj, :_allow)
|
166
172
|
end
|
167
173
|
|
168
174
|
class Recorder
|
169
|
-
def initialize(double)
|
175
|
+
def initialize(double, method)
|
170
176
|
@double = double
|
177
|
+
@method = method
|
171
178
|
end
|
172
179
|
|
173
180
|
def method_missing(*args, &ret)
|
174
|
-
@double.
|
181
|
+
@double.__send__(@method, args, &(ret || ->{}))
|
175
182
|
end
|
176
183
|
end
|
177
184
|
|
@@ -183,15 +190,24 @@ EOS
|
|
183
190
|
def initialize(klass)
|
184
191
|
@klass = klass
|
185
192
|
@expected = []
|
193
|
+
@allowed = []
|
186
194
|
end
|
187
195
|
|
188
196
|
def method_missing(*actual_args)
|
189
|
-
|
197
|
+
expected_index = @expected.find_index {|expected_args, ret|
|
190
198
|
expected_args == actual_args
|
191
199
|
}
|
192
200
|
|
193
|
-
if
|
194
|
-
@expected.delete_at(
|
201
|
+
matching_message = if expected_index
|
202
|
+
@expected.delete_at(expected_index)
|
203
|
+
else
|
204
|
+
@allowed.detect {|expected_args, ret|
|
205
|
+
expected_args == actual_args
|
206
|
+
}
|
207
|
+
end
|
208
|
+
|
209
|
+
if matching_message
|
210
|
+
matching_message[1].call
|
195
211
|
else
|
196
212
|
name, rest = *actual_args
|
197
213
|
::Kernel.raise DoubleFailure, "Unexpectedly received: %s(%s)" % [
|
@@ -201,7 +217,7 @@ EOS
|
|
201
217
|
end
|
202
218
|
end
|
203
219
|
|
204
|
-
# The
|
220
|
+
# The methods needed on this object to set it up and verify it are
|
205
221
|
# prefixed by `_` to try to ensure they don't clash with any method
|
206
222
|
# expectations. While not fail-safe, users should only be using
|
207
223
|
# expectations for a public API, and `_` is traditionally only used
|
@@ -212,6 +228,12 @@ EOS
|
|
212
228
|
@expected << [args, ret]
|
213
229
|
end
|
214
230
|
|
231
|
+
def _allow(args, &ret)
|
232
|
+
@klass.validate_call! args
|
233
|
+
|
234
|
+
@allowed << [args, ret]
|
235
|
+
end
|
236
|
+
|
215
237
|
def _verify
|
216
238
|
return if @expected.empty?
|
217
239
|
|
data/lib/xspec/notifiers.rb
CHANGED
data/spec/unit/doubles_spec.rb
CHANGED
@@ -88,6 +88,26 @@ describe 'doubles assertion context' do
|
|
88
88
|
assert_include 'foo(1, "abc")', e.message
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
it 'does not raise on uncalled allows' do
|
93
|
+
assert subject.instance_eval {
|
94
|
+
double = instance_double('Bogus')
|
95
|
+
allow(double).foo
|
96
|
+
assert_exhausted double
|
97
|
+
true
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'gives precendence to expect' do
|
102
|
+
assert_equal 1, subject.instance_eval {
|
103
|
+
double = instance_double('Bogus')
|
104
|
+
allow(double).foo
|
105
|
+
expect(double).foo { 1 }
|
106
|
+
ret = double.foo
|
107
|
+
assert_exhausted double
|
108
|
+
ret
|
109
|
+
}
|
110
|
+
end
|
91
111
|
end
|
92
112
|
|
93
113
|
describe 'instance_double' do
|
data/spec/unit/notifiers_spec.rb
CHANGED
@@ -154,6 +154,16 @@ describe 'null notifier' do
|
|
154
154
|
it_behaves_like_a ComposableNotifier
|
155
155
|
end
|
156
156
|
|
157
|
+
describe 'timings at end' do
|
158
|
+
let(:notifier) { XSpec::Notifier::TimingsAtEnd.new }
|
159
|
+
|
160
|
+
it 'always returns true' do
|
161
|
+
assert notifier.run_finish
|
162
|
+
end
|
163
|
+
|
164
|
+
it_behaves_like_a ComposableNotifier
|
165
|
+
end
|
166
|
+
|
157
167
|
def make_nested_test(parent_names = [], work_name = nil)
|
158
168
|
XSpec::NestedUnitOfWork.new(
|
159
169
|
parent_names.map {|name| XSpec::Context.make(name, Module.new) },
|
data/xspec.gemspec
CHANGED