flexmock 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,14 @@
1
1
  = Changes for FlexMock
2
2
 
3
+ == Version 0.8.4
4
+
5
+ * Added support for rails 2.2.x in should_render_view.
6
+
7
+ == Version 0.8.3
8
+
9
+ * Fixed a bug where the by_default option was not completely honored
10
+ in some edge cases.
11
+
3
12
  == Version 0.8.2
4
13
 
5
14
  * Added workaround for compatibility issues with RSpec on Rails.
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.8.3
6
+ Version :: 0.8.4
7
7
 
8
8
  = Links
9
9
 
@@ -470,12 +470,29 @@ The following rules are used for argument matching:
470
470
  with(eq(Integer)) will match f(Integer)
471
471
  with(eq(Integer)) will NOT match f(3)
472
472
 
473
- Note: If you do not use the FlexMock::TestCase Test Unit integration
474
- module, or the FlexMock::ArgumentTypes module, you will have to
475
- fully qualify the +eq+ method:
473
+ <b>Note:</b> If you do not use the FlexMock::TestCase Test Unit
474
+ integration module, or the FlexMock::ArgumentTypes module, you will
475
+ have to fully qualify the +eq+ method. This is true of all the
476
+ special argument matches (+eq+, +on+, +any+, +hsh+ and +ducktype+).
476
477
 
477
- with(FlexMock.eq(Integer)) will match f(Integer)
478
- with(FlexMock.eq(Integer)) will NOT match f(3)
478
+ with(FlexMock.eq(Integer))
479
+ with(FlexMock.on { code })
480
+ with(FlexMock.any)
481
+ with(FlexMock.hsh(:tag => 3))
482
+ with(FlexMock.ducktype(:wag => "dog"))
483
+
484
+ * If you wish to match a hash on _some_ of its values, the
485
+ FlexMock.hsh(...) method will work. Only specify the hash values
486
+ you are interested in, the others will be ignored.
487
+
488
+ with(hsh(:run => true)) will match f(:run => true, :stop => false)
489
+
490
+ * If you wish to match any object that responds to a certain set of
491
+ methods, use the FlexMock.ducktype method.
492
+
493
+ with(ducktype(:to_str)) will match f("string")
494
+ with(ducktype(:wag, :bark)) will match f(dog)
495
+ (assuming dog implements wag and bark)
479
496
 
480
497
  * If you wish to match _anything_, then use the <tt>FlexMock.any</tt>
481
498
  method in the with argument list.
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.8.3'
22
+ PKG_VERSION = '0.8.4'
23
23
 
