How to test a singleton class in Ruby?

1

I'm using require "singleton" to make a given class only be instantiated once. However, at the time of running the tests with rspec, I get the following error:

  

NoMethodError: private method 'new' called for MyClass.

I'm not instantiating the class with new , but rather getting the reference to the object with MinhaClasse.instance . How do I resolve this issue?

    
asked by anonymous 12.02.2014 / 00:57

1 answer

1

Better to show with an example:

# Obs.: Não foi testado
describe MySingletonClass do
  subject { MySingletonClass.instance }
  describe '#to_s' do
    it 'works' do
      expect(subject.to_s).to be eq(subject.to_s)
    end
  end
end

If that does not help, maybe it's a good idea to share your tests.

    
12.02.2014 / 01:09