I am writing a functional test for a controller. The problem I have is
that a before filter defined in ApplicationController is hit and I don’t
know how to stub it.
I tried controller.expects(:find_site).returns(@site) but it fails as
controller is unknown method.
I tried ApplicationController.expects(:find_site).returns(@site) but the
assertion fails as it never happens. So how do I deal with that?
The RSpec Book (Pragmatic Bookshelf: By Developers, For Developers)
just added a new chapter about testing controllers, within which is an
example of testing a before filter. You might find it of use.
The RSpec Book (Pragmatic Bookshelf: By Developers, For Developers)
just added a new chapter about testing controllers, within which is an
example of testing a before filter. You might find it of use.
Brandon
I stopped using RSpec, and switched back to Test::Unit, the Agile Web
dev with Rails has a good intro chapter and I was able to solve my
problem.
Just for this issue? If so, there was no need.
Not just for that issue, and Brandon probably assumed I was using rspec,
but it pissed me off some time ago.
Each time I would hit a wall with RSpec and have to search for hours how
to solve it. With Test::Unit for some reason, I don’t have as many
little annoying troubles, and when I do, I find a solution whether on my
own or by reading stuff online very quickly. I am having a much better
testing experience with Test::Unit.
How were you able to solve the problem? It will help others if you post
your solution.
Well I can’t directly stub a controller instance method. So I stubbed
the Model class method that the instance variable will be set to.
Only because I could have sworn I saw you posting over on that mailing
list just the other day.
I didn’t fully transition to test::unit yet, so I still use RSpec’s ML
from time to time.