Skip to content

Commit 5c7174c

Browse files
committed
Fix issue with Rails 6.1 saying it responds to writer= but then raising when you use it
1 parent b7c77f8 commit 5c7174c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/rspec/active_model/mocks/mocks.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ def stub_model(model_class, stubs={})
256256

257257
stubs.each do |message, return_value|
258258
if m.respond_to?("#{message}=")
259-
m.__send__("#{message}=", return_value)
259+
begin
260+
m.__send__("#{message}=", return_value)
261+
rescue ActiveModel::MissingAttributeError
262+
RSpec::Mocks.allow_message(m, message).and_return(return_value)
263+
end
260264
else
261265
RSpec::Mocks.allow_message(m, message).and_return(return_value)
262266
end

0 commit comments

Comments
 (0)