Last Updated: February 25, 2016
·
2.374K
· pguelpa

Testing a Ruby Singleton

Unit testing a singleton class can cause problems since you're using the same instance across all the specs, and thus the state will be effected by each test. To get around this, try creating an anonymous subclass for each test:

let(:resource) { Class.new(UniqueResource) }