vendredi 22 mai 2015

Rails 3, app/lib not loaded with rspec

I'm in trouble with a too simple stuff wich gonna make me crazy. I have a controller "A" wich requires a file in a subdirectory of app/lib (ex: app/lib/a_folder/my_class.rb). So I do somthing like this :

require 'a_folder/my_class'

class AController < ApplicationController
  # Some stuff using MyClass
end

It works well when I use the application but doesn't work when I launch RSpec.

This is what my rspec file looks like :

require 'spec_helper'
require 'lib/import_functions' # http://ift.tt/1JHpn0T

RSpec.describe AController, type: controller do
  # My tests routines
end

When I start rspec it tells me the require in the controller file doesn't found the file (`require': cannot load such file), while it works well when I start the app.

I've added a puts $LOAD_PATH just before the require and it appears that Rails.root/app/lib is not present.

I use Rails 3.2 and rspec-rails 3.2.

Is any have an idea about why it happens and how to fix it please ?

Thank you for your future answers.

Aucun commentaire:

Enregistrer un commentaire