Reputation: 785
I am trying to write a rake test that needs to call a method in another file in order to set up my current session, but when I try to include the filepath at the top of my rake file I get this Error:
rake aborted!LoadError: cannot load such file -- ~/../../spec/models/run_spec.rb
My rakefile is as follows:
require 'sqlite3'
require 'optparse'
require '~/../../spec/models/run_spec.rb'
task refresh_gn_input_files: :environment do
LOANS_INPUT_PATH_GN = Rails.root.to_s +
'/spec/inputs/loans_input_gn.json'
PRICING_INPUT_PATH_GN = Rails.root.to_s +
'/spec/inputs/pricing_input_gn.json'
puts 'creating and configuring current session...'
create_and_configure_session
puts 'generating loans input file...'
puts "THIS IS THE TEST: #{@session}"
puts 'geerating pricing input file...'
end
So I want to be able to call this 'create_and_configure_session' method that I have in another file but I am not able to include it in my rakefile?
Path to rakefile: ~/Desktop/a/spec/models/run_spec.rb
Path to outside method: ~/Desktop/a/lib/tasks/a_tasks_rake
Method code:
def create_and_configure_session
@support_engine = M::ScriptSet.new.get_engine("Support")
...
end
Upvotes: 1
Views: 84
Reputation: 1943
In the code that you tried, you are going up two levels(with ..
) from ~
.
On a Mac that would land you in /
.
Either of these should get you to your file:
require_relative '../../spec/models/run_spec'
require '~/Desktop/a/spec/models/run_spec'
Upvotes: 1