Your original error comes from our verifying doubles feature, which you must have turned on as part of the upgrade process, you can turn it off if Mongoid isn't playing nicely with it with:
``` RSpec.configure do |config| config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = false end end ``` Both Phils, and yours, snippets pass in an empty Rails app, so its likely an interaction between Rails and other libraries you are using. Cheers Jon ---------------- m...@jonrowe.co.uk https://jonrowe.co.uk On 9 February 2021 at 06:10, Abhinay Rao wrote: > That is because you are calling invoke_additional_tasks method on User > instance. The test case in my example is for test_method which is a Class > method. Please add Class method called test_method in User model to reproduce > the issue. > > user.rb > class User > attr_accessor :name > > class << self > def test_method > rv = validate_something("test") > return rv if rv[:error] > > user = User.new (http://User.new) > user.name (http://user.name) = "test#{rand(1..1000000)}" > user.save! > user.invoke_additional_tasks('test_method') > > return { success: true, user: user } > end > end > > def invoke_additional_tasks(test) > { success: true } > end > > private > > class << self > def validate_something(params) > { success: true } > end > end > end > > > > user_spec.rb > require 'rails_helper' > > RSpec.describe User, type: :model do > describe 'test_method' do > context 'when validate_something returns success' do > before(:each) do > allow(User).to receive(:validate_something).and_return(success: true) > end > > it 'should invoke_additional_tasks on user' do > expect_any_instance_of(User).to > receive(:invoke_additional_tasks).with('test_method') > User.test_method > end > end > end > end > > > > > > > > > > -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/dejalu-217-bc536cb4-619c-4b14-a1e9-7039f9fdd393%40jonrowe.co.uk.