Skip to content

Instantly share code, notes, and snippets.

@unixc3t
Forked from rrmartins/Error_Terminal
Last active April 7, 2017 13:58
Show Gist options
  • Save unixc3t/e8b087e04b0d36e04197ebae9988b9e0 to your computer and use it in GitHub Desktop.
Save unixc3t/e8b087e04b0d36e04197ebae9988b9e0 to your computer and use it in GitHub Desktop.
Solve Error Devise with RSpec and Rails 4 uninitialized constant ControllerMacros
module ControllerMacros
def login_admin
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:admin]
sign_in FactoryGirl.create(:user)
end
end
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryGirl.create(:user)
sign_in user
end
end
end
.../spec/spec_helper.rb:27:in `block (2 levels) in <top (required)>': uninitialized constant ControllerMacros (NameError)
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'devise'
ActiveRecord::Migration.maintain_test_schema!
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.include FactoryGirl::Syntax::Methods
config.include Devise::Test::ControllerHelpers, type: :controller
config.extend ControllerMacros, type: :controller
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
end
@unixc3t
Copy link
Author

unixc3t commented Apr 7, 2017

in rails_helper.rb

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment