flexmock 0.8.11 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/README.rdoc +2 -2
  2. data/Rakefile +23 -65
  3. data/TAGS +689 -691
  4. data/doc/releases/flexmock-0.9.0.rdoc +89 -0
  5. data/lib/flexmock.rb +1 -1
  6. data/lib/flexmock/argument_matchers.rb +5 -5
  7. data/lib/flexmock/argument_types.rb +1 -1
  8. data/lib/flexmock/base.rb +1 -1
  9. data/lib/flexmock/core.rb +5 -5
  10. data/lib/flexmock/core_class_methods.rb +6 -6
  11. data/lib/flexmock/default_framework_adapter.rb +2 -2
  12. data/lib/flexmock/deprecated_methods.rb +1 -1
  13. data/lib/flexmock/errors.rb +1 -1
  14. data/lib/flexmock/expectation.rb +12 -12
  15. data/lib/flexmock/expectation_director.rb +1 -1
  16. data/lib/flexmock/mock_container.rb +12 -2
  17. data/lib/flexmock/noop.rb +2 -2
  18. data/lib/flexmock/ordering.rb +1 -1
  19. data/lib/flexmock/partial_mock.rb +10 -3
  20. data/lib/flexmock/rails.rb +1 -1
  21. data/lib/flexmock/recorder.rb +1 -1
  22. data/lib/flexmock/rspec.rb +1 -1
  23. data/lib/flexmock/test_unit.rb +2 -2
  24. data/lib/flexmock/test_unit_integration.rb +5 -5
  25. data/lib/flexmock/undefined.rb +8 -4
  26. data/lib/flexmock/validators.rb +2 -2
  27. data/lib/flexmock/version.rb +11 -0
  28. data/test/{test_aliasing.rb → aliasing_test.rb} +7 -8
  29. data/test/{test_container_methods.rb → container_methods_test.rb} +21 -22
  30. data/test/{test_default_framework_adapter.rb → default_framework_adapter_test.rb} +8 -9
  31. data/test/{test_demeter_mocking.rb → demeter_mocking_test.rb} +1 -4
  32. data/test/{test_deprecated_methods.rb → deprecated_methods_test.rb} +11 -13
  33. data/test/{test_examples_from_readme.rb → examples_from_readme_test.rb} +5 -6
  34. data/test/{test_extended_should_receive.rb → extended_should_receive_test.rb} +11 -12
  35. data/test/{test_flexmodel.rb → flexmodel_test.rb} +1 -2
  36. data/test/{test_naming.rb → naming_test.rb} +5 -6
  37. data/test/{test_new_instances.rb → new_instances_test.rb} +36 -28
  38. data/test/{test_partial_mock.rb → partial_mock_test.rb} +20 -18
  39. data/test/{test_rails_view_stub.rb → rails_view_stub_test.rb} +3 -3
  40. data/test/{test_record_mode.rb → record_mode_test.rb} +2 -5
  41. data/test/rspec_integration/integration_spec.rb +14 -8
  42. data/test/{test_samples.rb → samples_test.rb} +13 -14
  43. data/test/{test_should_ignore_missing.rb → should_ignore_missing_test.rb} +4 -6
  44. data/test/{test_should_receive.rb → should_receive_test.rb} +39 -42
  45. data/test/test_setup.rb +30 -0
  46. data/test/test_unit_integration/{test_auto_test_unit.rb → auto_test_unit_test.rb} +4 -4
  47. data/test/tu_integration_test.rb +99 -0
  48. data/test/{test_undefined.rb → undefined_test.rb} +2 -3
  49. metadata +31 -39
  50. data/test/asserts.rb +0 -34
  51. data/test/test_tu_integration.rb +0 -94
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  #---
4
- # Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
4
+ # Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
5
5
  # All rights reserved.
6
6
 
7
7
  # Permission is granted for use, copying, modification, distribution,
@@ -9,8 +9,7 @@
9
9
  # above copyright notice is included.
10
10
  #+++
11
11
 
12
- require 'test/unit'
13
- require 'flexmock'
12
+ require 'test/test_setup'
14
13
 
15
14
  class TemperatureSampler
16
15
  def initialize(sensor)
@@ -49,7 +48,7 @@ class TestExamplesFromReadme < Test::Unit::TestCase
49
48
  m.should_receive(:foo).and_return_undefined
50
49
  m.foo.bar.baz
51
50
  end
52
-
51
+
53
52
  def test_db
54
53
  db = flexmock('db')
55
54
  db.should_receive(:query).and_return([1,2,3])
