I have a class like the following:
class Foo
@variable = {}
class << self
attr_accessor :variable
end
def self.run(file)
# do stuff
end
end
I have an RSpec type method like the following:
def method?
Foo.variable[@name] = {}
Foo.variable[@name][:variable_two] = 'string'
true
end
I have an rspec and custom task like the following:
RSpec::Core::RakeTask.new("rspec-#{spec}".to_sym) do |task|
task.pattern = spec
end
desc "do stuff"
task spec do
Rake::Task["rspec-#{spec}".to_sym].invoke
Foo.run(spec)
end
I am executing the spec
task with rake.
If I do puts Foo.variable
in the method?
definition, then I see that during the RSpec subtask for "rspec-#{spec}".to_sym
the Foo.variable
hash is populated exactly and perfectly as I expect. However, as soon as Foo.run
executes after the rspec rake task, the Foo.variable
hash becomes empty. I have tried many different ways to transfer or retain the values generated during the rspec rake task to the Foo.run
method and the above code is basically the template I return to after each attempt.
What kind of algorithm gives me the functionality to retain values assigned to a variable during a rspec rake task for another method executed afterwards?
Tried class variable suggestion with:
class Foo
@@variable = {}
def self.variable
@@variable
end
def self.run(file)
# do stuff
end
end
and same problem.