@@ -12,8 +12,8 @@ module ActiveModelInstanceMethods
12
12
# Stubs `persisted?` to return false and `id` to return nil
13
13
# @return self
14
14
def as_new_record
15
- self . stub ( :persisted? ) { false }
16
- self . stub ( :id ) { nil }
15
+ RSpec :: Mocks . allow_message ( self , :persisted? ) . and_return ( false )
16
+ RSpec :: Mocks . allow_message ( self , :id ) . and_return ( nil )
17
17
self
18
18
end
19
19
@@ -32,8 +32,8 @@ def respond_to?(message, include_private=false)
32
32
module ActiveRecordInstanceMethods
33
33
# Stubs `persisted?` to return `false` and `id` to return `nil`.
34
34
def destroy
35
- self . stub ( :persisted? ) { false }
36
- self . stub ( :id ) { nil }
35
+ RSpec :: Mocks . allow_message ( self , :persisted? ) . and_return ( false )
36
+ RSpec :: Mocks . allow_message ( self , :id ) . and_return ( nil )
37
37
end
38
38
39
39
# Transforms the key to a method and calls it.
@@ -106,7 +106,7 @@ def self.primary_key; :id; end
106
106
if defined? ( ActiveRecord )
107
107
[ :save , :update_attributes , :update ] . each do |key |
108
108
if stubs [ key ] == false
109
- m . errors . stub ( :empty? => false )
109
+ RSpec :: Mocks . allow_message ( m . errors , :empty? ) . and_return ( false )
110
110
end
111
111
end
112
112
end
@@ -150,8 +150,8 @@ def @object.to_s
150
150
module ActiveModelStubExtensions
151
151
# Stubs `persisted` to return false and `id` to return nil
152
152
def as_new_record
153
- self . stub ( :persisted? ) { false }
154
- self . stub ( :id ) { nil }
153
+ RSpec :: Mocks . allow_message ( self , :persisted? ) . and_return ( false )
154
+ RSpec :: Mocks . allow_message ( self , :id ) . and_return ( nil )
155
155
self
156
156
end
157
157
@@ -223,7 +223,11 @@ def stub_model(model_class, stubs={})
223
223
stubs . each do |k , v |
224
224
m . __send__ ( "#{ k } =" , stubs . delete ( k ) ) if m . respond_to? ( "#{ k } =" )
225
225
end
226
- m . stub ( stubs )
226
+
227
+ stubs . each do |message , return_val |
228
+ RSpec ::Mocks . allow_message ( m , message ) . and_return ( return_val )
229
+ end
230
+
227
231
yield m if block_given?
228
232
end
229
233
end
0 commit comments