How can I clear class variables between rspec tests in ruby How can I clear class variables between rspec tests in ruby ruby ruby

How can I clear class variables between rspec tests in ruby


describe DataFactory  before(:each) { DataFactory.class_variable_set :@@url, nil }  ...end


Here is an alternative to the accepted answer, which while wouldn't solve your particular example, I'm hoping it might help a few people with a question in the same vein. If the class in question doesn't specify a default value, and remains undefined until set, this seems to work:

describe DataFactory  before(:each) do    DataFactory.remove_class_variable :@@url if DataFactory.class_variable_defined? :@@url  end  ...end

Works for me with a class with something more like:

def initialize  @@url ||= MY_CONFIG["my value"]  ...end