@@ -85,7 +84,7 @@ class TestExamplesFromReadme < Test::Unit::TestCase
85
84
  assert_equal 12.3, db.query("GOOG")
86
85
  db.finish
87
86
  end
88
-
87
+
89
88
  def test_ordered_queries_in_record_mode
90
89
  db = flexmock('db')
91
90
  db.should_expect do |rec|
@@ -146,7 +145,7 @@ class TestExamplesFromReadme < Test::Unit::TestCase
146
145
  QuoteService.new.quote
147
146
  end
148
147
  end
149
-
148
+
150
149
  def test_portfolio_value
151
150
  flexmock(QuoteService).new_instances do |m|
152
151
  m.should_receive(:quote).and_return(100)
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  #---
4
- # Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
4
+ # Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
5
5
  # All rights reserved.
6
6
 
7
7
  # Permission is granted for use, copying, modification, distribution,
@@ -9,8 +9,7 @@
9
9
  # above copyright notice is included.
10
10
  #+++
11
11
 
12
- require "test/unit"
13
- require "flexmock"
12
+ require "test/test_setup"
14
13
 
15
14
  module ExtendedShouldReceiveTests
16
15
  def test_accepts_expectation_hash
@@ -18,27 +17,27 @@ module ExtendedShouldReceiveTests
18
17
  assert_equal :bar, @obj.foo
19
18
  assert_equal :froz, @obj.baz
20
19
  end
21
-
20
+
22
21
  def test_accepts_list_of_methods
23
22
  @mock.should_receive(:foo, :bar, "baz")
24
23
  assert_nil @obj.foo
25
24
  assert_nil @obj.bar
26
25
  assert_nil @obj.baz
27
26
  end
28
-
27
+
29
28
  def test_contraints_apply_to_all_expectations
30
29
  @mock.should_receive(:foo, :bar => :baz).with(1)
31
- ex = assert_raise(Test::Unit::AssertionFailedError) { @obj.foo(2) }
32
- ex = assert_raise(Test::Unit::AssertionFailedError) { @obj.bar(2) }
30
+ ex = assert_raise(assertion_failed_error) { @obj.foo(2) }
31
+ ex = assert_raise(assertion_failed_error) { @obj.bar(2) }
33
32
  assert_equal :baz, @obj.bar(1)
34
33
  end
35
-
34
+
36
35
  def test_count_contraints_apply_to_all_expectations
37
36
  @mock.should_receive(:foo, :bar => :baz).once
38
37
  @obj.foo
39
- assert_raise(Test::Unit::AssertionFailedError) { @mock.flexmock_verify }
38
+ assert_raise(assertion_failed_error) { @mock.flexmock_verify }
40
39
  end
41
-
40
+
42
41
  def test_multiple_should_receives_are_allowed
43
42
  @mock.should_receive(:hi).and_return(:bye).
44
43
  should_receive(:hello => :goodbye)
@@ -50,7 +49,7 @@ end
50
49
  class TestExtendedShouldReceiveOnFullMocks < Test::Unit::TestCase
51
50
  include FlexMock::TestCase
52
51
  include ExtendedShouldReceiveTests
53
-
52
+
54
53
  def setup
55
54
  @mock = flexmock("mock")
56
55
  @obj = @mock
@@ -61,7 +60,7 @@ end
61
60
  class TestExtendedShouldReceiveOnPartialMockProxies < Test::Unit::TestCase
62
61
  include FlexMock::TestCase
63
62
  include ExtendedShouldReceiveTests
64
-
63
+
65
64
  def setup
66
65
  @obj = Object.new
67
66
  @mock = flexmock(@obj, "mock")
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'test/unit'
4
- require 'flexmock'
3
+ require 'test/test_setup'
5
4
 
6
5
  class DummyModel
7
6
  end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  #---
4
- # Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
4
+ # Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
5
5
  # All rights reserved.
6
6
 
7
7
  # Permission is granted for use, copying, modification, distribution,
@@ -9,12 +9,11 @@
9
9
  # above copyright notice is included.
10
10
  #+++
11
11
 
12
- require 'test/unit'
13
- require 'flexmock'
12
+ require 'test/test_setup'
14
13
 
15
14
  class TestNaming < Test::Unit::TestCase
16
15
  include FlexMock::TestCase
17
-
16
+
18
17
  def test_name
19
18
  m = flexmock("m")
20
19
  assert_equal "m", m.flexmock_name
@@ -22,7 +21,7 @@ class TestNaming < Test::Unit::TestCase
22
21
 
