Rspec does not download support files

In my spec_helper file, I have this line:

 Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } 

But when I run rspec, I get errors like:

 undefined local variable or method `login_user' for RSpec::ExampleGroups::PostsController::POSTCreate::WhenSignedIn:Class 

The corresponding function is in support/auth_macros , where I would suggest that the require statement in my spec_helper would display spec_helper . Any idea what could happen?

This file:

 # support/auth_macros.rb module AuthMacros def login_user before(:each) do @request.env["devise.mapping"] = Devise.mappings[:user] @logged_in_user = FactoryGirl.create(:user, username: "logged_in") sign_in @logged_in_user end end def logout_user before(:each) do sign_out @logged_in_user end end end 
+8
ruby ruby-on-rails rspec
source share
1 answer

A file is required, but the method is wrapped inside the module. You need to either remove the wrapping module or include it in a group test.

Update:

To be 100% specific: require downloads the file and does nothing. After the file is needed, the module was created, but it is not included. You must enable it with: include AuthMacros

+7
source share

All Articles