24
24
  PKG_FILES = FileList[
25
25
  '[A-Z]*',
@@ -145,7 +145,7 @@ else
145
145
 
146
146
  s.author = "Jim Weirich"
147
147
  s.email = "jim@weirichhouse.org"
148
- s.homepage = "http://onestepback.org/software/flexmock"
148
+ s.homepage = "http://flexmock.rubyforge.org"
149
149
  end
150
150
 
151
151
  Rake::GemPackageTask.new(spec) do |pkg|
data/TAGS CHANGED
@@ -60,14 +60,13 @@ class FlexMockFlexMock15,371
60
60
  def initializeinitialize75,2276
61
61
  def passed?passed?79,2337
62
62
 
63
- lib/flexmock/default_framework_adapter.rb,387
63
+ lib/flexmock/default_framework_adapter.rb,345
64
64
  class FlexMockFlexMock14,337
65
65
  class DefaultFrameworkAdapterDefaultFrameworkAdapter15,352
66
66
  def assert_block(msg, &block)assert_block16,384
67
67
  def assert_equal(a, b, msg=nil)assert_equal22,497
68
- def passed?(test_case)passed?26,597
69
- class AssertionFailedError < StandardError; endAssertionFailedError30,657
70
- def assertion_failed_errorassertion_failed_error31,709
68
+ class AssertionFailedError < StandardError; endAssertionFailedError26,597
69
+ def assertion_failed_errorassertion_failed_error27,649
71
70
 
72
71
  lib/flexmock/deprecated_methods.rb,340
73
72
  class ModuleModule13,314
@@ -137,38 +136,26 @@ class FlexMockFlexMock15,363
137
136
  def call(*args)call38,1207
138
137
  def <<(expectation)<<46,1460
139
138
  def find_expectation(*args) # :nodoc:find_expectation51,1584
140
- def flexmock_verify # :nodoc:flexmock_verify59,1909
141
- def defaultify_expectation(exp) # :nodoc:defaultify_expectation66,2120
142
- def find_expectation_in(expectations, *args)find_expectation_in78,2401
143
-
144
- lib/flexmock/mini_unit.rb,393
145
- class FlexMockFlexMock15,357
146
- module TestCaseTestCase29,918
147
- def teardownteardown35,1093
148
- class MiniUnitFrameworkAdapterMiniUnitFrameworkAdapter45,1302
149
- def assertion_failed_errorassertion_failed_error47,1364
150
- def passed?(test_case)passed?51,1426
151
- module MiniMini59,1536
152
- class TestTest60,1548
153
- class TestCaseTestCase61,1561
154
- def teardownteardown70,1876
139
+ def flexmock_verify # :nodoc:flexmock_verify62,1959
140
+ def defaultify_expectation(exp) # :nodoc:defaultify_expectation69,2170
141
+ def find_expectation_in(expectations, *args)find_expectation_in81,2451
155
142
 
156
143
  lib/flexmock/mock_container.rb,882
157
- class FlexMockFlexMock15,371
158
- module MockContainerMockContainer25,777
159
- def flexmock_teardownflexmock_teardown30,961
160
- def flexmock_verifyflexmock_verify37,1152
161
- def flexmock_closeflexmock_close46,1447
162
- def flexmock(*args)flexmock115,4717
163
- def flexmock_remember(mocking_object)flexmock_remember157,5993
164
- class MockContainerHelperMockContainerHelper173,6643
165
- def next_idnext_id177,6752
166
- def parse_should_args(mock, args, &block) # :nodoc:parse_should_args190,7225
167
- def add_model_methods(mock, model_class, id)add_model_methods208,7738
168
- def make_partial_proxy(container, obj, name, safe_mode)make_partial_proxy232,8597
169
- def build_demeter_chain(mock, arg, &block)build_demeter_chain277,10450
170
- def check_proper_mock(mock, method_name)check_proper_mock302,11301
171
- def check_method_names(names)check_method_names312,11708
144
+ class FlexMockFlexMock16,399
145
+ module MockContainerMockContainer26,805
146
+ def flexmock_teardownflexmock_teardown31,989
147
+ def flexmock_verifyflexmock_verify38,1147
148
+ def flexmock_closeflexmock_close47,1442
149
+ def flexmock(*args)flexmock116,4712
150
+ def flexmock_remember(mocking_object)flexmock_remember158,5988
151
+ class MockContainerHelperMockContainerHelper174,6638
152
+ def next_idnext_id178,6747
153
+ def parse_should_args(mock, args, &block) # :nodoc:parse_should_args191,7220
154
+ def add_model_methods(mock, model_class, id)add_model_methods209,7733
155
+ def make_partial_proxy(container, obj, name, safe_mode)make_partial_proxy233,8592
156
+ def build_demeter_chain(mock, arg, &block)build_demeter_chain278,10445
157
+ def check_proper_mock(mock, method_name)check_proper_mock303,11296
158
+ def check_method_names(names)check_method_names313,11703
172
159
 
173
160
  lib/flexmock/noop.rb,0
174
161
 
@@ -225,6 +212,30 @@ class FlexMockFlexMock14,347
225
212
  def strict?strict?53,1675
226
213
  def method_missing(sym, *args, &block)method_missing59,1805
227
214
 
215
+ lib/flexmock/rmock.rb,991
216
+ class ObjectObject4,59
217
+ def stub!(method)stub!5,72
218
+ def should_receive(method)should_receive8,157
219
+ class FlexMockFlexMock13,261
220
+ class GlobalContainerGlobalContainer14,276
221
+ module RMockEmulationRMockEmulation20,375
222
+ class SpecialArgSpecialArg23,436
223
+ def initialize(&block)initialize24,457
224
+ def apply(exp)apply27,519
225
+ class RMockExpecationProxyRMockExpecationProxy35,682
226
+ def initialize(expectation)initialize36,713
227
+ def with(*args)with39,792
228
+ def method_missing(sym, *args, &block)method_missing48,1053
229
+ class RMockProxyRMockProxy53,1163
230
+ def initialize(mock)initialize54,1184
231
+ def should_receive(method)should_receive57,1242
232
+ def should_not_receive(method)should_not_receive60,1353
233
+ def method_missing(sym, *args, &block)method_missing63,1469
234
+ def mock(name, options={})mock68,1598
235
+ def stub(name, options={})stub74,1742
236
+ def no_argsno_args78,1812
237
+ def any_argsany_args82,1851
238
+
228
239
  lib/flexmock/rspec.rb,341
229
240
  class FlexMockFlexMock14,337
230
241
  class RSpecFrameworkAdapterRSpecFrameworkAdapter16,355
@@ -239,13 +250,12 @@ module TestTest14,354
239
250
  class TestCaseTestCase16,380
240
251
  def teardownteardown25,695
241
252
 
242
- lib/flexmock/test_unit_integration.rb,270
253
+ lib/flexmock/test_unit_integration.rb,227
243
254
  class FlexMockFlexMock15,357
244
255
  module TestCaseTestCase29,917
245
256
  def teardownteardown35,1092
246
257
  class TestUnitFrameworkAdapterTestUnitFrameworkAdapter45,1301
247
258
  def assertion_failed_errorassertion_failed_error47,1369
248
- def passed?(test_case)passed?51,1448
249
259
 
250
260
  lib/flexmock/undefined.rb,288
251
261
  class FlexMockFlexMock12,312
@@ -277,29 +287,13 @@ class FlexMockFlexMock12,312
277
287
  module FailureAssertionFailureAssertion15,368
278
288
  def assert_failure(message=nil)assert_failure21,567
279
289
 
280
- test/frameworks/mini_unit_test.rb,407
281
- class FlexmockMiniUnitTest < Mini::Test::TestCaseFlexmockMiniUnitTest20,432
282
- def test_can_create_mockstest_can_create_mocks22,509
283
- def test_can_use_argument_matcherstest_can_use_argument_matchers28,609
284
- class FlexmockMinitUnitCleanupTest < Mini::Test::TestCaseFlexmockMinitUnitCleanupTest35,730
285
- def teardownteardown37,789
286
- def test_mocks_are_auto_verifiedtest_mocks_are_auto_verified50,1066
287
-
288
- test/frameworks/rspec_spec.rb,0
289
-
290
- test/frameworks/test_unit_test.rb,431
291
- class TestFlexmockTestUnit < Test::Unit::TestCaseTestFlexmockTestUnit18,412
292
- def test_can_create_mockstest_can_create_mocks20,489
293
- def test_can_use_argument_matcherstest_can_use_argument_matchers26,589
294
- class TestFlexmockTestUnitCleanup < Test::Unit::TestCaseTestFlexmockTestUnitCleanup33,710
295
- def teardownteardown35,768
296
- def test_should_fail__mocks_are_auto_verifiedtest_should_fail__mocks_are_auto_verified45,1004
297
-
298
290
  test/redirect_error.rb,114
299
291
  class FlexMockFlexMock3,20
300
292
  module RedirectErrorRedirectError4,35
301
293
  def redirect_errorredirect_error5,58
302
294
 
295
+ test/rspec_integration/integration_spec.rb,0
296
+
303
297
  test/test_aliasing.rb,522
304
298
  class FlexMockFlexMock6,61
305
299
  module StubsAndExpectsStubsAndExpects7,76
@@ -577,6 +571,26 @@ class TestRecordMode < Test::Unit::TestCaseTestRecordMode16,390
577
571
  def test_strict_record_mode_requires_oncetest_strict_record_mode_requires_once136,3242
578
572
  def test_strict_record_mode_can_not_failtest_strict_record_mode_can_not_fail149,3517
579
573
 
574
+ test/test_rmock.rb,1390
575
+ class RMockTest < Test::Unit::TestCaseRMockTest6,94
576
+ def test_can_mock_methodstest_can_mock_methods9,169
577
+ def test_mocks_require_their_methods_to_be_called_at_least_oncetest_mocks_require_their_methods_to_be_called_at_least_once15,262
578
+ def test_undefined_methods_failtest_undefined_methods_fail23,470
579
+ def test_null_object_optiontest_null_object_option30,597
580
+ def test_can_create_stubstest_can_create_stubs36,753
581
+ def test_stubs_dont_care_if_their_methods_arent_calledtest_stubs_dont_care_if_their_methods_arent_called41,928
582
+ def test_stubbing_partial_mockstest_stubbing_partial_mocks45,1024
583
+ def test_mocking_partial_mockstest_mocking_partial_mocks51,1152
584
+ def test_mocking_partial_mockstest_mocking_partial_mocks57,1288
585
+ def test_should_not_receive_where_it_is_not_receivedtest_should_not_receive_where_it_is_not_received65,1487
586
+ def test_should_not_receive_where_it_is_receivedtest_should_not_receive_where_it_is_received70,1604
587
+ def test_with_matching_argstest_with_matching_args79,1814
588
+ def test_with_mismatching_argstest_with_mismatching_args85,1918
589
+ def test_with_no_args_matchingtest_with_no_args_matching95,2130
590
+ def test_with_no_args_mismatchingtest_with_no_args_mismatching101,2240
591
+ def test_with_any_args_and_no_argstest_with_any_args_and_no_args109,2420
592
+ def test_with_any_args_and_1_argtest_with_any_args_and_1_arg115,2535
593
+
580
594
  test/test_samples.rb,2164
581
595
  class TestSamples < Test::Unit::TestCaseTestSamples17,378
582
596
  def test_file_iotest_file_io25,748
@@ -636,7 +650,7 @@ class TestShouldIgnoreMissing < Test::Unit::TestCaseTestShouldIgnoreMissing16,
636
650
  def test_not_calling_method_proc_will_fail_count_constraintstest_not_calling_method_proc_will_fail_count_constraints66,1693
637
651
  def test_method_returns_do_nothing_proc_for_missing_methodstest_method_returns_do_nothing_proc_for_missing_methods75,1965
638
652
 
639
- test/test_should_receive.rb,10635
653
+ test/test_should_receive.rb,10636
640
654
  def mock_top_level_functionmock_top_level_function16,375
641
655
  module KernelKernel20,416
642
656
  def mock_kernel_functionmock_kernel_function21,430
@@ -735,20 +749,20 @@ class TestFlexMockShoulds < Test::Unit::TestCaseTestFlexMockShoulds26,477
735
749
  def test_expectations_with_count_constraints_can_by_marked_as_defaulttest_expectations_with_count_constraints_can_by_marked_as_default902,23069
736
750
  def test_default_expectations_are_overridden_by_later_expectationstest_default_expectations_are_overridden_by_later_expectations910,23315
737
751
  def test_default_expectations_can_be_changed_by_later_expectationstest_default_expectations_can_be_changed_by_later_expectations918,23543
738
- def test_ordered_default_expectations_can_be_specifiedtest_ordered_default_expectations_can_be_specified926,23792
739
- def test_ordered_default_expectations_can_be_overriddentest_ordered_default_expectations_can_be_overridden934,24043
740
- def test_by_default_works_at_mock_leveltest_by_default_works_at_mock_level946,24314
741
- def test_by_default_at_mock_level_does_nothing_with_no_expectationstest_by_default_at_mock_level_does_nothing_with_no_expectations957,24589
742
- def test_partial_mocks_can_have_default_expectationstest_partial_mocks_can_have_default_expectations963,24734
743
- def test_partial_mocks_can_have_default_expectations_overriddentest_partial_mocks_can_have_default_expectations_overridden969,24915
744
- def test_wicked_and_evil_tricks_with_by_default_are_thwartedtest_wicked_and_evil_tricks_with_by_default_are_thwarted976,25163
745
- def test_mocks_can_handle_multi_parameter_respond_tostest_mocks_can_handle_multi_parameter_respond_tos988,25568
746
- def test_can_mock_operatorstest_can_mock_operators999,25915
747
- def assert_operator(op, &block)assert_operator1028,26930
748
- class TestFlexMockShouldsWithInclude < Test::Unit::TestCaseTestFlexMockShouldsWithInclude1036,27084
749
- def test_include_enables_unqualified_arg_type_referencestest_include_enables_unqualified_arg_type_references1038,27178
750
- class TestFlexMockArgTypesDontLeak < Test::Unit::TestCaseTestFlexMockArgTypesDontLeak1046,27342
751
- def test_unqualified_arg_type_references_are_undefined_by_defaulttest_unqualified_arg_type_references_are_undefined_by_default1047,27400
752
+ def test_ordered_default_expectations_can_be_specifiedtest_ordered_default_expectations_can_be_specified929,23915
753
+ def test_ordered_default_expectations_can_be_overriddentest_ordered_default_expectations_can_be_overridden937,24166
754
+ def test_by_default_works_at_mock_leveltest_by_default_works_at_mock_level949,24437
755
+ def test_by_default_at_mock_level_does_nothing_with_no_expectationstest_by_default_at_mock_level_does_nothing_with_no_expectations960,24712
756
+ def test_partial_mocks_can_have_default_expectationstest_partial_mocks_can_have_default_expectations966,24857
757
+ def test_partial_mocks_can_have_default_expectations_overriddentest_partial_mocks_can_have_default_expectations_overridden972,25038
758
+ def test_wicked_and_evil_tricks_with_by_default_are_thwartedtest_wicked_and_evil_tricks_with_by_default_are_thwarted979,25286
759
+ def test_mocks_can_handle_multi_parameter_respond_tostest_mocks_can_handle_multi_parameter_respond_tos991,25691
760
+ def test_can_mock_operatorstest_can_mock_operators1002,26038
761
+ def assert_operator(op, &block)assert_operator1031,27053
762
+ class TestFlexMockShouldsWithInclude < Test::Unit::TestCaseTestFlexMockShouldsWithInclude1039,27207
763
+ def test_include_enables_unqualified_arg_type_referencestest_include_enables_unqualified_arg_type_references1041,27301
764
+ class TestFlexMockArgTypesDontLeak < Test::Unit::TestCaseTestFlexMockArgTypesDontLeak1049,27465
765
+ def test_unqualified_arg_type_references_are_undefined_by_defaulttest_unqualified_arg_type_references_are_undefined_by_default1050,27523
752
766
 
753
767
  test/test_tu_integration.rb,1570
754
768
  class TestTuIntegrationFlexMockMethod < Test::Unit::TestCaseTestTuIntegrationFlexMockMethod15,352
@@ -784,3 +798,9 @@ class UndefinedTest < Test::Unit::TestCaseUndefinedTest15,352
784
798
  def test_undefined_is_not_niltest_undefined_is_not_nil75,1934
785
799
  def assert_undefined(obj)assert_undefined81,2012
786
800
  def undefinedundefined85,2075
801
+
802
+ test/test_unit_integration/test_auto_test_unit.rb,263
803
+ class TestFlexmockTestUnit < Test::Unit::TestCaseTestFlexmockTestUnit17,387
804
+ def teardownteardown18,437
805
+ def test_can_create_mockstest_can_create_mocks23,496
806
+ def test_should_fail__mocks_are_auto_verifiedtest_should_fail__mocks_are_auto_verified30,641
@@ -0,0 +1,94 @@
1
+ = FlexMock 0.8.3 Released
2
+
3
+ FlexMock is a flexible mocking library for use in unit testing and
4
+ behavior specification in Ruby. Release 0.8.3 is a minor release with
5
+ a few bug fixes.
6
+
7
+ == Bug Fixes in 0.8.3
8
+
9
+ * Fixed a bug where the by_default option was not completely honored
10
+ in some edge cases.
11
+
12
+ == What is FlexMock?
13
+
14
+ FlexMock is a flexible framework for creating mock object for testing. When
15
+ running unit tests, it is often desirable to use isolate the objects being
16
+ tested from the "real world" by having them interact with simplified test
17
+ objects. Sometimes these test objects simply return values when called, other
18
+ times they verify that certain methods were called with particular arguments
19
+ in a particular order.
20
+
21
+ FlexMock makes creating these test objects easy.
22
+
23
+ === Features
24
+
25
+ * Easy integration with both Test::Unit and RSpec. Mocks created with the
26
+ flexmock method are automatically verified at the end of the test or
27
+ example.
28
+
29
+ * A fluent interface that allows mock behavior to be specified very
30
+ easily.
31
+
32
+ * A "record mode" where an existing implementation can record its
33
+ interaction with a mock for later validation against a new
34
+ implementation.
35
+
36
+ * Easy mocking of individual methods in existing, non-mock objects.
37
+
38
+ * Easy mocking of chains of method calls.
39
+
40
+ * The ability to cause classes to instantiate test instances (instead of real
41
+ instances) for the duration of a test.
42
+
43
+ === Example
44
+
45
+ Suppose you had a Dog object that wagged a tail when it was happy.
46
+ Something like this:
47
+
48
+ class Dog
49
+ def initialize(a_tail)
50
+ @tail = a_tail
51
+ end
52
+ def happy
53
+ @tail.wag
54
+ end
55
+ end
56
+
57
+ To test the +Dog+ class without a real +Tail+ object (perhaps because
58
+ real +Tail+ objects activate servos in some robotic equipment), you
59
+ can do something like this:
60
+
61
+ require 'test/unit'
62
+ require 'flexmock/test_unit'
63
+
64
+ class TestDog < Test::Unit::TestCase
65
+ def test_dog_wags_tail_when_happy
66
+ tail = flexmock("tail")
67
+ tail.should_receive(:wag).once
68
+ dog = Dog.new(tail)
69
+ dog.happy
70
+ end
71
+ end
72
+
73
+ FlexMock will automatically verify that the mocked tail object received the
74
+ message +wag+ exactly one time. If it doesn't, the test will not pass.
75
+
76
+ See the FlexMock documentation at http://flexmock.rubyforge.org for details on
77
+ specifying arguments and return values on mocked methods, as well as a simple
78
+ technique for mocking tail objects when the Dog class creates the tail objects
79
+ directly.
80
+
81
+ == Availability
82
+
83
+ You can make sure you have the latest version with a quick RubyGems command:
84
+
85
+ gem install flexmock (you may need root/admin privileges)
86
+
87
+ Otherwise, you can get it from the more traditional places:
88
+
89
+ Download:: http://rubyforge.org/project/showfiles.php?group_id=170
90
+
91
+ You will find documentation at: http://flexmock.rubyforge.org.
92
+
93
+ -- Jim Weirich
94
+
@@ -0,0 +1,93 @@
1
+ = FlexMock 0.8.4 Released
2
+
3
+ FlexMock is a flexible mocking library for use in unit testing and
4
+ behavior specification in Ruby. Release 0.8.4 is a minor release with
5
+ a few bug fixes.
6
+
7
+ == Bug Fixes in 0.8.4
8
+
9
+ * The should_render_view method is now compatible with Rails 2.2.2.
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
+ * Easy mocking of chains of method calls.
38
+
39
+ * The ability to cause classes to instantiate test instances (instead of real
40
+ instances) for the duration of a test.
41
+
42
+ === Example
43
+
44
+ Suppose you had a Dog object that wagged a tail when it was happy.
45
+ Something like this:
46
+
47
+ class Dog
48
+ def initialize(a_tail)
49
+ @tail = a_tail
50
+ end
51
+ def happy
52
+ @tail.wag
53
+ end
54
+ end
55
+
56
+ To test the +Dog+ class without a real +Tail+ object (perhaps because
57
+ real +Tail+ objects activate servos in some robotic equipment), you
58
+ can do something like this:
59
+
60
+ require 'test/unit'
61
+ require 'flexmock/test_unit'
62
+
63
+ class TestDog < Test::Unit::TestCase
64
+ def test_dog_wags_tail_when_happy
65
+ tail = flexmock("tail")
66
+ tail.should_receive(:wag).once
67
+ dog = Dog.new(tail)
68
+ dog.happy
69
+ end
70
+ end
71
+
72
+ FlexMock will automatically verify that the mocked tail object received the
73
+ message +wag+ exactly one time. If it doesn't, the test will not pass.
74
+
75
+ See the FlexMock documentation at http://flexmock.rubyforge.org for details on
76
+ specifying arguments and return values on mocked methods, as well as a simple
77
+ technique for mocking tail objects when the Dog class creates the tail objects
78
+ directly.
79
+
80
+ == Availability
81
+
82
+ You can make sure you have the latest version with a quick RubyGems command:
83
+
84
+ gem install flexmock (you may need root/admin privileges)
85
+
86
+ Otherwise, you can get it from the more traditional places:
87
+
88
+ Download:: http://rubyforge.org/project/showfiles.php?group_id=170
89
+
90
+ You will find documentation at: http://flexmock.rubyforge.org.
91
+
92
+ -- Jim Weirich
93
+
@@ -53,5 +53,34 @@ class FlexMock
53
53
  end
54
54
  end
55
55
 
56
+ ####################################################################
57
+ # Match only things where the block evaluates to true.
58
+ class HashMatcher
59
+ def initialize(hash)
60
+ @hash = hash
61
+ end
62
+ def ===(target)
63
+ @hash.all? { |k, v| target[k] == v }
64
+ end
65
+ def inspect
66
+ "hsh(#{@hash.inspect})"
67
+ "hsh(...)"
68
+ end
69
+ end
70
+
71
+ ####################################################################
72
+ # Match only things where the block evaluates to true.
73
+ class DuckMatcher
74
+ def initialize(methods)
75
+ @methods = methods
76
+ end
77
+ def ===(target)
78
+ @methods.all? { |m| target.respond_to?(m) }
79
+ end
80
+ def inspect
81
+ "ducktype(#{@methods.map{|m| m.inspect}.join(',')})"
82
+ end
83
+ end
84
+
56
85
 
57
86
  end
@@ -36,6 +36,18 @@ class FlexMock
36
36
  def on(&block)
37
37
  ProcMatcher.new(&block)
38
38
  end
39
+
40
+ # Return an argument matcher that matches a hash with the given
41
+ # entries.
42
+ def hsh(hash)
43
+ HashMatcher.new(hash)
44
+ end
45
+
46
+ # Return an argument matcher that matches any object that
47
+ # implementes (i.e. responds to) the given method list.
48
+ def ducktype(*methods)
49
+ DuckMatcher.new(methods)
50
+ end
39
51
  end
40
52
  extend ArgumentTypes
41
53
 
@@ -11,6 +11,7 @@
11
11
 
12
12
  require 'flexmock/noop'
13
13
  require 'flexmock/argument_types'
14
+ require 'flexmock/ordering'
14
15
 
15
16
  class FlexMock
16
17
 
@@ -207,24 +208,28 @@ class FlexMock
207
208
  # models.
208
209
  def add_model_methods(mock, model_class, id)
209
210
  container = mock.flexmock_container
210
- mock.should_receive(
211
- :id => id,
212
- :to_params => id.to_s,
213
- :new_record? => false,
214
- :class => model_class,
215
- :errors => container.flexmock("errors", :count => 0))
211
+
212
+ mock_errors = container.flexmock("errors")
213
+ mock_errors.should_receive(:count).and_return(0).by_default
214
+
215
+ mock.should_receive(:id).and_return(id).by_default
216
+ mock.should_receive(:to_params).and_return(id.to_s).by_default
217
+ mock.should_receive(:new_record?).and_return(false).by_default
218
+ mock.should_receive(:class).and_return(model_class).by_default
219
+ mock.should_receive(:errors).and_return(mock_errors).by_default
220
+
216
221
  # HACK: Ruby 1.9 needs the following lambda so that model_class
217
222
  # is correctly bound below.
218
223
  lambda { }
219
224
  mock.should_receive(:is_a?).with(any).and_return { |other|
220
225
  other == model_class
221
- }
226
+ }.by_default
222
227
  mock.should_receive(:instance_of?).with(any).and_return { |other|
223
228
  other == model_class
224
- }
229
+ }.by_default
225
230
  mock.should_receive(:kind_of?).with(any).and_return { |other|
226
231
  model_class.ancestors.include?(other)
227
- }
232
+ }.by_default
228
233
  end
