-
-
Save unixc3t/e8b087e04b0d36e04197ebae9988b9e0 to your computer and use it in GitHub Desktop.
Solve Error Devise with RSpec and Rails 4 uninitialized constant ControllerMacros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.../spec/spec_helper.rb:27:in `block (2 levels) in <top (required)>': uninitialized constant ControllerMacros (NameError) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
Rspec.describe LinkController do | |
context 'user has login' do | |
login_user | |
it 'request edit link' do | |
get :edit, id: link | |
expect(assigns(:link)).to eq link | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in rails_helper.rb
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }