flexmock 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,11 @@
1
1
  = Changes for FlexMock
2
2
 
3
+ == Pre-Version 0.8.1
4
+
5
+ * Added Joe O'Brien's patch to allow view stubbing in Rails 2.0
6
+ * Added Evan Phoenix's patch to remove allocate from default
7
+ allocators in new_instances (for Rubinius compatibility).
8
+
3
9
  == Version 0.8.0
4
10
 
5
11
  * Added by_default
data/README CHANGED
@@ -3,7 +3,7 @@ examples= Flex Mock -- Making Mock Easy
3
3
  FlexMock is a simple, but flexible, mock object library for Ruby unit
4
4
  testing.
5
5
 
6
- Version :: 0.8.0
6
+ Version :: 0.8.1
7
7
 
8
8
  = Links
9
9
 
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.0'
22
+ PKG_VERSION = '0.8.1'
23
23
 
24
24
  PKG_FILES = FileList[
25
25
  '[A-Z]*',
data/TAGS CHANGED
@@ -1,12 +1,10 @@
1
1
 
2
- install.rb,29
3
- def indir(newdir)indir7,68
4
-
5
2
  doc/jamis.rb,43
6
3
  module RDocRDoc1,0
7
4
  module PagePage2,12
8
5
 
9
- lib/flexmock.rb,0
6
+ install.rb,29
7
+ def indir(newdir)indir7,68
10
8
 
11
9
  lib/flexmock/argument_matchers.rb,424
12
10
  class FlexMockFlexMock14,338
@@ -34,23 +32,24 @@ lib/flexmock/base.rb,0
34
32
  lib/flexmock/composite.rb,30
35
33
  class FlexMockFlexMock8,133
36
34
 
37
- lib/flexmock/core.rb,857
35
+ lib/flexmock/core.rb,900
38
36
  class FlexMockFlexMock46,1290
39
37
  def initialize(name="unknown", container=nil)initialize55,1560
40
38
  def inspectinspect65,1854
41
39
  def flexmock_verifyflexmock_verify71,2014
42
40
  def flexmock_teardownflexmock_teardown82,2255
43
41
  def should_ignore_missingshould_ignore_missing86,2335
44
- def method_missing(sym, *args, &block)method_missing92,2510
45
- def respond_to?(sym)respond_to?109,2982
46
- def flexmock_find_expectation(method_name, *args) # :nodoc:flexmock_find_expectation114,3131
47
- def flexmock_expectations_for(method_name) # :nodoc:flexmock_expectations_for120,3336
48
- def method(sym)method125,3495
49
- def should_receive(*args)should_receive154,4534
50
- def should_expectshould_expect176,5237
51
- def flexmock_wrap(&block)flexmock_wrap184,5427
52
- def override_existing_method(sym)override_existing_method198,5986
53
- def sclasssclass207,6206
42
+ def by_defaultby_default91,2447
43
+ def method_missing(sym, *args, &block)method_missing97,2576
44
+ def respond_to?(sym, *args)respond_to?114,3048
45
+ def flexmock_find_expectation(method_name, *args) # :nodoc:flexmock_find_expectation119,3204
46
+ def flexmock_expectations_for(method_name) # :nodoc:flexmock_expectations_for125,3409
47
+ def method(sym)method130,3568
48
+ def should_receive(*args)should_receive159,4607
49
+ def should_expectshould_expect182,5352
50
+ def flexmock_wrap(&block)flexmock_wrap190,5542
51
+ def override_existing_method(sym)override_existing_method204,6101
52
+ def sclasssclass213,6321
54
53
 
55
54
  lib/flexmock/core_class_methods.rb,289
56
55
  class FlexMockFlexMock15,371
@@ -91,44 +90,44 @@ class FlexMockFlexMock14,337
91
90
  def verify_call(*args)verify_call55,1562
92
91
  def _return_value(args) # :nodoc:_return_value64,1782
93
92
  def return_value(args)return_value69,1922
94
- def perform_yielding(args)perform_yielding83,2245
95
- def eligible?eligible?99,2822
96
- def call_count_constrained?call_count_constrained?104,2971
97
- def validate_ordervalidate_order109,3081
98
- def flexmock_verifyflexmock_verify121,3456
99
- def match_args(args)match_args129,3653
100
- def match_arg(expected, actual)match_arg138,3999
101
- def with(*args)with145,4228
102
- def with_no_argswith_no_args151,4362
103
- def with_any_argswith_any_args157,4495
104
- def and_return(*args, &block)and_return188,5504
105
- def and_return_undefinedand_return_undefined212,6217
106
- def and_yield(*yield_values)and_yield228,6786
107
- def and_raise(exception, *args)and_raise252,7549
108
- def and_throw(sym, value=nil)and_throw266,7914
109
- def zero_or_more_timeszero_or_more_times272,8089
110
- def times(limit)times279,8312
111
- def nevernever288,8659
112
- def onceonce295,8874
113
- def twicetwice302,9089
114
- def at_leastat_least314,9415
115
- def at_mostat_most327,9794
116
- def ordered(group_name=nil)ordered356,11063
117
- def globallyglobally368,11443
118
- def define_ordered(group_name, ordering)define_ordered374,11558
119
- def by_defaultby_default388,12056
120
- class CompositeExpectationCompositeExpectation399,12463
121
- def initializeinitialize402,12537
122
- def add(expectation)add407,12633
123
- def method_missing(sym, *args, &block)method_missing412,12774
124
- def order_numberorder_number423,13153
125
- def mockmock428,13263
126
- def should_receive(*args, &block)should_receive434,13431
127
- def to_sto_s439,13577
128
- class ExpectationRecorderExpectationRecorder453,14035
129
- def initializeinitialize456,14095
130
- def method_missing(sym, *args, &block)method_missing461,14206
131
- def apply(mock)apply469,14482
93
+ def perform_yielding(args)perform_yielding83,2253
94
+ def eligible?eligible?99,2839
95
+ def call_count_constrained?call_count_constrained?104,2988
96
+ def validate_ordervalidate_order109,3098
97
+ def flexmock_verifyflexmock_verify121,3473
98
+ def match_args(args)match_args129,3670
99
+ def match_arg(expected, actual)match_arg138,4016
100
+ def with(*args)with145,4245
101
+ def with_no_argswith_no_args151,4379
102
+ def with_any_argswith_any_args157,4512
103
+ def and_return(*args, &block)and_return188,5521
104
+ def and_return_undefinedand_return_undefined212,6239
105
+ def and_yield(*yield_values)and_yield228,6808
106
+ def and_raise(exception, *args)and_raise252,7571
107
+ def and_throw(sym, value=nil)and_throw266,7936
108
+ def zero_or_more_timeszero_or_more_times272,8111
109
+ def times(limit)times279,8334
110
+ def nevernever288,8681
111
+ def onceonce295,8896
112
+ def twicetwice302,9111
113
+ def at_leastat_least314,9437
114
+ def at_mostat_most327,9816
115
+ def ordered(group_name=nil)ordered356,11085
116
+ def globallyglobally368,11465
117
+ def define_ordered(group_name, ordering)define_ordered374,11580
118
+ def by_defaultby_default388,12078
119
+ class CompositeExpectationCompositeExpectation399,12485
120
+ def initializeinitialize402,12559
121
+ def add(expectation)add407,12655
122
+ def method_missing(sym, *args, &block)method_missing412,12796
123
+ def order_numberorder_number423,13175
124
+ def mockmock428,13285
125
+ def should_receive(*args, &block)should_receive434,13453
126
+ def to_sto_s439,13599
127
+ class ExpectationRecorderExpectationRecorder453,14057
128
+ def initializeinitialize456,14117
129
+ def method_missing(sym, *args, &block)method_missing461,14228
130
+ def apply(mock)apply469,14504
132
131
 
133
132
  lib/flexmock/expectation_director.rb,483
134
133
  class FlexMockFlexMock15,363
@@ -139,7 +138,7 @@ class FlexMockFlexMock15,363
139
138
  def find_expectation(*args) # :nodoc:find_expectation51,1584
140
139
  def flexmock_verify # :nodoc:flexmock_verify59,1909
141
140
  def defaultify_expectation(exp) # :nodoc:defaultify_expectation66,2120
142
- def find_expectation_in(expectations, *args)find_expectation_in78,2431
141
+ def find_expectation_in(expectations, *args)find_expectation_in78,2401
143
142
 
144
143
  lib/flexmock/mock_container.rb,882
145
144
  class FlexMockFlexMock15,371
@@ -153,10 +152,10 @@ class FlexMockFlexMock15,371
153
152
  def next_idnext_id177,6719
154
153
  def parse_should_args(mock, args, &block) # :nodoc:parse_should_args190,7192
155
154
  def add_model_methods(mock, model_class, id)add_model_methods208,7705
156
- def make_partial_proxy(container, obj, name, safe_mode)make_partial_proxy229,8443
157
- def build_demeter_chain(mock, arg, &block)build_demeter_chain274,10296
158
- def check_proper_mock(mock, method_name)check_proper_mock299,11147
159
- def check_method_names(names)check_method_names309,11554
155
+ def make_partial_proxy(container, obj, name, safe_mode)make_partial_proxy232,8564
156
+ def build_demeter_chain(mock, arg, &block)build_demeter_chain277,10417
157
+ def check_proper_mock(mock, method_name)check_proper_mock302,11268
158
+ def check_method_names(names)check_method_names312,11675
160
159
 
161
160
  lib/flexmock/noop.rb,0
162
161
 
@@ -173,26 +172,36 @@ lib/flexmock/partial_mock.rb,1380
173
172
  class FlexMockFlexMock14,337
174
173
  class PartialMockProxyPartialMockProxy26,968
175
174
  def initialize(obj, mock, safe_mode)initialize40,1310
176
- def flexmock_getflexmock_get53,1620
177
- def should_receive(*args)should_receive77,2560
178
- def add_mock_method(obj, method_name)add_mock_method88,2838
179
- def new_instances(*allocators, &block)new_instances114,3788
180
- def invoke_original(method, args)invoke_original132,4419
181
- def flexmock_verifyflexmock_verify140,4713
182
- def flexmock_teardownflexmock_teardown145,4849
183
- def flexmock_containerflexmock_container157,5187
184
- def flexmock_container=(container)flexmock_container=163,5382
185
- def flexmock_expectations_for(method_name)flexmock_expectations_for167,5498
186
- def sclasssclass174,5659
187
- def singleton?(method_name)singleton?180,5800
188
- def hide_existing_method(method_name)hide_existing_method190,6262
189
- def stow_existing_definition(method_name)stow_existing_definition197,6479
190
- def create_alias_for_existing_method(method_name)create_alias_for_existing_method217,7196
191
- def define_proxy_method(method_name)define_proxy_method235,7715
192
- def restore_original_definition(method_name)restore_original_definition256,8415
193
- def remove_current_method(method_name)remove_current_method268,8779
194
- def detached?detached?273,8940
195
- def new_name(old_name)new_name278,9048
175
+ def flexmock_getflexmock_get55,1675
176
+ def should_receive(*args)should_receive79,2615
177
+ def add_mock_method(obj, method_name)add_mock_method90,2893
178
+ def new_instances(*allocators, &block)new_instances118,3947
179
+ def invoke_original(method, args)invoke_original139,4749
180
+ def flexmock_verifyflexmock_verify147,5043
181
+ def flexmock_teardownflexmock_teardown152,5179
182
+ def flexmock_containerflexmock_container164,5517
183
+ def flexmock_container=(container)flexmock_container=170,5712
184
+ def flexmock_expectations_for(method_name)flexmock_expectations_for174,5828
185
+ def sclasssclass181,5989
186
+ def singleton?(method_name)singleton?187,6130
187
+ def hide_existing_method(method_name)hide_existing_method197,6592
188
+ def stow_existing_definition(method_name)stow_existing_definition204,6809
189
+ def create_alias_for_existing_method(method_name)create_alias_for_existing_method224,7526
190
+ def define_proxy_method(method_name)define_proxy_method242,8045
191
+ def restore_original_definition(method_name)restore_original_definition263,8745
192
+ def remove_current_method(method_name)remove_current_method275,9109
193
+ def detached?detached?280,9270
194
+ def new_name(old_name)new_name285,9378
195
+
196
+ lib/flexmock/rails/view_mocking.rb,404
197
+ class FlexMockFlexMock3,20
198
+ module MockContainerMockContainer4,35
199
+ def rails_versionrails_version6,59
200
+ def should_render_view(template_name=nil)should_render_view25,684
201
+ def should_render_view_prior_version_124(template_name) # :nodoc:should_render_view_prior_version_12437,1045
202
+ def should_render_view_after_version_124(template_name)should_render_view_after_version_12457,1795
203
+
204
+ lib/flexmock/rails.rb,0
196
205
 
197
206
  lib/flexmock/recorder.rb,271
198
207
  class FlexMockFlexMock14,347
@@ -246,6 +255,8 @@ class FlexMockFlexMock14,337
246
255
  class AtMostCountValidator < CountValidatorAtMostCountValidator69,2058
247
256
  def validate(n)validate71,2173
248
257
 
258
+ lib/flexmock.rb,0
259
+
249
260
  test/asserts.rb,139
250
261
  class FlexMockFlexMock12,312
251
262
  module FailureAssertionFailureAssertion15,368
@@ -256,6 +267,8 @@ class FlexMockFlexMock3,20
256
267
  module RedirectErrorRedirectError4,35
257
268
  def redirect_errorredirect_error5,58
258
269
 
270
+ test/rspec_integration/integration_spec.rb,0
271
+
259
272
  test/test_aliasing.rb,522
260
273
  class FlexMockFlexMock6,61
261
274
  module StubsAndExpectsStubsAndExpects7,76
@@ -323,36 +336,52 @@ class TestFlexMock < Test::Unit::TestCaseTestFlexMock17,420
323
336
  def test_called_with_blocktest_called_with_block42,898
324
337
  def test_return_valuetest_return_value49,1096
325
338
  def test_handle_missing_methodtest_handle_missing_method54,1201
326
- def test_ignore_missing_methodtest_ignore_missing_method62,1426
327
- def test_good_countstest_good_counts68,1557
328
- def test_bad_countstest_bad_counts76,1696
329
- def test_undetermined_countstest_undetermined_counts87,1913
330
- def test_zero_countstest_zero_counts96,2058
331
- def test_file_io_with_usetest_file_io_with_use105,2237
332
- def count_lines(stream)count_lines113,2441
333
- def test_usetest_use121,2559
334
- def test_failures_during_usetest_failures_during_use130,2716
335
- def test_sequential_valuestest_sequential_values140,2935
336
- def test_respond_to_returns_false_for_non_handled_methodstest_respond_to_returns_false_for_non_handled_methods149,3169
337
- def test_respond_to_returns_true_for_explicit_methodstest_respond_to_returns_true_for_explicit_methods153,3304
338
- def test_respond_to_returns_true_for_missing_methods_when_ignoring_missingtest_respond_to_returns_true_for_missing_methods_when_ignoring_missing158,3463
339
- def test_respond_to_returns_true_for_missing_methods_when_ignoring_missing_using_shouldtest_respond_to_returns_true_for_missing_methods_when_ignoring_missing_using_should163,3644
340
- def test_method_proc_raises_error_on_unknowntest_method_proc_raises_error_on_unknown168,3840
341
- def test_method_returns_callable_proctest_method_returns_callable_proc174,3958
342
- def test_method_returns_do_nothing_proc_for_missing_methodstest_method_returns_do_nothing_proc_for_missing_methods183,4214
343
- class TestDeprecatedOrderingMethods < Test::Unit::TestCaseTestDeprecatedOrderingMethods191,4441
344
- def test_deprecated_ordering_methodstest_deprecated_ordering_methods195,4564
345
- class TestAnyInstance < Test::Unit::TestCaseTestAnyInstance207,4960
346
- class DogDog211,5069
347
- def barkbark212,5081
348
- def test_any_instance_still_works_for_backwards_compatibilitytest_any_instance_still_works_for_backwards_compatibility217,5121
349
-
350
- test/test_example.rb,278
339
+ def test_ignore_missing_methodtest_ignore_missing_method62,1431
340
+ def test_good_countstest_good_counts68,1562
341
+ def test_bad_countstest_bad_counts76,1701
342
+ def test_undetermined_countstest_undetermined_counts87,1918
343
+ def test_zero_countstest_zero_counts96,2063
344
+ def test_file_io_with_usetest_file_io_with_use105,2242
345
+ def count_lines(stream)count_lines113,2446
346
+ def test_usetest_use121,2564
347
+ def test_failures_during_usetest_failures_during_use130,2721
348
+ def test_sequential_valuestest_sequential_values140,2940
349
+ def test_respond_to_returns_false_for_non_handled_methodstest_respond_to_returns_false_for_non_handled_methods149,3174
350
+ def test_respond_to_returns_true_for_explicit_methodstest_respond_to_returns_true_for_explicit_methods153,3309
351
+ def test_respond_to_returns_true_for_missing_methods_when_ignoring_missingtest_respond_to_returns_true_for_missing_methods_when_ignoring_missing158,3468
352
+ def test_respond_to_returns_true_for_missing_methods_when_ignoring_missing_using_shouldtest_respond_to_returns_true_for_missing_methods_when_ignoring_missing_using_should163,3649
353
+ def test_method_proc_raises_error_on_unknowntest_method_proc_raises_error_on_unknown168,3845
354
+ def test_method_returns_callable_proctest_method_returns_callable_proc174,3963
355
+ def test_method_returns_do_nothing_proc_for_missing_methodstest_method_returns_do_nothing_proc_for_missing_methods183,4219
356
+ class TestDeprecatedOrderingMethods < Test::Unit::TestCaseTestDeprecatedOrderingMethods191,4446
357
+ def test_deprecated_ordering_methodstest_deprecated_ordering_methods195,4569
358
+ class TestAnyInstance < Test::Unit::TestCaseTestAnyInstance207,4965
359
+ class DogDog211,5074
360
+ def barkbark212,5086
361
+ def test_any_instance_still_works_for_backwards_compatibilitytest_any_instance_still_works_for_backwards_compatibility217,5126
362
+
363
+ test/test_examples_from_readme.rb,1207
351
364
  class TemperatureSamplerTemperatureSampler15,352
352
365
  def initialize(sensor)initialize16,377
353
366
  def average_tempaverage_temp20,430
354
367
  class TestTemperatureSampler < Test::Unit::TestCaseTestTemperatureSampler26,557
355
368
  def test_tempurature_samplertest_tempurature_sampler29,639
369
+ class TestExamplesFromReadme < Test::Unit::TestCaseTestExamplesFromReadme38,918
370
+ def test_simple_return_valuestest_simple_return_values41,1000
371
+ def test_returning_an_undefined_valuetest_returning_an_undefined_value47,1140
372
+ def test_dbtest_db53,1280
373
+ def test_query_and_updatetest_query_and_update62,1510
374
+ def test_ordered_queriestest_ordered_queries71,1763
375
+ def test_ordered_queries_in_record_modetest_ordered_queries_in_record_mode89,2362
376
+ def test_build_xmltest_build_xml106,2894
377
+ def known_good_way_to_build_xml(rec)known_good_way_to_build_xml115,3149
378
+ def new_way_to_build_xml(rec)new_way_to_build_xml120,3219
379
+ def test_multiple_getstest_multiple_gets124,3307
380
+ def test_an_important_messagetest_an_important_message133,3552
381
+ class QuoteServiceQuoteService142,3782
382
+ class PortfolioPortfolio144,3809
383
+ def valuevalue145,3827
384
+ def test_portfolio_valuetest_portfolio_value150,3887
356
385
 
357
386
  test/test_extended_should_receive.rb,809
358
387
  module ExtendedShouldReceiveTestsExtendedShouldReceiveTests15,352
@@ -367,14 +396,14 @@ class TestExtendedShouldReceiveOnPartialMockProxies < Test::Unit::TestCaseTestE
367
396
  def setupsetup65,1770
368
397
 
369
398
  test/test_flexmodel.rb,528
370
- class DummyModelDummyModel5,42
371
- class ChildModel < DummyModelChildModel8,64
372
- class TestFlexModel < Test::Unit::TestCaseTestFlexModel12,170
373
- def test_initial_conditionstest_initial_conditions15,243
374
- def test_classifying_mock_modelstest_classifying_mock_models27,644
375
- def test_mock_models_have_different_idstest_mock_models_have_different_ids37,891
376
- def test_mock_models_can_have_quick_defstest_mock_models_can_have_quick_defs43,1042
377
- def test_mock_models_can_have_blockstest_mock_models_can_have_blocks48,1182
399
+ class DummyModelDummyModel6,61
400
+ class ChildModel < DummyModelChildModel9,83
401
+ class TestFlexModel < Test::Unit::TestCaseTestFlexModel13,189
402
+ def test_initial_conditionstest_initial_conditions16,262
403
+ def test_classifying_mock_modelstest_classifying_mock_models28,663
404
+ def test_mock_models_have_different_idstest_mock_models_have_different_ids38,910
405
+ def test_mock_models_can_have_quick_defstest_mock_models_can_have_quick_defs44,1061
406
+ def test_mock_models_can_have_blockstest_mock_models_can_have_blocks49,1201
378
407
 
379
408
  test/test_naming.rb,816
380
409
  class TestNaming < Test::Unit::TestCaseTestNaming15,352
@@ -390,7 +419,7 @@ class TestNaming < Test::Unit::TestCaseTestNaming15,352
390
419
  def test_partial_mocks_use_original_inspecttest_partial_mocks_use_original_inspect74,1722
391
420
  def test_partial_mocks_can_override_inspecttest_partial_mocks_can_override_inspect80,1886
392
421
 
393
- test/test_new_instances.rb,2299
422
+ test/test_new_instances.rb,2271
394
423
  class TestNewInstances < Test::Unit::TestCaseTestNewInstances16,382
395
424
  class DogDog20,494
396
425
  def barkbark21,506
@@ -408,87 +437,147 @@ class TestNewInstances < Test::Unit::TestCaseTestNewInstances16,382
408
437
  def test_new_gets_block_after_restubbingtest_new_gets_block_after_restubbing81,1782
409
438
  def test_new_instances_stub_verification_happens_on_teardowntest_new_instances_stub_verification_happens_on_teardown94,2107
410
439
  def test_new_instances_reports_error_on_non_classestest_new_instances_reports_error_on_non_classes104,2470
411
- def test_can_stub_objects_created_with_allocate_instead_of_newtest_can_stub_objects_created_with_allocate_instead_of_new114,2752
412
- def test_can_stub_objects_created_with_arbitrary_class_methodstest_can_stub_objects_created_with_arbitrary_class_methods122,2984
413
- def test_stubbing_arbitrary_class_methods_leaves_new_alonetest_stubbing_arbitrary_class_methods_leaves_new_alone129,3209
414
- def test_stubbing_new_and_allocate_doesnt_double_stub_objects_on_newtest_stubbing_new_and_allocate_doesnt_double_stub_objects_on_new136,3424
415
- def test_stubbing_new_and_allocate_doesnt_double_stub_objects_on_allocatetest_stubbing_new_and_allocate_doesnt_double_stub_objects_on_allocate145,3626
416
- def test_blocks_on_new_do_not_have_stubs_installedtest_blocks_on_new_do_not_have_stubs_installed158,4093
417
- def test_new_instances_accept_chained_expectationstest_new_instances_accept_chained_expectations172,4433
418
- def test_fancy_use_of_chained_should_receivedtest_fancy_use_of_chained_should_received180,4705
419
- def test_writable_accessorstest_writable_accessors185,4862
420
- def test_ordering_can_be_specifiedtest_ordering_can_be_specified191,5009
421
- def test_ordering_can_be_specified_in_groupstest_ordering_can_be_specified_in_groups199,5205
422
-
423
- test/test_partial_mock.rb,4530
440
+ def test_does_not_by_default_stub_objects_created_with_allocatetest_does_not_by_default_stub_objects_created_with_allocate114,2752
441
+ def test_can_explicitly_stub_objects_created_with_allocatetest_can_explicitly_stub_objects_created_with_allocate122,2982
442
+ def test_can_stub_objects_created_with_arbitrary_class_methodstest_can_stub_objects_created_with_arbitrary_class_methods130,3221
443
+ def test_stubbing_arbitrary_class_methods_leaves_new_alonetest_stubbing_arbitrary_class_methods_leaves_new_alone137,3446
444
+ def test_stubbing_new_and_allocate_doesnt_double_stub_objects_on_newtest_stubbing_new_and_allocate_doesnt_double_stub_objects_on_new144,3661
445
+ def test_blocks_on_new_do_not_have_stubs_installedtest_blocks_on_new_do_not_have_stubs_installed157,4116
446
+ def test_new_instances_accept_chained_expectationstest_new_instances_accept_chained_expectations171,4456
447
+ def test_fancy_use_of_chained_should_receivedtest_fancy_use_of_chained_should_received179,4728
448
+ def test_writable_accessorstest_writable_accessors184,4885
449
+ def test_ordering_can_be_specifiedtest_ordering_can_be_specified190,5032
450
+ def test_ordering_can_be_specified_in_groupstest_ordering_can_be_specified_in_groups198,5228
451
+
452
+ test/test_partial_mock.rb,4817
424
453
  class TestStubbing < Test::Unit::TestCaseTestStubbing16,372
425
454
  class DogDog19,446
426
455
  def barkbark20,458
427
456
  def Dog.createcreate23,491
428
- def test_stub_command_add_behavior_to_arbitrary_objectstest_stub_command_add_behavior_to_arbitrary_objects28,540
429
- def test_stub_command_can_configure_via_blocktest_stub_command_can_configure_via_block34,726
430
- def test_stubbed_methods_can_take_blockstest_stubbed_methods_can_take_blocks42,925
431
- def test_multiple_stubs_on_the_same_object_reuse_the_same_partial_mocktest_multiple_stubs_on_the_same_object_reuse_the_same_partial_mock49,1152
432
- def test_multiple_methods_can_be_stubbedtest_multiple_methods_can_be_stubbed54,1301
433
- def test_original_behavior_can_be_restoredtest_original_behavior_can_be_restored62,1555
434
- def test_original_missing_behavior_can_be_restoredtest_original_missing_behavior_can_be_restored72,1892
435
- def test_multiple_stubs_on_single_method_can_be_restored_missing_methodtest_multiple_stubs_on_single_method_can_be_restored_missing_method81,2171
436
- def test_original_behavior_is_restored_when_multiple_methods_are_mockedtest_original_behavior_is_restored_when_multiple_methods_are_mocked92,2582
437
- def test_original_behavior_is_restored_on_class_objectstest_original_behavior_is_restored_on_class_objects101,2911
438
- def test_original_behavior_is_restored_on_singleton_methodstest_original_behavior_is_restored_on_singleton_methods108,3162
439
- def obj.hi() :hello endhi110,3245
440
- def test_original_behavior_is_restored_on_singleton_methods_with_multiple_stubstest_original_behavior_is_restored_on_singleton_methods_with_multiple_stubs118,3441
441
- def obj.hi(n) "hello#{n}" endhi120,3544
442
- def test_original_behavior_is_restored_on_nonsingleton_methods_with_multiple_stubstest_original_behavior_is_restored_on_nonsingleton_methods_with_multiple_stubs130,3865
443
- def test_stubbing_file_shouldnt_break_writingtest_stubbing_file_shouldnt_break_writing146,4359
444
- def test_original_behavior_is_restored_even_when_errorstest_original_behavior_is_restored_even_when_errors162,4798
445
- def m.flexmock_verify() endflexmock_verify170,5117
446
- def test_not_calling_stubbed_method_is_an_errortest_not_calling_stubbed_method_is_an_error173,5156
447
- def test_mock_is_verified_when_the_stub_is_verifiedtest_mock_is_verified_when_the_stub_is_verified182,5385
448
- def test_stub_can_have_explicit_nametest_stub_can_have_explicit_name191,5655
449
- def test_unamed_stub_will_use_default_naming_conventiontest_unamed_stub_will_use_default_naming_convention197,5834
450
- def test_partials_can_be_defined_in_a_blocktest_partials_can_be_defined_in_a_block203,6030
451
- def test_partials_defining_block_return_real_obj_not_proxytest_partials_defining_block_return_real_obj_not_proxy211,6217
452
- def test_partial_mocks_always_return_domain_objecttest_partial_mocks_always_return_domain_object218,6411
453
- def test_domain_objects_do_not_have_mock_methodstest_domain_objects_do_not_have_mock_methods229,6691
454
- def test_partial_mocks_have_mock_methodstest_partial_mocks_have_mock_methods236,6883
455
- def test_partial_mocks_do_not_have_mock_methods_after_teardowntest_partial_mocks_do_not_have_mock_methods_after_teardown244,7079
456
- def test_partial_mocks_with_mock_method_singleton_colision_have_original_defs_restoredtest_partial_mocks_with_mock_method_singleton_colision_have_original_defs_restored253,7329
457
- def dog.mock() :original endmock255,7436
458
- class MockColisionMockColision261,7557
459
- def mockmock262,7578
460
- def test_partial_mocks_with_mock_method_non_singleton_colision_have_original_defs_restoredtest_partial_mocks_with_mock_method_non_singleton_colision_have_original_defs_restored267,7622
461
- def test_safe_partial_mocks_do_not_support_mock_methodstest_safe_partial_mocks_do_not_support_mock_methods274,7826
462
- def test_safe_partial_mocks_require_blocktest_safe_partial_mocks_require_block282,8054
463
- def test_safe_partial_mocks_are_actually_mockedtest_safe_partial_mocks_are_actually_mocked287,8192
464
- class LiarLiar292,8362
465
- def respond_to?(method_name)respond_to?293,8375
466
- def test_liar_actually_liestest_liar_actually_lies303,8544
467
- def test_partial_mock_where_respond_to_is_true_yet_method_is_not_theretest_partial_mock_where_respond_to_is_true_yet_method_is_not_there309,8696
468
- class ValueObjectValueObject320,9125
469
- def initialize(val)initialize323,9167
470
- def ==(other)==327,9217
471
- def test_partial_mocks_in_the_presense_of_equal_definitiontest_partial_mocks_in_the_presense_of_equal_definition332,9274
457
+ class DogPlus < DogDogPlus28,540
458
+ def should_receiveshould_receive29,562
459
+ def new_instancesnew_instances32,611
460
+ def by_defaultby_default35,656
461
+ def test_stub_command_add_behavior_to_arbitrary_objectstest_stub_command_add_behavior_to_arbitrary_objects40,712
462
+ def test_stub_command_can_configure_via_blocktest_stub_command_can_configure_via_block46,898
463
+ def test_stubbed_methods_can_take_blockstest_stubbed_methods_can_take_blocks54,1097
464
+ def test_multiple_stubs_on_the_same_object_reuse_the_same_partial_mocktest_multiple_stubs_on_the_same_object_reuse_the_same_partial_mock61,1324
465
+ def test_multiple_methods_can_be_stubbedtest_multiple_methods_can_be_stubbed66,1473
466
+ def test_original_behavior_can_be_restoredtest_original_behavior_can_be_restored74,1727
467
+ def test_original_missing_behavior_can_be_restoredtest_original_missing_behavior_can_be_restored84,2064
468
+ def test_multiple_stubs_on_single_method_can_be_restored_missing_methodtest_multiple_stubs_on_single_method_can_be_restored_missing_method93,2343
469
+ def test_original_behavior_is_restored_when_multiple_methods_are_mockedtest_original_behavior_is_restored_when_multiple_methods_are_mocked104,2754
470
+ def test_original_behavior_is_restored_on_class_objectstest_original_behavior_is_restored_on_class_objects113,3083
471
+ def test_original_behavior_is_restored_on_singleton_methodstest_original_behavior_is_restored_on_singleton_methods120,3334
472
+ def obj.hi() :hello endhi122,3417
473
+ def test_original_behavior_is_restored_on_singleton_methods_with_multiple_stubstest_original_behavior_is_restored_on_singleton_methods_with_multiple_stubs130,3613
474
+ def obj.hi(n) "hello#{n}" endhi132,3716
475
+ def test_original_behavior_is_restored_on_nonsingleton_methods_with_multiple_stubstest_original_behavior_is_restored_on_nonsingleton_methods_with_multiple_stubs142,4037
476
+ def test_stubbing_file_shouldnt_break_writingtest_stubbing_file_shouldnt_break_writing158,4531
477
+ def test_original_behavior_is_restored_even_when_errorstest_original_behavior_is_restored_even_when_errors174,4970
478
+ def m.flexmock_verify() endflexmock_verify182,5289
479
+ def test_not_calling_stubbed_method_is_an_errortest_not_calling_stubbed_method_is_an_error185,5328
480
+ def test_mock_is_verified_when_the_stub_is_verifiedtest_mock_is_verified_when_the_stub_is_verified194,5557
481
+ def test_stub_can_have_explicit_nametest_stub_can_have_explicit_name203,5827
482
+ def test_unamed_stub_will_use_default_naming_conventiontest_unamed_stub_will_use_default_naming_convention209,6006
483
+ def test_partials_can_be_defined_in_a_blocktest_partials_can_be_defined_in_a_block215,6202
484
+ def test_partials_defining_block_return_real_obj_not_proxytest_partials_defining_block_return_real_obj_not_proxy223,6389
485
+ def test_partial_mocks_always_return_domain_objecttest_partial_mocks_always_return_domain_object230,6583
486
+ def test_domain_objects_do_not_have_mock_methodstest_domain_objects_do_not_have_mock_methods241,6863
487
+ def test_partial_mocks_have_mock_methodstest_partial_mocks_have_mock_methods248,7055
488
+ def test_partial_mocks_do_not_have_mock_methods_after_teardowntest_partial_mocks_do_not_have_mock_methods_after_teardown256,7251
489
+ def test_partial_mocks_with_mock_method_singleton_colision_have_original_defs_restoredtest_partial_mocks_with_mock_method_singleton_colision_have_original_defs_restored265,7501
490
+ def dog.mock() :original endmock267,7608
491
+ class MockColisionMockColision273,7729
492
+ def mockmock274,7750
493
+ def test_partial_mocks_with_mock_method_non_singleton_colision_have_original_defs_restoredtest_partial_mocks_with_mock_method_non_singleton_colision_have_original_defs_restored279,7794
494
+ def test_safe_partial_mocks_do_not_support_mock_methodstest_safe_partial_mocks_do_not_support_mock_methods286,7998
495
+ def test_safe_partial_mocks_require_blocktest_safe_partial_mocks_require_block294,8226
496
+ def test_safe_partial_mocks_are_actually_mockedtest_safe_partial_mocks_are_actually_mocked299,8364
497
+ def test_should_receive_does_not_override_preexisting_deftest_should_receive_does_not_override_preexisting_def304,8534
498
+ class LiarLiar311,8787
499
+ def respond_to?(method_name)respond_to?312,8800
500
+ def test_liar_actually_liestest_liar_actually_lies322,8969
501
+ def test_partial_mock_where_respond_to_is_true_yet_method_is_not_theretest_partial_mock_where_respond_to_is_true_yet_method_is_not_there328,9121
502
+ class ValueObjectValueObject339,9550
503
+ def initialize(val)initialize342,9592
504
+ def ==(other)==346,9642
505
+ def test_partial_mocks_in_the_presense_of_equal_definitiontest_partial_mocks_in_the_presense_of_equal_definition351,9699
506
+
507
+ test/test_rails_view_stub.rb,931
508
+ module ViewTestsViewTests6,80
509
+ def test_view_mocks_as_stubtest_view_mocks_as_stub7,97
510
+ def test_fails_if_no_rendertest_fails_if_no_render12,191
511
+ def test_view_mocks_with_expectationtest_view_mocks_with_expectation19,335
512
+ def test_view_mocks_with_expectation_fails_with_different_templatetest_view_mocks_with_expectation_fails_with_different_template24,439
513
+ def test_view_mocks_with_expectation_wand_multiple_templatestest_view_mocks_with_expectation_wand_multiple_templates32,658
514
+ def pretend_to_be_rails_version(version)pretend_to_be_rails_version39,835
515
+ class TestRailsViewStubForVersionsUpTo_1_2_4 < Test::Unit::TestCaseTestRailsViewStubForVersionsUpTo_1_2_445,1030
516
+ def setupsetup49,1148
517
+ def render(*names)render56,1377
518
+ class TestRailsViewStubForVersionsAfter_1_2_4 < Test::Unit::TestCaseTestRailsViewStubForVersionsAfter_1_2_470,1655
519
+ def setupsetup74,1774
520
+ def render(*names)render82,2047
472
521
 
473
522
  test/test_record_mode.rb,1339
474
523
  class TestRecordMode < Test::Unit::TestCaseTestRecordMode16,390
475
524
  def test_recording_mode_workstest_recording_mode_works20,505
476
525
  def test_arguments_are_passed_to_recording_mode_blocktest_arguments_are_passed_to_recording_mode_block28,687
477
526
  def test_recording_mode_handles_multiple_returnstest_recording_mode_handles_multiple_returns39,962
478
- def test_recording_mode_does_not_specify_ordertest_recording_mode_does_not_specify_order50,1229
479
- def test_recording_mode_gets_block_args_tootest_recording_mode_gets_block_args_too61,1475
480
- def test_recording_mode_should_validate_args_with_equalstest_recording_mode_should_validate_args_with_equals73,1757
481
- def test_recording_mode_should_allow_arg_contraint_validationtest_recording_mode_should_allow_arg_contraint_validation84,1992
482
- def test_recording_mode_should_handle_multiplicity_contraintstest_recording_mode_should_handle_multiplicity_contraints95,2233
483
- def test_strict_record_mode_requires_exact_argument_matchestest_strict_record_mode_requires_exact_argument_matches107,2500
484
- def test_strict_record_mode_requires_exact_orderingtest_strict_record_mode_requires_exact_ordering119,2780
485
- def test_strict_record_mode_requires_oncetest_strict_record_mode_requires_once133,3085
486
- def test_strict_record_mode_can_not_failtest_strict_record_mode_can_not_fail146,3360
487
-
488
- test/test_samples.rb,142
527
+ def test_recording_mode_does_not_specify_ordertest_recording_mode_does_not_specify_order53,1386
528
+ def test_recording_mode_gets_block_args_tootest_recording_mode_gets_block_args_too64,1632
529
+ def test_recording_mode_should_validate_args_with_equalstest_recording_mode_should_validate_args_with_equals76,1914
530
+ def test_recording_mode_should_allow_arg_contraint_validationtest_recording_mode_should_allow_arg_contraint_validation87,2149
531
+ def test_recording_mode_should_handle_multiplicity_contraintstest_recording_mode_should_handle_multiplicity_contraints98,2390
532
+ def test_strict_record_mode_requires_exact_argument_matchestest_strict_record_mode_requires_exact_argument_matches110,2657
533
+ def test_strict_record_mode_requires_exact_orderingtest_strict_record_mode_requires_exact_ordering122,2937
534
+ def test_strict_record_mode_requires_oncetest_strict_record_mode_requires_once136,3242
535
+ def test_strict_record_mode_can_not_failtest_strict_record_mode_can_not_fail149,3517
536
+
537
+ test/test_samples.rb,2164
489
538
  class TestSamples < Test::Unit::TestCaseTestSamples17,378
490
539
  def test_file_iotest_file_io25,748
491
540
  def count_lines(file)count_lines33,999
541
+ class TestUndefined < Test::Unit::TestCaseTestUndefined43,1092
542
+ def test_undefined_valuestest_undefined_values46,1165
543
+ class TestSimple < Test::Unit::TestCaseTestSimple55,1351
544
+ def test_simple_mocktest_simple_mock58,1421
545
+ class TestDog < Test::Unit::TestCaseTestDog65,1556
546
+ def test_dog_wagstest_dog_wags68,1625
547
+ class WooferWoofer74,1736
548
+ class DogDog77,1754
549
+ def initializeinitialize78,1764
550
+ def barkbark81,1812
551
+ def wagwag84,1846
552
+ class TestDogBarking < Test::Unit::TestCaseTestDogBarking89,1878
553
+ def setupsetup94,2043
554
+ def test_dogtest_dog99,2118
555
+ class TestDogBarkingWithNewInstances < Test::Unit::TestCaseTestDogBarkingWithNewInstances105,2249
556
+ def setupsetup110,2415
557
+ def test_dogtest_dog114,2502
558
+ class TestDefaults < Test::Unit::TestCaseTestDefaults120,2636
559
+ def setupsetup123,2708
560
+ def test_something_where_bark_must_be_called_oncetest_something_where_bark_must_be_called_once128,2837
561
+ class TestDemeter < Test::Unit::TestCaseTestDemeter136,3040
562
+ def test_manual_mockingtest_manual_mocking138,3110
563
+ def test_demetertest_demeter151,3544
564
+ class TestDb < Test::Unit::TestCaseTestDb161,3759
565
+ def test_dbtest_db164,3825
566
+ class TestDb < Test::Unit::TestCaseTestDb175,4030
567
+ def test_query_and_updatetest_query_and_update178,4096
568
+ def test_ordered_queriestest_ordered_queries189,4383
569
+ def test_ordered_queries_in_record_modetest_ordered_queries_in_record_mode207,4923
570
+ def known_good_way_to_build_xml(builder)known_good_way_to_build_xml224,5400
571
+ def new_way_to_build_xml(builder)new_way_to_build_xml228,5467
572
+ def test_build_xmltest_build_xml232,5551
573
+ class TestMoreSamples < Test::Unit::TestCaseTestMoreSamples243,5813
574
+ def test_multiple_getstest_multiple_gets246,5888
575
+ def test_an_important_messagetest_an_important_message255,6133
576
+ class QuoteServiceQuoteService264,6394
577
+ class PortfolioPortfolio267,6422
578
+ def initializeinitialize268,6440
579
+ def valuevalue271,6507
580
+ def test_portfolio_valuetest_portfolio_value276,6563
492
581
 
493
582
  test/test_should_ignore_missing.rb,1173
494
583
  class TestShouldIgnoreMissing < Test::Unit::TestCaseTestShouldIgnoreMissing16,375
@@ -504,7 +593,7 @@ class TestShouldIgnoreMissing < Test::Unit::TestCaseTestShouldIgnoreMissing16,
504
593
  def test_not_calling_method_proc_will_fail_count_constraintstest_not_calling_method_proc_will_fail_count_constraints66,1693
505
594
  def test_method_returns_do_nothing_proc_for_missing_methodstest_method_returns_do_nothing_proc_for_missing_methods75,1965
506
595
 
507
- test/test_should_receive.rb,10143
596
+ test/test_should_receive.rb,10493
508
597
  def mock_top_level_functionmock_top_level_function16,375
509
598
  module KernelKernel20,416
510
599
  def mock_kernel_functionmock_kernel_function21,430
@@ -604,15 +693,18 @@ class TestFlexMockShoulds < Test::Unit::TestCaseTestFlexMockShoulds26,477
604
693
  def test_default_expectations_are_overridden_by_later_expectationstest_default_expectations_are_overridden_by_later_expectations910,23315
605
694
  def test_ordered_default_expectations_can_be_specifiedtest_ordered_default_expectations_can_be_specified918,23543
606
695
  def test_ordered_default_expectations_can_be_overriddentest_ordered_default_expectations_can_be_overridden926,23794
607
- def test_partial_mocks_can_have_default_expectationstest_partial_mocks_can_have_default_expectations938,24065
608
- def test_partial_mocks_can_have_default_expectations_overriddentest_partial_mocks_can_have_default_expectations_overridden944,24246
609
- def test_wicked_and_evil_tricks_with_by_default_are_thwartedtest_wicked_and_evil_tricks_with_by_default_are_thwarted951,24494
610
- def test_can_mock_operatorstest_can_mock_operators962,24842
611
- def assert_operator(op, &block)assert_operator991,25857
612
- class TestFlexMockShouldsWithInclude < Test::Unit::TestCaseTestFlexMockShouldsWithInclude999,26011
613
- def test_include_enables_unqualified_arg_type_referencestest_include_enables_unqualified_arg_type_references1001,26105
614
- class TestFlexMockArgTypesDontLeak < Test::Unit::TestCaseTestFlexMockArgTypesDontLeak1009,26269
615
- def test_unqualified_arg_type_references_are_undefined_by_defaulttest_unqualified_arg_type_references_are_undefined_by_default1010,26327
696
+ def test_by_default_works_at_mock_leveltest_by_default_works_at_mock_level938,24065
697
+ def test_by_default_at_mock_level_does_nothing_with_no_expectationstest_by_default_at_mock_level_does_nothing_with_no_expectations949,24340
698
+ def test_partial_mocks_can_have_default_expectationstest_partial_mocks_can_have_default_expectations955,24485
699
+ def test_partial_mocks_can_have_default_expectations_overriddentest_partial_mocks_can_have_default_expectations_overridden961,24666
700
+ def test_wicked_and_evil_tricks_with_by_default_are_thwartedtest_wicked_and_evil_tricks_with_by_default_are_thwarted968,24914
701
+ def test_mocks_can_handle_multi_parameter_respond_tostest_mocks_can_handle_multi_parameter_respond_tos980,25319
702
+ def test_can_mock_operatorstest_can_mock_operators991,25666
703
+ def assert_operator(op, &block)assert_operator1020,26681
704
+ class TestFlexMockShouldsWithInclude < Test::Unit::TestCaseTestFlexMockShouldsWithInclude1028,26835
705
+ def test_include_enables_unqualified_arg_type_referencestest_include_enables_unqualified_arg_type_references1030,26929
706
+ class TestFlexMockArgTypesDontLeak < Test::Unit::TestCaseTestFlexMockArgTypesDontLeak1038,27093
707
+ def test_unqualified_arg_type_references_are_undefined_by_defaulttest_unqualified_arg_type_references_are_undefined_by_default1039,27151
616
708
 
617
709
  test/test_tu_integration.rb,1570
618
710
  class TestTuIntegrationFlexMockMethod < Test::Unit::TestCaseTestTuIntegrationFlexMockMethod15,352
@@ -649,8 +741,6 @@ class UndefinedTest < Test::Unit::TestCaseUndefinedTest15,352
649
741
  def assert_undefined(obj)assert_undefined81,2012
650
742
  def undefinedundefined85,2075
651
743
 
652
- test/rspec_integration/integration_spec.rb,0
653
-
654
744
  test/test_unit_integration/test_auto_test_unit.rb,263
655
745
  class TestFlexmockTestUnit < Test::Unit::TestCaseTestFlexmockTestUnit17,387
656
746
  def teardownteardown18,437
@@ -1,10 +1,10 @@
1
- = FlexMock 0.7.1 Released
1
+ = FlexMock 0.8.0 Released
2
2
 
3
3
  FlexMock is a flexible mocking library for use in unit testing and
4
4
  behavior specification in Ruby. It is a minor release that contains
5
5
  some new funtionality.
6
6
 
7
- == New Features n 0.8.0
7
+ == New Features in 0.8.0
8
8
 
9
9
  * When should_ignore_missing is specified, the mock will return an
10
10
  undefined object for any method calls that are ignored.
@@ -69,7 +69,7 @@ class FlexMock
69
69
  def return_value(args)
70
70
  case @return_queue.size
71
71
  when 0
72
- block = lambda { @return_value }
72
+ block = lambda { |*args| @return_value }
73
73
  when 1
74
74
  block = @return_queue.first
75
75
  else
@@ -85,7 +85,7 @@ class FlexMock
85
85
  unless @yield_queue.empty?
86
86
  block = args.last
87
87
  values = (@yield_queue.size == 1) ? @yield_queue.first : @yield_queue.shift
88
- if block.respond_to?(:call)
88
+ if block && block.respond_to?(:call)
89
89
  @return_value = block.call(*values)
90
90
  else
91
91
  fail MockError, "No Block given to mock with 'and_yield' expectation"
@@ -190,7 +190,7 @@ class FlexMock
190
190
  @return_queue << block
191
191
  else
192
192
  args.each do |arg|
193
- @return_queue << lambda { arg }
193
+ @return_queue << lambda { |*a| arg }
194
194
  end
195
195
  end
196
196
  self
@@ -213,6 +213,9 @@ class FlexMock
213
213
  :new_record? => false,
214
214
  :class => model_class,
215
215
  :errors => container.flexmock("errors", :count => 0))
