Skip to content

Commit b299f07

Browse files
committed
Remove global mock
1 parent 265ac5e commit b299f07

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lib/rspec/active_model/mocks/mocks.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def association(association_name)
9494
# * A String representing a Class that extends ActiveModel::Naming
9595
# * A Class that extends ActiveModel::Naming
9696
def mock_model(string_or_model_class, stubs={})
97+
@__rspec_active_model_mocks ||= Hash.new { |h, k| h[k] = [] }
98+
9799
if String === string_or_model_class
98100
if Object.const_defined?(string_or_model_class)
99101
model_class = Object.const_get(string_or_model_class)
@@ -135,16 +137,12 @@ def self.param_delimiter; "-"; end
135137
:blank? => false }.merge(stubs)
136138

137139
double("#{model_class.name}_#{stubs[:id]}", stubs).tap do |m|
138-
mock_store_klass = RSpec::ActiveModel::Mocks::Mocks
139140
if model_class.method(:===).owner == Module && !stubs.key?(:===)
140-
allow(mock_store_klass).to receive(:mock_store) do
141-
@mock_store ||= Hash.new { |h, k| h[k] = [] }
142-
end
143141
allow(model_class).to receive(:===).and_wrap_original do |original, other|
144-
mock_store_klass.mock_store[model_class].include?(other) || original.call(other)
142+
@__rspec_active_model_mocks[model_class].include?(other) || original.call(other)
145143
end
146144
end
147-
mock_store_klass.mock_store[model_class] << m if mock_store_klass.respond_to?(:mock_store)
145+
@__rspec_active_model_mocks[model_class] << m
148146
msingleton = class << m; self; end
149147
msingleton.class_eval do
150148
include ActiveModelInstanceMethods

0 commit comments

Comments
 (0)