flexmock 0.1.5 → 0.1.6
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.
- data/CHANGELOG +9 -0
- data/README +1 -1
- data/Rakefile +1 -1
- data/lib/flexmock.rb +18 -0
- data/test/test_should_receive.rb +15 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
= Changes for FlexMock
|
|
2
2
|
|
|
3
|
+
== Version 0.1.6
|
|
4
|
+
|
|
5
|
+
* Added a proc based matcher for arguments (using keyword +on+).
|
|
6
|
+
|
|
7
|
+
== Version 0.1.5
|
|
8
|
+
|
|
9
|
+
* Fixed the overzealous argument matching when String is given as an
|
|
10
|
+
argument qualifier to +should_receive+.
|
|
11
|
+
|
|
3
12
|
== Version 0.1.4
|
|
4
13
|
|
|
5
14
|
* Added eq and any methods for argument matching.
|
data/README
CHANGED
data/Rakefile
CHANGED
data/lib/flexmock.rb
CHANGED
|
@@ -248,6 +248,20 @@ class FlexMock
|
|
|
248
248
|
|
|
249
249
|
ANY = AnyMatcher.new
|
|
250
250
|
|
|
251
|
+
####################################################################
|
|
252
|
+
# Match only things where the block evaluates to true.
|
|
253
|
+
class ProcMatcher
|
|
254
|
+
def initialize(&block)
|
|
255
|
+
@block = block
|
|
256
|
+
end
|
|
257
|
+
def ===(target)
|
|
258
|
+
@block.call(target)
|
|
259
|
+
end
|
|
260
|
+
def inspect
|
|
261
|
+
"on{...}"
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
251
265
|
####################################################################
|
|
252
266
|
# Include this module in your test class if you wish to use the +eq+
|
|
253
267
|
# and +any+ argument matching methods without a prefix. (Otherwise
|
|
@@ -264,6 +278,10 @@ class FlexMock
|
|
|
264
278
|
def eq(obj)
|
|
265
279
|
EqualMatcher.new(obj)
|
|
266
280
|
end
|
|
281
|
+
|
|
282
|
+
def on(&block)
|
|
283
|
+
ProcMatcher.new(&block)
|
|
284
|
+
end
|
|
267
285
|
end
|
|
268
286
|
|
|
269
287
|
####################################################################
|
data/test/test_should_receive.rb
CHANGED
|
@@ -108,6 +108,21 @@ class TestFlexMockShoulds < Test::Unit::TestCase
|
|
|
108
108
|
end
|
|
109
109
|
end
|
|
110
110
|
|
|
111
|
+
def test_with_arbitrary_arg_matching
|
|
112
|
+
FlexMock.use('greeter') do |m|
|
|
113
|
+
m.should_receive(:hi).with(FlexMock.on { |arg| arg % 2 == 0 }).twice
|
|
114
|
+
m.should_receive(:hi).never
|
|
115
|
+
m.should_receive(:hi).with(1).once
|
|
116
|
+
m.should_receive(:hi).with(2).never
|
|
117
|
+
m.should_receive(:hi).with(3).once
|
|
118
|
+
m.should_receive(:hi).with(4).never
|
|
119
|
+
m.hi(1)
|
|
120
|
+
m.hi(2)
|
|
121
|
+
m.hi(3)
|
|
122
|
+
m.hi(4)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
111
126
|
def test_args_matching_with_regex
|
|
112
127
|
FlexMock.use do |m|
|
|
113
128
|
m.should_receive(:hi).with(/one/).returns(10)
|