导轨 3.2,RSpec 2.11。控制器宏不起作用,从我所做的所有研究来看,它似乎是正确编写的。这是代码
/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
执行结果:未定义的局部变量或方法 'login_user' for # (NameError)