flexmock 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  = Changes for FlexMock
4
4
 
5
+ == Version 0.6.1
6
+
7
+ * Fixed bug that prevented mocks from mocking field assignment operators.
8
+ * Fixed bug that prevented partial mocks from being ordered.
9
+
5
10
  == Version 0.6.0
6
11
 
7
12
  * Dropped class interception.
data/README CHANGED
@@ -3,7 +3,7 @@
3
3
  FlexMock is a simple, but flexible, mock object library for Ruby unit
4
4
  testing.
5
5
 
6
- Version :: 0.6.0
6
+ Version :: 0.6.1
7
7
 
8
8
  = Links
9
9
 
@@ -155,7 +155,7 @@ expectation and adds constraints to that.
155
155
 
156
156
  For example, the following code:
157
157
 
158
- mock.should_recieve(:average).and_return(12)
158
+ mock.should_receive(:average).and_return(12)
159
159
 
160
160
  Means that the mock will now accept method calls to an +average+ method. The
161
161
  expectation will accept any arguments and may be called any number of times
@@ -545,7 +545,7 @@ All the query message must occur before any of the update messages.
545
545
  def test_query_and_update
546
546
  db = flexmock('db')
547
547
  db.should_receive(:query).and_return([1,2,3]).ordered
548
- db.should_recieve(:update).and_return(nil).ordered
548
+ db.should_receive(:update).and_return(nil).ordered
549
549
  # test code here
550
550
  end
551
551
 
@@ -637,7 +637,7 @@ ignoring.
637
637
 
638
638
  def test_an_important_message
639
639
  m = flexmock('m')
640
- m.should_recieve(:an_important_message).and_return(1).once
640
+ m.should_receive(:an_important_message).and_return(1).once
641
641
  m.should_ignore_missing
642
642
  # test code here
643
643
  end
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ require 'rake/contrib/rubyforgepublisher'
19
19
  CLEAN.include('*.tmp')
20
20
  CLOBBER.include("html", 'pkg')
21
21
 
22
- PKG_VERSION = '0.6.0'
22
+ PKG_VERSION = '0.6.1'
23
23
 
