How to test config method in this module with Rspec 3 mocks?
module TestModule
class << self
attr_accessor :config
end
def self.config
@config ||= Config.new
end
class Config
attr_accessor :money_url
def initialize
@money_url = "https://example1.come"
end
end
end
I tried something like this:
describe "TestModule config" do
it "should have config instance" do
config = class_double("TestModule::Config")
obj = instance_double("TestModule")
allow(obj).to receive(:config).and_return(config)
obj.config
expect(obj.config).to eq(config)
end
end
It looks, that it doesn't works, why ?
Failures:
1) TestModule config should have config instance Failure/Error: allow(obj).to receive(:config).and_return(config) TestModule does not implement: config # ./spec/config_spec.rb:41:in `block (2 levels) in '