Hi I and trying to rspec mock the following class:
class Person
def initialize(personid)
Rails.logger.debug "Creating person with id #{personid}"
end
end
Using this:
require 'spec_helper'
describe Person do
describe "#initialize" do
let(:rails_mock) { double("Rails").as_null_object }
let(:logger_mock) { double("Rails.logger").as_null_object }
it "logs a message" do
rails_mock.stub(:logger).and_return(logger_mock)
logger_mock.should_receive(:debug)
Person.new "dummy"
end
end
end
and getting this message:
RSpec::Mocks::MockExpectationError: (Double "Rails.logger").debug(any args)
expected: 1 time
received: 0 times
Any help would be great!