24
24
  PKG_FILES = FileList[
25
25
  '[A-Z]*',
@@ -32,7 +32,7 @@ FlexMock is a flexible mocking library for use in unit testing and behavior spec
32
32
  flexmock.should_receive(:read, :write).at_least.once
33
33
 
34
34
 
35
- * +should_recieve+ now will allow expectation hashes as arguments. This is
35
+ * +should_receive+ now will allow expectation hashes as arguments. This is
36
36
  similar to the list of methods, but allows each defined method to have its
37
37
  own return value.
38
38
 
@@ -0,0 +1,91 @@
1
+ = FlexMock 0.6.1 Released
2
+
3
+ FlexMock is a flexible mocking library for use in unit testing and behavior
4
+ specification in Ruby. Version 0.6.1 introduces a number minor bug fixes.
5
+
6
+ == New in 0.6.1
7
+
8
+ * Fixed several bugs related to partial mocks and ordering and mocking field
9
+ assignments.
10
+
11
+ == What is FlexMock?
12
+
13
+ FlexMock is a flexible framework for creating mock object for testing. When
14
+ running unit tests, it is often desirable to use isolate the objects being
15
+ tested from the "real world" by having them interact with simplified test
16
+ objects. Sometimes these test objects simply return values when called, other
17
+ times they verify that certain methods were called with particular arguments
18
+ in a particular order.
19
+
20
+ FlexMock makes creating these test objects easy.
21
+
22
+ === Features
23
+
24
+ * Easy integration with both Test::Unit and RSpec. Mocks created with the
25
+ flexmock method are automatically verified at the end of the test or
26
+ example.
27
+
28
+ * A fluent interface that allows mock behavior to be specified very
29
+ easily.
30
+
31
+ * A "record mode" where an existing implementation can record its
32
+ interaction with a mock for later validation against a new
33
+ implementation.
34
+
35
+ * Easy mocking of individual methods in existing, non-mock objects.
36
+
37
+ * The ability to cause classes to instantiate test instances (instead of real
38
+ instances) for the duration of a test.
39
+
40
+ === Example
41
+
42
+ Suppose you had a Dog object that wagged a tail when it was happy.
43
+ Something like this:
44
+
45
+ class Dog
46
+ def initialize(a_tail)
47
+ @tail = a_tail
48
+ end
49
+ def happy
50
+ @tail.wag
51
+ end
52
+ end
53
+
54
+ To test the +Dog+ class without a real +Tail+ object (perhaps because
55
+ real +Tail+ objects activate servos in some robotic equipment), you
56
+ can do something like this:
57
+
58
+ require 'test/unit'
59
+ require 'flexmock/test_unit'
60
+
61
+ class TestDog < Test::Unit::TestCase
62
+ def test_dog_wags_tail_when_happy
63
+ tail = flexmock("tail")
64
+ tail.should_receive(:wag).once
65
+ dog = Dog.new(tail)
66
+ dog.happy
67
+ end
68
+ end
69
+
70
+ FlexMock will automatically verify that the mocked tail object received the
71
+ message +wag+ exactly one time. If it doesn't, the test will not pass.
72
+
73
+ See the FlexMock documentation at http://flexmock.rubyforge.org for details on
74
+ specifying arguments and return values on mocked methods, as well as a simple
75
+ technique for mocking tail objects when the Dog class creates the tail objects
76
+ directly.
77
+
78
+ == Availability
79
+
80
+ You can make sure you have the latest version with a quick RubyGems command:
81
+
82
+ gem install flexmock (you may need root/admin privileges)
83
+
84
+ Otherwise, you can get it from the more traditional places:
85
+
86
+ Download:: http://rubyforge.org/project/showfiles.php?group_id=170
87
+
88
+ You will find documentation at: http://flexmock.rubyforge.org.
89
+
90
+ -- Jim Weirich
91
+
@@ -85,7 +85,6 @@ class FlexMock
85
85
 
86
86
  # Allocation a new order number from the mock.
87
87
  def mock_allocate_order
88
- @auto_allocate = true
89
88
  @allocated_order += 1
90
89
  end
91
90
 
@@ -13,19 +13,18 @@ require 'flexmock/noop'
13
13
 
14
14
  class FlexMock
15
15
 
16
- ####################################################################
17
- # PartialMock is used to mate the mock framework to an existing
18
- # object. The object is "enhanced" with a reference to a mock
19
- # object (stored in <tt>@flexmock_mock</tt>). When the
20
- # +should_receive+ method is sent to the proxy, it overrides the
21
- # existing object's method by creating singleton method that
22
- # forwards to the mock. When testing is complete, PartialMock
23
- # will erase the mocking infrastructure from the object being
24
- # mocked (e.g. remove instance variables and mock singleton
25
- # methods).
16
+ # #########################################################################
17
+ # PartialMock is used to mate the mock framework to an existing object. The
18
+ # object is "enhanced" with a reference to a mock object (stored in
19
+ # <tt>@flexmock_mock</tt>). When the +should_receive+ method is sent to the
20
+ # proxy, it overrides the existing object's method by creating singleton
21
+ # method that forwards to the mock. When testing is complete, PartialMock
22
+ # will erase the mocking infrastructure from the object being mocked (e.g.
23
+ # remove instance variables and mock singleton methods).
26
24
  #
27
25
  class PartialMock
28
- attr_reader :mock
26
+ attr_reader :mock, :mock_groups
27
+ attr_accessor :mock_current_order, :mock_container
29
28
 
30
29
  # Initialize a PartialMock object.
31
30
  def initialize(obj, mock)
@@ -33,6 +32,9 @@ class FlexMock
33
32
  @mock = mock
34
33
  @method_definitions = {}
35
34
  @methods_proxied = []
35
+ @allocated_order = 0
36
+ @mock_current_order = 0
37
+ @mock_groups = {}
36
38
  end
37
39
 
38
40
  # :call-seq:
@@ -132,16 +134,9 @@ class FlexMock
132
134
  end
133
135
  end
134
136
 
135
- # Return the container for this mocking object. Returns nil if the
136
- # mock is not in a container. Mock containers make sure that mock objects
137
- # inside the container are torn down at the end of a test
138
- def mock_container
139
- @mock.mock_container
140
- end
141
-
142
- # Set the container for this mock object.
143
- def mock_container=(container)
144
- @mock.mock_container = container
137
+ # Allocation a new order number from the mock.
138
+ def mock_allocate_order
139
+ @allocated_order += 1
145
140
  end
146
141
 
147
142
  private
@@ -189,9 +184,19 @@ class FlexMock
189
184
  # proxy method is defined as a singleton method on the object
190
185
  # being mocked.
191
186
  def define_proxy_method(method_name)
192
- sclass.class_eval %{
193
- def #{method_name}(*args, &block) @flexmock_proxy.mock.#{method_name}(*args, &block) end
194
- }
187
+ if method_name.to_s =~ /=$/
188
+ sclass.class_eval %{
189
+ def #{method_name}(*args, &block)
190
+ @flexmock_proxy.mock.__send__(:#{method_name}, *args, &block)
191
+ end
192
+ }
193
+ else
194
+ sclass.class_eval %{
195
+ def #{method_name}(*args, &block)
196
+ @flexmock_proxy.mock.#{method_name}(*args, &block)
197
+ end
198
+ }
199
+ end
195
200
  end
196
201
 
197
202
  # Restore the original singleton defintion for method_name that
@@ -191,6 +191,30 @@ class TestNewInstances < Test::Unit::TestCase
191
191
  assert_equal :grrr, Dog.new.woof
192
192
  end
193
193
 
194
+ def test_writable_accessors
195
+ flexmock(Dog).new_instances.should_receive(:name=).with("fido")
196
+ dog = Dog.new
197
+ dog.name = 'fido'
198
+ end
199
+
200
+ def test_ordering_can_be_specified
201
+ dog = Dog.new
202
+ flexmock(dog).should_receive(:bark).once.ordered
203
+ flexmock(dog).should_receive(:bite).once.ordered
204
+ dog.bark
205
+ dog.bite
206
+ end
207
+
208
+ def test_ordering_can_be_specified_in_groups
209
+ dog = Dog.new
210
+ flexmock(dog).should_receive(:wag).once.ordered(:safe)
211
+ flexmock(dog).should_receive(:bark).once.ordered(:danger)
212
+ flexmock(dog).should_receive(:bite).once.ordered(:danger)
213
+ dog.wag
214
+ dog.bite
215
+ dog.bark
216
+ end
217
+
194
218
  def redirect_error
195
219
  require 'stringio'
196
220
  old_err = $stderr
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: flexmock
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.0
7
- date: 2007-04-14 00:00:00 -04:00
6
+ version: 0.6.1
7
+ date: 2007-05-08 00:00:00 -04:00
8
8
  summary: Simple and Flexible Mock Objects for Testing
9
9
  require_paths:
10
10
  - lib
@@ -74,6 +74,7 @@ files:
74
74
  - doc/releases/flexmock-0.5.0.rdoc
75
75
  - doc/releases/flexmock-0.5.1.rdoc
76
76
  - doc/releases/flexmock-0.6.0.rdoc
77
+ - doc/releases/flexmock-0.6.1.rdoc
77
78
  test_files: []
78
79
 
79
80
  rdoc_options:
@@ -93,6 +94,7 @@ extra_rdoc_files:
93
94
  - doc/releases/flexmock-0.5.0.rdoc
94
95
  - doc/releases/flexmock-0.5.1.rdoc
95
96
  - doc/releases/flexmock-0.6.0.rdoc
97
+ - doc/releases/flexmock-0.6.1.rdoc
96
98
  executables: []
97
99
 
98
100
  extensions: []