23
22
  def test_name_in_no_handler_found_error
24
23
  m = flexmock("mmm")
25
- ex = assert_raises(Test::Unit::AssertionFailedError) {
24
+ ex = assert_raises(assertion_failed_error) {
26
25
  m.should_receive(:xx).with(1)
27
26
  m.xx(2)
28
27
  }
@@ -31,7 +30,7 @@ class TestNaming < Test::Unit::TestCase
31
30
 
32
31
  def test_name_in_received_count_error
33
32
  m = flexmock("mmm")
34
- ex = assert_raises(Test::Unit::AssertionFailedError) {
33
+ ex = assert_raises(assertion_failed_error) {
35
34
  m.should_receive(:xx).once
36
35
  m.flexmock_verify
37
36
  }
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  #---
4
- # Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
4
+ # Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
5
5
  # All rights reserved.
6
6
 
7
7
  # Permission is granted for use, copying, modification, distribution,
@@ -9,14 +9,12 @@
9
9
  # above copyright notice is included.
10
10
  #+++
11
11
 
12
- require 'test/unit'
13
- require 'flexmock'
14
- require 'test/redirect_error'
12
+ require 'test/test_setup'
15
13
 
16
14
  class TestNewInstances < Test::Unit::TestCase
17
15
  include FlexMock::TestCase
18
16
  include FlexMock::RedirectError
19
-
17
+
20
18
  class Dog
21
19
  def bark
22
20
  :woof
@@ -36,7 +34,7 @@ class TestNewInstances < Test::Unit::TestCase
36
34
  block.call(self) if block_given?
37
35
  end
38
36
  end
39
-
37
+
40
38
  class Connection
41
39
  def initialize(*args)
42
40
  yield(self) if block_given?
@@ -56,7 +54,7 @@ class TestNewInstances < Test::Unit::TestCase
56
54
  m = Dog.new
57
55
  assert_equal :whimper, m.bark
58
56
  end
59
-
57
+
60
58
  def test_new_instances_stubs_still_have_existing_methods
61
59
  flexstub(Dog).new_instances do |obj|
62
60
  obj.should_receive(:bark).and_return(:whimper)
@@ -84,7 +82,7 @@ class TestNewInstances < Test::Unit::TestCase
84
82
  m = Cat.new("Fido") { x = :called }
85
83
  assert_equal :called, x
86
84
  flexmock_teardown
87
-
85
+
88
86
  flexstub(Cat).new_instances { }
89
87
  x = :not_called
90
88
  m = Cat.new("Fido") { x = :called }
@@ -95,14 +93,14 @@ class TestNewInstances < Test::Unit::TestCase
95
93
  flexstub(Dog).new_instances do |obj|
96
94
  obj.should_receive(:bark).once.and_return(nil)
97
95
  end
98
-
99
- fido = Dog.new
100
- ex = assert_raise(Test::Unit::AssertionFailedError) { flexmock_teardown }
96
+
97
+ Dog.new
98
+ ex = assert_raise(assertion_failed_error) { flexmock_teardown }
101
99
  assert_match(/method 'bark\(.*\)' called incorrect number of times/, ex.message)
102
100
  end
103
101
 
104
102
  def test_new_instances_reports_error_on_non_classes
105
- ex = assert_raise(ArgumentError) {
103
+ ex = assert_raise(ArgumentError) {
106
104
  flexstub(Dog.new).new_instances do |obj|
107
105
  obj.should_receive(:hi)
108
106
  end
@@ -110,7 +108,7 @@ class TestNewInstances < Test::Unit::TestCase
110
108
  assert_match(/Class/, ex.message)
111
109
  assert_match(/new_instances/, ex.message)
112
110
  end
113
-
111
+
114
112
  def test_does_not_by_default_stub_objects_created_with_allocate
115
113
  flexstub(Dog).new_instances do |obj|
116
114
  obj.should_receive(:bark).and_return(:whimper)
@@ -118,22 +116,32 @@ class TestNewInstances < Test::Unit::TestCase
118
116
  m = Dog.allocate
119
117
  assert_equal :woof, m.bark
120
118
  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)
119
+
120
+ if RUBY_VERSION >= "1.9"
121
+ def test_explicitly_mocking_allocation_in_new_instances_fails_in_ruby_19
122
+ assert_raise FlexMock::UsageError do
123
+ flexstub(Dog).new_instances(:allocate) do |obj|
124
+ obj.should_receive(:bark).and_return(:whimper)
125
+ end
126
+ end
127
+ end
128
+ else
129
+ def test_can_explicitly_stub_objects_created_with_allocate
130
+ flexstub(Dog).new_instances(:allocate) do |obj|
131
+ obj.should_receive(:bark).and_return(:whimper)
132
+ end
133
+ m = Dog.allocate
134
+ assert_equal :whimper, m.bark
125
135
  end
126
- m = Dog.allocate
127
- assert_equal :whimper, m.bark
128
136
  end
129
-
137
+
130
138
  def test_can_stub_objects_created_with_arbitrary_class_methods
131
139
  flexstub(Dog).new_instances(:make) do |obj|
132
140
  obj.should_receive(:bark).and_return(:whimper)
133
141
  end
134
142
  assert_equal :whimper, Dog.make.bark
135
143
  end
136
-
144
+
137
145
  def test_stubbing_arbitrary_class_methods_leaves_new_alone
138
146
  flexstub(Dog).new_instances(:make) do |obj|
139
147
  obj.should_receive(:bark).and_return(:whimper)
@@ -150,9 +158,9 @@ class TestNewInstances < Test::Unit::TestCase
150
158
  assert_equal 1, counter
151
159
  end
152
160
 
153
- # Current behavior does not install stubs into the block passed to new.
161
+ # Current behavior does not install stubs into the block passed to new.
154
162
  # This is rather difficult to achieve, although it would be nice. For the
155
- # moment, we assure that they are not stubbed, but I am willing to change
163
+ # moment, we assure that they are not stubbed, but I am willing to change
156
164
  # this in the future.
157
165
  def test_blocks_on_new_do_not_have_stubs_installed
158
166
  flexstub(Connection).new_instances do |new_con|
@@ -167,7 +175,7 @@ class TestNewInstances < Test::Unit::TestCase
167
175
  end
168
176
  assert block_run
169
177
  end
170
-
178
+
171
179
  def test_new_instances_accept_chained_expectations
172
180
  flexmock(Dog).new_instances.
173
181
  should_receive(:growl).and_return(:grr).
@@ -175,18 +183,18 @@ class TestNewInstances < Test::Unit::TestCase
175
183
  assert_equal :grr, Dog.new.growl
176
184
  assert_equal :flip, Dog.new.roll_over
177
185
  end
178
-
186
+
179
187
  def test_fancy_use_of_chained_should_received
180
188
  flexmock(Dog).new_instances.should_receive(:woof => :grrr)
181
189
  assert_equal :grrr, Dog.new.woof
182
190
  end
183
-
191
+
184
192
  def test_writable_accessors
185
193
  flexmock(Dog).new_instances.should_receive(:name=).with("fido")
186
194
  dog = Dog.new
187
195
  dog.name = 'fido'
188
196
  end
189
-
197
+
190
198
  def test_ordering_can_be_specified
191
199
  dog = Dog.new
192
200
  flexmock(dog).should_receive(:bark).once.ordered
@@ -194,7 +202,7 @@ class TestNewInstances < Test::Unit::TestCase
194
202
  dog.bark
195
203
  dog.bite
196
204
  end
197
-
205
+
198
206
  def test_ordering_can_be_specified_in_groups
199
207
  dog = Dog.new
200
208
  flexmock(dog).should_receive(:wag).once.ordered(:safe)
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  #---
4
- # Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
4
+ # Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org).
5
5
  # All rights reserved.
6
6
 
7
7
  # Permission is granted for use, copying, modification, distribution,
@@ -9,13 +9,11 @@
9
9
  # above copyright notice is included.
10
10
  #+++
11
11
 
12
- require 'test/unit'
13
- require 'fileutils'
14
- require 'flexmock'
12
+ require 'test/test_setup'
15
13
 
16
14
  class TestStubbing < Test::Unit::TestCase
17
15
  include FlexMock::TestCase
18
-
16
+
19
17
  class Dog
20
18
  def bark
21
19
  :woof
@@ -42,7 +40,7 @@ class TestStubbing < Test::Unit::TestCase
42
40
  flexmock(obj).should_receive(:hi).once.and_return(:stub_hi)
43
41
  assert_equal :stub_hi, obj.hi
44
42
  end
45
-
43
+
46
44
  def test_stub_command_can_configure_via_block
47
45
  obj = Object.new
48
46
  flexmock(obj) do |m|
@@ -50,19 +48,19 @@ class TestStubbing < Test::Unit::TestCase
50
48
  end
51
49
  assert_equal :stub_hi, obj.hi
52
50
  end
53
-
51
+
54
52
  def test_stubbed_methods_can_take_blocks
55
53
  obj = Object.new
56
54
  flexmock(obj).should_receive(:with_block).once.with(Proc).
57
55
  and_return { |block| block.call }
58
56
  assert_equal :block, obj.with_block { :block }
59
57
  end
60
-
58
+
61
59
  def test_multiple_stubs_on_the_same_object_reuse_the_same_partial_mock
62
60
  obj = Object.new
63
61
  assert_equal flexmock(obj), flexmock(obj)
64
62
  end
65
-
63
+
66
64
  def test_multiple_methods_can_be_stubbed
67
65
  dog = Dog.new
68
66
  flexmock(dog).should_receive(:bark).and_return(:grrrr)
@@ -70,7 +68,7 @@ class TestStubbing < Test::Unit::TestCase
70
68
  assert_equal :grrrr, dog.bark
71
69
  assert_equal :happy, dog.wag
72
70
  end
73
-
71
+
74
72
  def test_original_behavior_can_be_restored
75
73
  dog = Dog.new
76
74
  partial_mock = flexmock(dog)
@@ -80,7 +78,7 @@ class TestStubbing < Test::Unit::TestCase
80
78
  assert_equal :woof, dog.bark
81
79
  assert_equal nil, dog.instance_variable_get("@flexmock_proxy")
82
80
  end
83
-
81
+
84
82
  def test_original_missing_behavior_can_be_restored
85
83
  obj = Object.new
86
84
  partial_mock = flexmock(obj)
@@ -100,7 +98,7 @@ class TestStubbing < Test::Unit::TestCase
100
98
  partial_mock.flexmock_teardown
101
99
  assert_raise(NoMethodError) { obj.hi }
102
100
  end
103
-
101
+
104
102
  def test_original_behavior_is_restored_when_multiple_methods_are_mocked
105
103
  dog = Dog.new
106
104
  flexmock(dog).should_receive(:bark).and_return(:grrrr)
@@ -114,7 +112,7 @@ class TestStubbing < Test::Unit::TestCase
114
112
  flexmock(Dog).should_receive(:create).once.and_return(:new_stub)
115
113
  assert_equal :new_stub, Dog.create
116
114
  flexmock(Dog).flexmock_teardown
117
- assert_equal :new_dog, Dog.create
115
+ assert_equal :new_dog, Dog.create
118
116
  end
119
117
 
120
118
  def test_original_behavior_is_restored_on_singleton_methods
@@ -173,7 +171,11 @@ class TestStubbing < Test::Unit::TestCase
173
171
 
174
172
  def test_original_behavior_is_restored_even_when_errors
175
173
  flexmock(Dog).should_receive(:create).once.and_return(:mock)
176
- flexmock_teardown rescue nil
174
+ begin
175
+ flexmock_teardown
176
+ rescue assertion_failed_error => _
177
+ nil
178
+ end
177
179
  assert_equal :new_dog, Dog.create
178
180
 
179
181
  # Now disable the mock so that it doesn't cause errors on normal
@@ -185,7 +187,7 @@ class TestStubbing < Test::Unit::TestCase
185
187
  def test_not_calling_stubbed_method_is_an_error
186
188
  dog = Dog.new
187
189
  flexmock(dog).should_receive(:bark).once
188
- assert_raise(Test::Unit::AssertionFailedError) {
190
+ assert_raise(assertion_failed_error) {
189
191
  flexmock(dog).flexmock_verify
190
192
  }
191
193
  dog.bark
@@ -195,11 +197,11 @@ class TestStubbing < Test::Unit::TestCase
195
197
  obj = Object.new
196
198
  partial_mock = flexmock(obj)
197
199
  partial_mock.should_receive(:hi).once.and_return(:ok)
198
- assert_raise(Test::Unit::AssertionFailedError) {
200
+ assert_raise(assertion_failed_error) {
199
201
  partial_mock.flexmock_verify
200
202
  }
201
203
  end
202
-
204
+
203
205
  def test_stub_can_have_explicit_name
204
206
  obj = Object.new
205
207
  partial_mock = flexmock(obj, "Charlie")
@@ -293,7 +295,7 @@ class TestStubbing < Test::Unit::TestCase
293
295
 
294
296
  def test_safe_partial_mocks_require_block
295
297
  dog = Dog.new
296
- ex = assert_raise(FlexMock::UsageError) { flexmock(:safe, dog) }
298
+ assert_raise(FlexMock::UsageError) { flexmock(:safe, dog) }
297
299
  end
298
300
 
299
301
  def test_safe_partial_mocks_are_actually_mocked