229
234
 
230
235
  # Create a PartialMockProxy for the given object. Use +name+ as
@@ -27,8 +27,10 @@ class FlexMock
27
27
  should_render_view_prior_version_124(template_name)
28
28
  elsif rails_version <= '2.0.0'
29
29
  should_render_view_after_version_124(template_name)
30
- else
30
+ elsif rails_version < '2.2'
31
31
  should_render_view_after_version_202(template_name)
32
+ else
33
+ should_render_view_22x(template_name)
32
34
  end
33
35
  end
34
36
 
@@ -97,6 +99,25 @@ class FlexMock
97
99
  end
98
100
  flexmock(ActionView::Base).should_receive(:new).and_return(viewmock)
99
101
  end
100
-
102
+
103
+ # This version of should_render_view will work with versions of
104
+ # Rails at Version 2.2.x.
105
+ def should_render_view_22x(template_name)
106
+ viewmock = flexmock("ViewMock")
107
+ viewmock.should_receive(
108
+ :helpers => viewmock,
109
+ :include => nil,
110
+ :template_format =>nil,
111
+ :render => "RENDERED TEXT",
112
+ :assigns => {})
113
+ if template_name
114
+ viewmock.should_receive(:_exempt_from_layout?).with(/\/#{template_name}$/).
115
+ and_return(true).once
116
+ viewmock.should_receive(:_exempt_from_layout?).and_return(true)
117
+ else
118
+ viewmock.should_receive(:_exempt_from_layout?).at_least.once.and_return(true)
119
+ end
120
+ flexmock(ActionView::Base).should_receive(:new).and_return(viewmock)
121
+ end
101
122
  end
102
123
  end
@@ -23,6 +23,14 @@ module Kernel
23
23
  end
24
24
  end
25
25
 
26
+ # Used for testing
27
+ class Cat
28
+ def purr
29
+ end
30
+ def meow
31
+ end
32
+ end
33
+
26
34
  class TestFlexMockShoulds < Test::Unit::TestCase
27
35
  include FlexMock::TestCase
28
36
  include FlexMock::FailureAssertion
@@ -357,6 +365,38 @@ class TestFlexMockShoulds < Test::Unit::TestCase
357
365
  end
358
366
  end
359
367
 
368
+ def test_with_ducktype_arg_matching
369
+ FlexMock.use('greeter') do |m|
370
+ m.should_receive(:hi).with(FlexMock.ducktype(:purr, :meow)).once
371
+ m.hi(Cat.new)
372
+ end
373
+ end
374
+
375
+ def test_with_ducktype_arg_matching_no_match
376
+ FlexMock.use('greeter') do |m|
377
+ m.should_receive(:hi).with(FlexMock.ducktype(:purr, :meow, :growl))
378
+ assert_failure {
379
+ m.hi(Cat.new)
380
+ }
381
+ end
382
+ end
383
+
384
+ def test_with_hash_matching
385
+ FlexMock.use('greeter') do |m|
386
+ m.should_receive(:hi).with(FlexMock.hsh(:a => 1, :b => 2)).once
387
+ m.hi(:a => 1, :b => 2, :c => 3)
388
+ end
389
+ end
390
+
391
+ def test_with_hash_non_matching
392
+ FlexMock.use('greeter') do |m|
393
+ m.should_receive(:hi).with(FlexMock.hsh(:a => 1, :b => 2))
394
+ assert_failure {
395
+ m.hi(:a => 1, :b => 4, :c => 3)
396
+ }
397
+ end
398
+ end
399
+
360
400
  def test_with_equal_arg_nonmatching
361
401
  FlexMock.use('greeter') do |m|
362
402
  m.should_receive(:hi).with(FlexMock.eq(Object)).never
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Weirich
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-03 00:00:00 -04:00
12
+ date: 2009-02-19 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -38,6 +38,8 @@ extra_rdoc_files:
38
38
  - doc/releases/flexmock-0.7.1.rdoc
39
39
  - doc/releases/flexmock-0.8.0.rdoc
40
40
  - doc/releases/flexmock-0.8.2.rdoc
41
+ - doc/releases/flexmock-0.8.3.rdoc
42
+ - doc/releases/flexmock-0.8.4.rdoc
41
43
  files:
42
44
  - CHANGES
43
45
  - Rakefile
@@ -107,8 +109,10 @@ files:
107
109
  - doc/releases/flexmock-0.7.1.rdoc
108
110
  - doc/releases/flexmock-0.8.0.rdoc
109
111
  - doc/releases/flexmock-0.8.2.rdoc
112
+ - doc/releases/flexmock-0.8.3.rdoc
113
+ - doc/releases/flexmock-0.8.4.rdoc
110
114
  has_rdoc: true
111
- homepage: http://onestepback.org/software/flexmock
115
+ homepage: http://flexmock.rubyforge.org
112
116
  post_install_message:
113
117
  rdoc_options:
114
118
  - --title
@@ -133,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
137
  requirements: []
134
138
 
135
139
  rubyforge_project:
136
- rubygems_version: 1.2.0
140
+ rubygems_version: 1.3.1
137
141
  signing_key:
138
142
  specification_version: 2
139
143
  summary: Simple and Flexible Mock Objects for Testing