Ryan Ahearn
Ryan Ahearn

Reputation: 7934

Do Ruby classes get cleared out between Rake tasks

I have a Rakefile that defines the spec task as

task :spec => [:check_dependencies, :load_backends]

And then runs the actual rspec tests. During the load_backends task, it loads a class called Story, but in the first spec test, defined?(Story) returns false.

I'm assuming that it is intended behavior of Rake to start with a fresh environment at the beginning of each task, but is there a way to override this? Or do I need to re-architect loading the backends into each task?

Upvotes: 3

Views: 145

Answers (1)

Konstantin Haase
Konstantin Haase

Reputation: 25954

RSpec's spec task fires up a new Ruby process (mainly to not screw with your Rake process, I think), therefore classes defined in a rake task (even the spec task) are not available in your specs. Consider moving this logic to your spec helper or don't use RSpec's spec task.

Upvotes: 1

Related Questions