[rspec-users] Scope problems for before hooks using helper methods?

Gordon anexiole at gmail.com
Fri Oct 14 01:01:19 EDT 2011


 > Let's see the helper method please.


 ---------------spec/support/controller_macros.rb: start ----------

module ControllerMacros
  include Devise::TestHelpers

  # sets up an instance of a non-admin user
  def login_user
    before(:each) do
      @request.env["devise.mapping"] = Devise.mappings[:user]
      @user = FactoryGirl.create(:user)
      sign_in @user
    end
  end

  # sets up an instance of a admin user
  def login_admin_user
    before(:each) do
      @request.env["devise.mapping"] = Devise.mappings[:user]
      @admin_user = FactoryGirl.create(:admin)
      sign_in @admin_user
    end
  end
end

 ---------------spec/support/controller_macros.rb: end    ----------

It works for my existing controller specs and it's based on
https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-Views-tests-with-Rails-3-(and-rspec)


More information about the rspec-users mailing list