我正在尝试testingRailslogging器在我的一些规范中接收消息。 我正在使用Logging的gem 。 假设我有这样的课程: class BaseWorker def execute logger.info 'Starting the worker…' end end 和一个规范一样: describe BaseWorker do it 'should log an info message' do base_worker = BaseWorker.new logger_mock = double('Logging::Rails').as_null_object Logging::Rails.stub_chain(:logger, :info).and_return(logger_mock) logger_mock.should_receive(:info).with('Starting the worker…') base_worker.execute Logging::Rails.unstub(:logger) end end 我收到以下失败消息: Failure/Error: logger_mock.should_receive(:info).with('Starting worker…') (Double "Logging::Rails").info("Starting worker…") expected: 1 time received: 0 times 我已经尝试了几种不同的方法来使规范通过。 这适用于例如: […]