RSpec for should_receive and should_not_receive both passed for Exception
问题 I had a really weird rspec case scenario. I tried to test if my function handles exception correctly. And the following is my code: in User.rb: def welcome_user begin send_welcome_mail(self) rescue Exception => exception ErrorMessage.add(exception, user_id: self.id) end end end in user_spec.rb it "adds to error message if an exception is thrown" do mock_user = User.new mock_user.stub(:send_welcome_mail).and_raise(Exception) ErrorMessage.should_receive(:add) mock_user.welcome_user end The test