On Thursday, December 11, 2014 6:02:48 AM UTC-8, [email protected] wrote: > > 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 > endend > > 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) > endend > > 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 ' > > `config` is a singleton method on `TestModule` (often called a class method when on a module or class). It's not an instance method. Change `instance_double("TestModule")` to `class_double("TestDouble")` and it should work.
HTH, Myron -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/f1426931-f604-4c67-a1c5-30bf1799f091%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
