在我们的Rails(3.2)的一个模块,还有条件include
:如何让R语句的语句总是返回true?
include UsersHelper if find_config_const('allow_sales_manage_customer_login') == 'true'
这里find_config_const
是表格检索找到allow_sales_manage_customer_login
值的方法。使用rspec(版本2.14)进行测试时,模块UserHelper
需要为include
,因此find_config_const('allow_sales_manage_customer_login') == 'true'
应始终返回true。 FactoryGirl不在此处工作,因为由FactoryGirl创建的条目在include
和find_config_const('allow_sales_manage_customer_login') == 'true'
之后加载为false。我们可以让find_config_const('allow_sales_manage_customer_login') == 'true'
始终为rspec返回true(版本2.14)吗?
@@ spiria,find_config_const在Authen :: AuthenUtility中定义。我们在(:each)之前放置以下内容:Authen :: AuthenUtility.any_instance.stub(:find_config_const).with('allow_sales_manage_customer_login')。and_return(true)。有NoMethod错误说未定义的Authen :: AuthenUtility:Module的any_instance。我们错过了什么? – user938363 2014-11-24 19:49:20
你可以试试吗? (:'find_config_const').with('allow_sales_ma nage_customer_login')。and_return(true) – spiria 2014-11-25 13:46:09