我有控制器:
class AccountController < ApplicationController
def index
end
private
def current_account
@current_account ||= current_user.account
end
end
如何使用rspec测试私有方法current_account
?
附言:我使用Rspec2和Ruby on Rails 3
发布于 2010-11-25 05:48:40
使用#instance_eval
@controller = AccountController.new
@controller.instance_eval{ current_account } # invoke the private method
@controller.instance_eval{ @current_account }.should eql ... # check the value of the instance variable
发布于 2012-05-28 19:57:06
我使用send方法。例如:
event.send(:private_method).should == 2
因为"send“可以调用私有方法。
发布于 2010-11-25 05:29:57
在哪里使用了current_account方法?它的作用是什么?
通常,您不测试私有方法,而是测试调用私有方法的方法。
https://stackoverflow.com/questions/4271696
复制相似问题