List Info

Thread: Mocking and Stubbing Controllers




Mocking and Stubbing Controllers
user name
2007-12-20 13:51:06
I'm scratching my head a little trying to figure out how to
mock and
stub controller methods.  For instance,

def index
  # Where current_user is a protected controller method
  articles = current_user.articles.find(:all)
end

That's a pretty common sort of call in a controller.  How
are you guys
mocking and stubbing such calls?  I'm currently using Mocha,
but I
doubt this will effect what your approach is.

Ideas?  Thoughts?  Tips?  I'm all ears.

James
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails" group.
To post to this group, send email to rubyonrailsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-unsubscribegooglegroups.com
For more options, visit this group at http://gro
ups.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---


Re: Mocking and Stubbing Controllers
user name
2007-12-23 07:41:42
Try this:

current_user = mock_model(User)
controller.stub!(:current_user).and_return(current_user)

On Dec 20, 9:51 pm, "James H."
<james.herd...gmail.com> wrote:
> I'm scratching my head a little trying to figure out
how to mock and
> stub controller methods.  For instance,
>
> def index
>   # Where current_user is a protected controller
method
>   articles = current_user.articles.find(:all)
> end
>
> That's a pretty common sort of call in a controller. 
How are you guys
> mocking and stubbing such calls?  I'm currently using
Mocha, but I
> doubt this will effect what your approach is.
>
> Ideas?  Thoughts?  Tips?  I'm all ears.
>
> James
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails" group.
To post to this group, send email to rubyonrailsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-unsubscribegooglegroups.com
For more options, visit this group at http://gro
ups.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )