Reputation: 10350
In one of our rails (3.2) modules, there is conditional include
:
include UsersHelper if find_config_const('allow_sales_manage_customer_login') == 'true'
Here the find_config_const
is a method searching a table to find the value of allow_sales_manage_customer_login
. When testing with rspec (ver 2.14), Module UserHelper
needs to be include
and therefore find_config_const('allow_sales_manage_customer_login') == 'true'
should always return true. FactoryGirl does not work here because the entry created by FactoryGirl is loaded AFTER include
and find_config_const('allow_sales_manage_customer_login') == 'true'
is false. Is there a way we can make find_config_const('allow_sales_manage_customer_login') == 'true'
always returns true for rspec (ver 2.14)?
Upvotes: 0
Views: 469
Reputation: 106
The answer is to stub the method by using #stub or #should_receive.
Can you tell me where the find_config_const method is defined?
Suppose it is defined in SomeHelper. You could do:
SomeHelper.any_instance.stub(:find_config_const).with('allow_sales_manage_customer_login').and_return(true)
Upvotes: 1