flexmock 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,11 @@
1
1
  = Changes for FlexMock
2
2
 
3
+ == Version 0.1.3
4
+
5
+ * Improved the definition of ordered so that it takes group names
6
+ instead of explicit order numbers. This make the code easier to
7
+ write and the API easier to understand.
8
+
3
9
  == Version 0.1.2
4
10
 
5
11
  * Fixed homepage in gem spec.
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.2
6
+ Version :: 0.1.3
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.2'
11
+ PKG_VERSION = '0.1.3'
12
12
 
13
13
  PKG_FILES = FileList[
14
14
  '[A-Z]*',
data/lib/flexmock.rb CHANGED
@@ -33,7 +33,7 @@ require 'test/unit'
33
33
  class FlexMock
34
34
  include Test::Unit::Assertions
35
35
 
36
- attr_reader :mock_name
36
+ attr_reader :mock_name, :mock_groups
37
37
  attr_accessor :mock_current_order
38
38
 
39
39
  # Create a FlexMock object with the given name. The name is used in
@@ -43,6 +43,7 @@ class FlexMock
43
43
  @expectations = Hash.new
44
44
  @allocated_order = 0
45
45
  @mock_current_order = 0
46
+ @mock_groups = {}
46
47
  end
47
48
 
48
49
  # Handle all messages denoted by +sym+ by calling the given block
@@ -70,19 +71,6 @@ class FlexMock
70
71
  @allocated_order += 1
71
72
  end
72
73
 
73
- # Allocation a new order number from the mock.
74
- def mock_reallocate(n)
75
- if @auto_allocate && n <= @allocated_order
76
- FlexMock.failure "explicit order number #{n} must be greater than " +
77
- @allocated_order.to_s
78
- elsif (n < @allocated_order)
79
- FlexMock.failure "explicit order number #{n} must be greater than or equal to " +
80
- @allocated_order.to_s
81
- end
82
- @auto_allocate = false
83
- @allocated_order = n
84
- end
85
-
86
74
  # Ignore all undefined (missing) method calls.
87
75
  def should_ignore_missing
88
76
  @ignore_missing = true
@@ -460,24 +448,30 @@ class FlexMock
460
448
  # If the user needs more fine control over ordering
461
449
  # (e.g. specifying that a group of messages may be received in any
462
450
  # order as long as they all come after another group of messages),
463
- # a _order_ _number_ may be specified in the +ordered+ calls
451
+ # a _group_ _name__ may be specified in the +ordered+ calls. All
452
+ # messages within the same group may be recieved in any order.
464
453
  #
465
454
  # For example, in the following, messages +flip+ and +flop+ may be
466
- # received in any order (because they have the same order number),
467
- # but must occur strictly after +start+ but before +end+.
455
+ # received in any order (because they are in the same group), but
456
+ # must occur strictly after +start+ but before +end+. The message
457
+ # +any_time+ may be received at any time because it is not
458
+ # ordered.
468
459
  #
469
460
  # m = FlexMock.new
461
+ # m.should_receive(:any_time)
470
462
  # m.should_receive(:start).ordered
471
- # m.should_receive(:flip).ordered(10)
472
- # m.should_receive(:flop).ordered(10)
463
+ # m.should_receive(:flip).ordered(:flip_flop_group)
464
+ # m.should_receive(:flop).ordered(:flip_flop_group)
473
465
  # m.should_receive(:end).ordered
474
466
  #
475
- def ordered(order=nil)
476
- if order.nil?
467
+ def ordered(group_name=nil)
468
+ if group_name.nil?
477
469
  @order_number = @mock.mock_allocate_order
470
+ elsif (num = @mock.mock_groups[group_name])
471
+ @order_number = num
478
472
  else
479
- @order_number = order
480
- @mock.mock_reallocate order
473
+ @order_number = @mock.mock_allocate_order
474
+ @mock.mock_groups[group_name] = @order_number
481
475
  end
482
476
  self
483
477
  end
@@ -375,11 +375,26 @@ class TestFlexMock < Test::Unit::TestCase
375
375
  end
376
376
  end
377
377
 
378
- def test_explicit_ordering
378
+ def test_grouped_ordering
379
379
  FlexMock.use 'm' do |m|
380
- m.should_receive(:start).ordered(2)
381
- m.should_receive(:flip).ordered(10)
382
- m.should_receive(:flop).ordered(10)
380
+ m.should_receive(:start).ordered(:start_group)
381
+ m.should_receive(:flip).ordered(:flip_flop_group)
382
+ m.should_receive(:flop).ordered(:flip_flop_group)
383
+ m.should_receive(:final).ordered
384
+
385
+ m.start
386
+ m.flop
387
+ m.flip
388
+ m.flop
389
+ m.final
390
+ end
391
+ end
392
+
393
+ def test_grouped_ordering_with_symbols
394
+ FlexMock.use 'm' do |m|
395
+ m.should_receive(:start).ordered(:group_one)
396
+ m.should_receive(:flip).ordered(:group_two)
397
+ m.should_receive(:flop).ordered(:group_two)
383
398
  m.should_receive(:final).ordered
384
399
 
385
400
  m.start
@@ -393,27 +408,18 @@ class TestFlexMock < Test::Unit::TestCase
393
408
  def test_explicit_ordering_mixed_with_implicit_ordering_should_not_overlap
394
409
  FlexMock.use 'm' do |m|
395
410
  xstart = m.should_receive(:start).ordered
396
- xmid = m.should_receive(:mid).ordered(2)
411
+ xmid = m.should_receive(:mid).ordered(:group_name)
397
412
  xend = m.should_receive(:end).ordered
398
413
  assert xstart.order_number < xmid.order_number
399
414
  assert xmid.order_number < xend.order_number
400
415
  end
401
416
  end
402
417
 
403
- def test_explicit_ordering_with_overlap_with_start
404
- ex = assert_failure do
405
- FlexMock.use 'm' do |m|
406
- xstart = m.should_receive(:start).ordered
407
- xmid = m.should_receive(:mid).ordered(1)
408
- end
409
- end
410
- end
411
-
412
418
  def test_explicit_ordering_with_explicit_misorders
413
419
  assert_failure do
414
420
  FlexMock.use 'm' do |m|
415
- m.should_receive(:hi).ordered(2)
416
- m.should_receive(:lo).ordered(10)
421
+ m.should_receive(:hi).ordered(:first_group)
422
+ m.should_receive(:lo).ordered(:second_group)
417
423
 
418
424
  m.lo
419
425
  m.hi
@@ -421,15 +427,6 @@ class TestFlexMock < Test::Unit::TestCase
421
427
  end
422
428
  end
423
429
 
424
- def test_explicit_ordering_with_out_of_order_explicitness
425
- assert_failure do
426
- FlexMock.use 'm' do |m|
427
- m.should_receive(:lo).ordered(10)
428
- m.should_receive(:hi).ordered(2)
429
- end
430
- end
431
- end
432
-
433
430
  def test_expectation_formating
434
431
  m = FlexMock.new("m")
435
432
  exp = m.should_receive(:f).with(1,"two", /^3$/).and_return(0).at_least.once
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11.3
2
+ rubygems_version: 0.8.10.100
3
3
  specification_version: 1
4
4
  name: flexmock
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.2
7
- date: 2005-10-25 00:00:00 -04:00
6
+ version: 0.1.3
7
+ date: 2005-10-27 00:00:00 -04:00
8
8
  summary: Simple and Flexible Mock Objects for Testing
9
9
  require_paths:
10
10
  - lib