Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Ruby classes get cleared out between Rake tasks

Tags:

ruby

rake

rspec

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?

like image 540
Ryan Ahearn Avatar asked Mar 04 '26 01:03

Ryan Ahearn


1 Answers

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.

like image 192
Konstantin Haase Avatar answered Mar 06 '26 19:03

Konstantin Haase



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!