216
+ # HACK: Ruby 1.9 needs the following lambda so that model_class
217
+ # is correctly bound below.
218
+ lambda { }
216
219
  mock.should_receive(:is_a?).with(any).and_return { |other|
217
220
  other == model_class
218
221
  }
@@ -104,22 +104,27 @@ class FlexMock
104
104
  # new_instances is a short cut method for overriding the behavior of any
105
105
  # new instances created via a mocked class object.
106
106
  #
107
- # By default, new_instances will mock the behaviour of the :new and
108
- # :allocate methods. If you wish to mock a different set of class
109
- # methods, just pass a list of symbols to as arguments.
107
+ # By default, new_instances will mock the behaviour of the :new
108
+ # method. If you wish to mock a different set of class methods,
109
+ # just pass a list of symbols to as arguments. (previous versions
110
+ # also mocked :allocate by default. If you need :allocate to be
111
+ # mocked, just request it explicitly).
110
112
  #
111
- # For example, to stub only objects created by :make (and not :new
112
- # or :allocate), use:
113
+ # For example, to stub only objects created by :make (and not
114
+ # :new), use:
113
115
  #
114
116
  # flexmock(ClassName).new_instances(:make).should_receive(...)
115
117
  #
116
118
  def new_instances(*allocators, &block)
