Rails 3.2, RSpec 2.11. Controller macro isn't working, and it appears to be written correctly from all the research I've done. Here's the code
/spec/support/controller_macros.rb
module ControllerMacros
   def login_user
    before(:each) do
      @request.env["devise.mapping"] = Devise.mappings[:user]
      user = FactoryGirl.create(:user)
      @current_user = user
      sign_in user
    end
  end
end
/spec/spec_helper.rb
RSpec.configure do |config|
  ....
  config.extend ControllerMacros, :type => :controller
end
/spec/controllers/companies_controller_spec.rb
require File.dirname(__FILE__) + '/../spec_helper'
describe CompaniesController, "index companies" do
    context "for authenticated users" do
        login_user
        ...
    end
end
execution results: undefined local variable or method 'login_user' for # (NameError)
Seems to have been answered here , you need to change your extend to an include
Adding the spec type fixed it for me:
Before:
describe Api::FooController do
   .
   .
end
After:
describe Api::FooController, type: :controller do
   .
   .
end
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With