试图为我已经编写的代码编写一些测试,以期使用测试驱动开发来扩展我的代码。Rspec - 访问巫术方法/变量
我有一个控制器,其索引操作调用一个'user_info'方法,该方法仅依靠Sorcery的current_user变量收集一些实例变量。例如:
def user_info
@current_A = current_user.a
@current_B = current_user.b
end
def index
user_info
// rest of the method goes here
end
我开始使用rspec编写一些测试,只是为了感受测试这个代码库。我的控制器规范是非常基本的,看起来像这样:
describe MyController do
describe "GET 'index'" do
get 'index'
response.should be_success
end
end
不过,我得到以下错误,当我尝试运行此规格: NoMethodError:未定义的方法“一个”假:FalseClass
第一所有,我怎么让我的规格识别Sorcery方法current_user?出于好奇,为什么current_user被标记为FalseClass的实例?如果它没有调用Sorcery方法(并且我没有在我的代码中的任何其他地方定义current_user),它应该不显示为零吗?
总是最好接受最好的答案,或者你自己回答,并接受。由于 – 2014-08-12 00:28:29