117
119
  fail ArgumentError, "new_instances requires a Class to stub" unless Class === @obj
118
- allocators = [:new, :allocate] if allocators.empty?
120
+ allocators = [:new] if allocators.empty?
119
121
  result = ExpectationRecorder.new
120
- allocators.each do |m|
121
- self.should_receive(m).and_return { |*args|
122
- new_obj = invoke_original(m, args)
122
+ allocators.each do |allocate_method|
123
+ # HACK: Without the following lambda, Ruby 1.9 will not bind
124
+ # the allocate_method parameter correctly.
125
+ lambda { }
126
+ self.should_receive(allocate_method).and_return { |*args|
127
+ new_obj = invoke_original(allocate_method, args)
123
128
  mock = flexmock_container.flexmock(new_obj)
124
129
  block.call(mock) if block_given?
125
130
  result.apply(mock)
@@ -3,18 +3,45 @@ require 'flexmock'
3
3
  class FlexMock
4
4
  module MockContainer
5
5
 
6
+ def rails_version
7
+ Rails::VERSION::STRING
8
+ end
9
+
6
10
  # Declare that the Rails controller under test should render the
7
11
  # named view. If a view template name is given, it will be an
8
12
  # error if the named view is not rendered during the execution of
9
13
  # the contoller action. If no template name is given, then the
10
14
  # any view may be rendered. If no view is actually rendered, then
11
- # a assertion failure will occur.
15
+ # an assertion failure will occur.
16
+ #
17
+ # def test_my_action_does_what_it_should
18
+ # should_render_view 'show'
19
+ #
20
+ # get :show, :id => 1
21
+ #
22
+ # assert_response :success
23
+ # end
24
+ #
12
25
  def should_render_view(template_name=nil)
26
+ if rails_version <= '1.2.4'
27
+ should_render_view_prior_version_124(template_name)
28
+ elsif rails_version <= '2.0.0'
29
+ should_render_view_after_version_124(template_name)
30
+ else
31
+ should_render_view_after_version_202(template_name)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ # This version of should_render_view will work for Rails 1.2.4
38
+ # (and prehaps some number of prior versions).
39
+ def should_render_view_prior_version_124(template_name) # :nodoc:
13
40
  view = flexmock("MockView")
14
- view.should_receive(
15
- :assigns => {},
16
- :render_file => true,
17
- :first_render => "dummy_template"
41
+ view.should_receive(
42
+ :assigns => {},
43
+ :render_file => true,
44
+ :first_render => "dummy_template"
18
45
  )
19
46
  if template_name
20
47
  view.should_receive(:file_exists?).with(/#{template_name}$/).once.
@@ -26,5 +53,49 @@ class FlexMock
26
53
  flexmock(@controller.class).should_receive(:view_class).once.
27
54
  and_return(view_class)
28
55
  end
56
+
57
+ # This version of should_render_view will work with versions of
58
+ # Rails after Version 1.2.4.
59
+ def should_render_view_after_version_124(template_name)
60
+ view = flexmock("MockView")
61
+ view.should_receive(
62
+ :assigns => {},
63
+ :render_file => true,
64
+ :template_format => :dummy_format,
65
+ :view_paths => :dummy_view_paths,
66
+ :pick_template_extension => :dummy_extension
67
+ )
68
+ if template_name
69
+ view.should_receive(:file_exists?).with(/#{template_name}$/).once.
70
+ and_return(true)
71
+ end
72
+ view.should_receive(:file_exists?).with(any).and_return(true)
73
+
74
+ # The number of times this is called changes from version 1.2.6
75
+ # to 2.0. The important thing is that it is checked at least once.
76
+ flexmock(@response).should_receive(:template).and_return(view).
77
+ at_least.once
78
+ end
79
+
80
+ # This version of should_render_view will work with versions of
81
+ # Rails at Version 2.0.2 and after
82
+ def should_render_view_after_version_202(template_name)
83
+ viewmock = flexmock("ViewMock")
84
+ viewmock.should_receive(
85
+ :assigns => {},
86
+ :pick_template_extension => ".html",
87
+ :template_format =>nil,
88
+ :view_paths => nil,
89
+ :file_exists? => true,
90
+ :first_render => "")
91
+ if template_name
92
+ viewmock.should_receive(:render_file).with(/\/#{template_name}$/, any, any).
93
+ and_return(nil).once
94
+ else
95
+ viewmock.should_receive(:render_file).and_return(nil)
96
+ end
97
+ flexmock(ActionView::Base).should_receive(:new).and_return(viewmock)
98
+ end
99
+
29
100
  end
30
101
  end
@@ -52,7 +52,7 @@ class TestFlexMock < Test::Unit::TestCase
52
52
  end
53
53
 
54
54
  def test_handle_missing_method
55
- expected_error = (VERSION >= "1.8.0") ? NoMethodError : NameError
55
+ expected_error = (RUBY_VERSION >= "1.8.0") ? NoMethodError : NameError
56
56
  ex = assert_raises(expected_error) {
57
57
  @mock.not_defined
58
58
  }
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'test/unit'
4
+ require 'flexmock'
4
5
 
5
6
  class DummyModel
6
7
  end
@@ -111,11 +111,19 @@ class TestNewInstances < Test::Unit::TestCase
111
111
  assert_match(/new_instances/, ex.message)
112
112
  end
113
113
 
114
- def test_can_stub_objects_created_with_allocate_instead_of_new
114
+ def test_does_not_by_default_stub_objects_created_with_allocate
115
115
  flexstub(Dog).new_instances do |obj|
116
116
  obj.should_receive(:bark).and_return(:whimper)
117
117
  end
118
118
  m = Dog.allocate
119
+ assert_equal :woof, m.bark
120
+ end
121
+
122
+ def test_can_explicitly_stub_objects_created_with_allocate
123
+ flexstub(Dog).new_instances(:allocate) do |obj|
124
+ obj.should_receive(:bark).and_return(:whimper)
125
+ end
126
+ m = Dog.allocate
119
127
  assert_equal :whimper, m.bark
120
128
  end
121
129
 
@@ -142,15 +150,6 @@ class TestNewInstances < Test::Unit::TestCase
142
150
  assert_equal 1, counter
143
151
  end
144
152
 
145
- def test_stubbing_new_and_allocate_doesnt_double_stub_objects_on_allocate
146
- counter = 0
147
- flexstub(Dog).new_instances do |obj|
148
- counter += 1
149
- end
150
- Dog.allocate
151
- assert_equal 1, counter
152
- end
153
-
154
153
  # Current behavior does not install stubs into the block passed to new.
155
154
  # This is rather difficult to achieve, although it would be nice. For the
156
155
  # moment, we assure that they are not stubbed, but I am willing to change
@@ -3,15 +3,7 @@
3
3
  require 'test/unit'
4
4
  require 'flexmock/rails/view_mocking'
5
5
 
6
- ######################################################################
7
- class TestRailsViewStub < Test::Unit::TestCase
8
- include FlexMock::TestCase
9
-
10
- def setup
11
- @controller_class = flexmock("controller class")
12
- @controller = flexmock("controller", :class => @controller_class)
13
- end
14
-
6
+ module ViewTests
15
7
  def test_view_mocks_as_stub
16
8
  should_render_view
17
9
  render "controller/new.rthml"
@@ -44,6 +36,23 @@ class TestRailsViewStub < Test::Unit::TestCase
44
36
 
45
37
  private
46
38
 
39
+ def pretend_to_be_rails_version(version)
40
+ flexmock(self).should_receive(:rails_version).and_return(version)
41
+ end
42
+ end
43
+
44
+ ######################################################################
45
+ class TestRailsViewStubForVersionsUpTo_1_2_4 < Test::Unit::TestCase
46
+ include FlexMock::TestCase
47
+ include ViewTests
48
+
49
+ def setup
50
+ @controller_class = flexmock("controller class")
51
+ @controller = flexmock("controller", :class => @controller_class)
52
+ pretend_to_be_rails_version("1.2.4")
53
+ end
54
+
55
+ # Simulate Rails rendering in version 1.2.4
47
56
  def render(*names)
48
57
  vc = @controller.class.view_class
49
58
  v = vc.new
@@ -54,4 +63,32 @@ class TestRailsViewStub < Test::Unit::TestCase
54
63
  v.file_exists?(name)
55
64
  end
56
65
  end
66
+
67
+ end
68
+
69
+ ######################################################################
70
+ class TestRailsViewStubForVersionsAfter_1_2_4 < Test::Unit::TestCase
71
+ include FlexMock::TestCase
72
+ include ViewTests
73
+
74
+ def setup
75
+ @controller_class = flexmock("controller class")
76
+ @controller = flexmock("controller", :class => @controller_class)
77
+ @response = flexmock("Response")
78
+ pretend_to_be_rails_version("2.0")
79
+ end
80
+
81
+ # Simulate Rails rendering after Rails version 1.2.4
82
+ def render(*names)
83
+ v = @response.template
84
+ v.assigns(:x => :y)
85
+ v.render_file
86
+ v.template_format
87
+ v.view_paths
88
+ v.pick_template_extension
89
+ names.each do |name|
90
+ v.file_exists?(name)
91
+ end
92
+ end
93
+
57
94
  end
@@ -40,6 +40,9 @@ class TestRecordMode < Test::Unit::TestCase
40
40
  FlexMock.use("mock") do |mock|
41
41
  mock.should_expect do |r|
42
42
  answers = [1, 2]
43
+ # HACK: The following lambda is needed in Ruby 1.9 to cause
44
+ # the answers to be properly bound in the following block.
45
+ lambda { }
43
46
  r.f { answers.shift }
44
47
  end
45
48
  assert_equal 1, mock.f
metadata CHANGED
@@ -1,39 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: flexmock
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.8.0
7
- date: 2007-11-08 00:00:00 -05:00
8
- summary: Simple and Flexible Mock Objects for Testing
9
- require_paths:
10
- - lib
11
- email: jim@weirichhouse.org
12
- homepage: http://onestepback.org/software/flexmock
13
- rubyforge_project:
14
- description: FlexMock is a extremely simple mock object class compatible with the Test::Unit framework. Although the FlexMock's interface is simple, it is very flexible.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.8.1
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Jim Weirich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-21 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: FlexMock is a extremely simple mock object class compatible with the Test::Unit framework. Although the FlexMock's interface is simple, it is very flexible.
17
+ email: jim@weirichhouse.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - CHANGES
25
+ - doc/GoogleExample.rdoc
26
+ - doc/releases/flexmock-0.4.0.rdoc
27
+ - doc/releases/flexmock-0.4.1.rdoc
28
+ - doc/releases/flexmock-0.4.2.rdoc
29
+ - doc/releases/flexmock-0.4.3.rdoc
30
+ - doc/releases/flexmock-0.5.0.rdoc
31
+ - doc/releases/flexmock-0.5.1.rdoc
32
+ - doc/releases/flexmock-0.6.0.rdoc
33
+ - doc/releases/flexmock-0.6.1.rdoc
34
+ - doc/releases/flexmock-0.6.2.rdoc
35
+ - doc/releases/flexmock-0.6.3.rdoc
36
+ - doc/releases/flexmock-0.6.4.rdoc
37
+ - doc/releases/flexmock-0.7.0.rdoc
38
+ - doc/releases/flexmock-0.7.1.rdoc
39
+ - doc/releases/flexmock-0.8.0.rdoc
31
40
  files:
32
41
  - CHANGES
33
42
  - Rakefile
34
43
  - README
35
44
  - TAGS
36
- - lib/flexmock.rb
37
45
  - lib/flexmock/argument_matchers.rb
38
46
  - lib/flexmock/argument_types.rb
39
47
  - lib/flexmock/base.rb
@@ -49,6 +57,7 @@ files:
49
57
  - lib/flexmock/noop.rb
50
58
  - lib/flexmock/ordering.rb
51
59
  - lib/flexmock/partial_mock.rb
60
+ - lib/flexmock/rails/view_mocking.rb
52
61
  - lib/flexmock/rails.rb
53
62
  - lib/flexmock/recorder.rb
54
63
  - lib/flexmock/rspec.rb
@@ -56,9 +65,10 @@ files:
56
65
  - lib/flexmock/test_unit_integration.rb
57
66
  - lib/flexmock/undefined.rb
58
67
  - lib/flexmock/validators.rb
59
- - lib/flexmock/rails/view_mocking.rb
68
+ - lib/flexmock.rb
60
69
  - test/asserts.rb
61
70
  - test/redirect_error.rb
71
+ - test/rspec_integration/integration_spec.rb
62
72
  - test/test_aliasing.rb
63
73
  - test/test_container_methods.rb
64
74
  - test/test_default_framework_adapter.rb
@@ -77,7 +87,6 @@ files:
77
87
  - test/test_should_receive.rb
78
88
  - test/test_tu_integration.rb
79
89
  - test/test_undefined.rb
80
- - test/rspec_integration/integration_spec.rb
81
90
  - test/test_unit_integration/test_auto_test_unit.rb
82
91
  - flexmock.blurb
83
92
  - install.rb
@@ -96,37 +105,35 @@ files:
96
105
  - doc/releases/flexmock-0.7.0.rdoc
97
106
  - doc/releases/flexmock-0.7.1.rdoc
98
107
  - doc/releases/flexmock-0.8.0.rdoc
99
- test_files: []
100
-
108
+ has_rdoc: true
109
+ homepage: http://onestepback.org/software/flexmock
110
+ post_install_message:
101
111
  rdoc_options:
102
112
  - --title
103
113
  - Flex Mock
104
114
  - --main
105
115
  - README
106
116
  - --line-numbers
107
- extra_rdoc_files:
108
- - README
109
- - CHANGES
110
- - doc/GoogleExample.rdoc
111
- - doc/releases/flexmock-0.4.0.rdoc
112
- - doc/releases/flexmock-0.4.1.rdoc
113
- - doc/releases/flexmock-0.4.2.rdoc
114
- - doc/releases/flexmock-0.4.3.rdoc
115
- - doc/releases/flexmock-0.5.0.rdoc
116
- - doc/releases/flexmock-0.5.1.rdoc
117
- - doc/releases/flexmock-0.6.0.rdoc
118
- - doc/releases/flexmock-0.6.1.rdoc
119
- - doc/releases/flexmock-0.6.2.rdoc
120
- - doc/releases/flexmock-0.6.3.rdoc
121
- - doc/releases/flexmock-0.6.4.rdoc
122
- - doc/releases/flexmock-0.7.0.rdoc
123
- - doc/releases/flexmock-0.7.1.rdoc
124
- - doc/releases/flexmock-0.8.0.rdoc
125
- executables: []
126
-
127
- extensions: []
128
-
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: "0"
124
+ version:
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: "0"
130
+ version:
129
131
  requirements: []
130
132
 
131
- dependencies: []
133
+ rubyforge_project:
134
+ rubygems_version: 1.0.1
135
+ signing_key:
136
+ specification_version: 2
137
+ summary: Simple and Flexible Mock Objects for Testing
138
+ test_files: []
132
139