0

I have a class that laod config file from config/config.yml.

class Example
  def initialize
    config = YAML.load_file('config/config.yml')
  end
end

I have created proyect/spec/config/config.yml example file but when I run the test it try load file proyect/config/config.yml.

How I change rspec working directory?

rjurado01
  • 5,337
  • 3
  • 36
  • 45

1 Answers1

0

Why not point the config to the right path?

class Example
  def initialize
    config = YAML.load_file('spec/config/config.yml')
  end
end

According to this, you can set the load_path like so

$LOAD_PATH.unshift 'spec'
     or
$:.unshift 'spec'

Also according to that,

As much as I like removing unnecessary requires in specs I prefer verbosity over magic -- anything that gives the code reader more clarity as to what's necessary for a particular example group.

J-Dizzle
  • 3,176
  • 6
  • 31
  • 49
  • Proyect is a gem that need load config from `config/config.yml' like [mongoid](https://github.com/mongoid/mongoid). I want to test that it is done correctly. – rjurado01 Jul 14 '15 at 17:51
  • or [this](http://stackoverflow.com/questions/592554/best-way-to-create-custom-config-options-for-my-rails-app) or [this](http://stackoverflow.com/questions/3075855/how-do-i-load-files-from-a-specific-relative-path-in-ruby) – J-Dizzle Jul 14 '15 at 18:00