gpt4 book ai didi

ruby-on-rails - RSpec Controller 宏不起作用

转载 作者:行者123 更新时间:2023-12-04 12:33:32 26 4
gpt4 key购买 nike

Rails 3.2,RSpec 2.11。 Controller 宏不起作用,而且从我所做的所有研究来看,它似乎是正确编写的。这是代码

/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”(NameError)

最佳答案

好像已经回答了here ,您需要更改您的extendinclude

关于ruby-on-rails - RSpec Controller 宏不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15479924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com