On 25 Nov 2009, at 16:02, Krasimir Angelov wrote:
Hi all,
I'm using rspec-caching-test-plugin to test caching (obviously) in
my controller specs. Because views are also involved in caching
integrate_views have to be turned On.
The problem comes when mock is passed to a helper, for examle
link_to_profile(profile)
where porfile = mock_model(Profile)
The error thrown is "can't convert Spec::Mocks::Mock into String".
Usually when dealing with view specs in this case I'm just doing
template.stub!(:link_to_profile => '/link/to/profile')
and specing the helper method in separate helper spec, but in this
case (controller spec with integrate_views turned On) I have no
access to template object.
Is there any way to stub helper method or I just have to give away
mocks and use real records created with FactoryGirl instead?
You have a couple of options, I think:
(1) Try mocking enough of the object's interface that the Rails helper
will happily build a link to it. I think that just means stubbing a
#to_param method on it.
(2) Use rspec-rails' mock_model method to build the mock object, which
will basically do that for you.
(3) Use rspec-rails' stub_model method to build the mock object, which
creates a real model object instance (like FactoryGirl would) except
with the database connection crippled.
Okay that was three options.
cheers,
Matt
http://mattwynne.net
+447974 430184
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users