What is the best practice to read a file (under lib) while developing a gem?
I experienced some pain when deal with the "path" in developing a gem.
Here is the folder structure
production codes:
lib/gem_name/foo/templates/some_template.erb
lib/gem_name/foo/bar.rb
test codes:
test/gem_name/foo/bar_test.rb
In bar.rb, I read the template by:
File.read("templates/some_template.erb") => Errno::ENOENT: No such file or
directory
when I run the unit test in bar_test.rb in RubyMine, it gives me the error:
Errno::ENOENT: No such file or directory -
D:/.../test/gem_name/foo/templates/some_template.erb
Obviously the test in the path is wrong.
My question are,
How to deal with this issues?
What is the best practice to handle such path problem while developing a gem?
No comments:
Post a Comment