RSpec recipe: remove constants created during a test execution
Dmitry Shvetsov

We ran into this issue testing some modules in our codebase. One option that worked well for us was to create the modules/classes with instantiation syntax and avoid creating a constant:

greeter_klass = do
def initialize(object)
@object = object
  def hello
"Hello, my name is #{}"

This also works nicely with let as well, if you’re into that sort of thing:

let(:my_module) { { def foo; end } }
Like what you read? Give Robert Fletcher a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.