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 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
@@ -3,7 +3,7 @@
3
3
  FlexMock is a simple mock object for unit testing. The interface is
4
4
  simple, but still provides a good bit of flexibility.
5
5
 
6
- Version :: 0.1.5
6
+ Version :: 0.1.6
7
7
 
8
8
  = Links
9
9
 
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rake/testtask'
8
8
 
9
9
  CLOBBER.include("html", 'pkg')
10
10
 
11
- PKG_VERSION = '0.1.5'
11
+ PKG_VERSION = '0.1.6'
12
12
 
13
13
  PKG_FILES = FileList[
14
14
  '[A-Z]*',
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
  ####################################################################
@@ -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)
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11.3
3
3
  specification_version: 1
4
4
  name: flexmock
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.5
6
+ version: 0.1.6
7
7
  date: 2005-11-13 00:00:00 -05:00
8
8
  summary: Simple and Flexible Mock Objects for Testing
9
9
  require_paths: